/* Firebug 4 IE */
//if($.browser.msie && parseFloat($.browser.version.substr(0,3)) < '8'){ document.write(unescape("%3Cscript%20type%3D%27text/javascript%27%20src%3D%27http%3A//getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js%27%3E%3C/script%3E")); }

var isIE6 = false;
if($.browser.msie && parseFloat($.browser.version.substr(0,3)) < '7'){
	isIE6 = true;
}

$.extend({
	  getUrlVars: function(){
		var href = unescape(window.location.href.slice(window.location.href.indexOf('?') + 1))
	    var vars = [], hash;
	    var hashes = href.split('&');
	    for(var i = 0; i < hashes.length; i++) {
	      hash = hashes[i].split('=');
	      vars.push(hash[0]);
	      vars[hash[0]] = hash[1];
	    }
	    return vars;
	  }
	});

var $j = jQuery.noConflict();

$j(document).ready(function(){

	$j(".startbox a").attr('title','click here to read more');

	$j(".pictureslider li img").show();
	
	$j("#news").easySlider({
		controlsBoth: true,
		controlsFade: false,
		controlsBefore: '<div class="ctrl_orange"><div class="controls">',
		controlsAfter: '</div></div>',
		prevId: 'prev1a',
		nextId: 'next1a',
		numeric: true,
		numericId: 'numeric_news',
		continuous: true,
		speed: 500
	});
	$j("#events").easySlider({
		controlsBoth: true,
		controlsFade: false,
		controlsBefore: '<div class="ctrl_orange"><div class="controls">',
		controlsAfter: '</div></div>',
		prevId: 'prev1b',
		nextId: 'next1b',
		numeric: true,
		numericId: 'numeric_events',
		continuous: true,
		speed: 500
	});

	$j("#prod_otm").easySlider({
		controlsBoth: true,
		controlsFade: false,
		controlsBefore: '<div class="ctrl_blue"><div class="controls">',
		controlsAfter: '</div></div>',
		prevId: 'prev2',
		nextId: 'next2',
		numeric: true,
		numericId: 'numeric_prod',
		continuous: true,
		speed: 500
	});
	
	$j("#app_otm").easySlider({
		controlsBoth: true,
		controlsFade: false,
		controlsBefore: '<div class="ctrl_green"><div class="controls">',
		controlsAfter: '</div></div>',
		prevId: 'prev3',
		nextId: 'next3',
		numeric: true,
		numericId: 'numeric_app',
		continuous: true,
		speed: 500
	});
	
	//Scroll Back to Top
	$j('#toplink').click(function(){
		$j('html, body').animate({scrollTop: '0px'}, {duration:500,easing:'swing',queue:false});
		return false;
	});

	//Produktmenü Links
	$j('#navi_main ul:first > li').each( function () {
		if (!$j(this).hasClass('active')) {
			$j(this).find('ul').hide();
			$j(this).addClass('inactive');
		}
	});
	$j('#navi_main ul:first > li > a').click( function () {
		var ul = $j(this).next();
		var li = $j(this).parent();
		if( li.hasClass('active') ) {
			li.addClass('inactive')
			li.removeClass('active')
			ul.slideUp('middle');
		} else {
			li.removeClass('inactive')
			li.addClass('active')
			ul.slideDown('slow');
		}
		return false;
	});
	//Product List & Submenues
	//$j('#overlay').hide();
	//$j('.navi_page').hide();
	$j('.navi_page .navi_innerbox').tabs();
	$j('.navi_page .navi_innerbox .tab_navi_top').each(function(i,e){
		$j(e).find('li:first').addClass('ui-first');
		$j(e).find('li:last').addClass('ui-last');
		$j(e).find('li.ui-first.ui-last').removeClass('ui-first').removeClass('ui-last').addClass('ui-both');
	});
	$j("#products li:nth-child(odd)").addClass("odd");
	$j("#products li:nth-child(even)").addClass("even");
	$j('#navi_top ul li a').click(function(){
		var id = $j(this).parent().attr('id');
		if( $j('#navi_'+id).length == 0 || $j('#navi_'+id).text() == '' ){ return true; }
		$j('#navi_'+id).css('left',
			$j('#pagewrap').offset().left
			+ parseInt($j('#pagewrap').css('padding-left'))
		);
		if ($j('#navi_'+id+':hidden').length > 0) {
			if(!isIE6) $j('#'+id).addClass("npactive");
			showOverlay();
			$j('#navi_'+id).slideDown(500, function(){ showOverlay(); });
		} else {
			$j('#overlay').fadeTo(300,0,function(){
				$j('#overlay').hide();
				if(!isIE6) $j('#'+id).removeClass("npactive");
			});
			$j('#navi_'+id).slideUp(500);
		}
		return false; 
	});
	//warten bis Overlay geladen wurde
	setTimeout(function(){
		$j('.navi_page .close, #overlay').click(function(){
			$j('#overlay').fadeTo(300,0,function(){
				$j('#overlay').hide();
				if(!isIE6) {
					$j('#navi_top li').removeClass("npactive");
					$j('#contactflag .contactbox').removeClass("npactive");
				}
			});
			if($j(this).hasClass('close')) { $j(this).parent().parent().slideUp(500); } else { $j('.navi_page').slideUp(500); }
			return false;
		});
	},100);
	
	//Productbox im IE6 Scrollen
	if(isIE6){
		var mtop = parseInt($j('.navi_page').css('top'));
		ieproductscroll(mtop)
	}
	// Kontaktbox oeffnen
	$j('a.contact').click(function(){
		if( $j('#contactform').length == 0 || $j('#contactform').text() == '' ){ return true; }
		$j('#contactform').css('left',
			$j('#pagewrap').offset().left
			+ parseInt($j('#pagewrap').css('padding-left'))
		);
		if ($j('#contactform:hidden').length > 0) {
			if(!isIE6) $j('#contactflag .contactbox').addClass("npactive");
			showOverlay();
			$j('#contactform').slideDown(500, function(){ showOverlay(); });
		} else {
			$j('#overlay').fadeTo(300,0,function(){
				$j('#overlay').hide();
				if(!isIE6) $j('#contactflag .contactbox').removeClass("npactive");
			});
			$j('#contactform').slideUp(500);
		}
		return false;
	});

	//Kontaktbox where do you know from
	// #uid23 = Selectbox
	// #uid24 = other field
	$j('#contactform #powermaildiv_uid23').append($j('#contactform #uid24'));
	$j('#contactform #uid24').hide();
	$j('#contactform #powermaildiv_uid24').remove();
	$j('#contactform #uid23').change(function(){
		var val = $j(this).val()
		if (val.substr(0,3) == '...') {
			$j('#uid24').show();
		} else {
			$j('#uid24').hide();
		}
	});
	$j('#contactform #uid23').change();
	//Scroll Back to Top
	$j('a.gotologin').click(function(){
		$j('html, body').animate({scrollTop: '0px'}, {duration:500,easing:'swing',queue:false});
		return false;
	});
	$j('a.login').click(function(){
		$j('html, body').animate({scrollTop: '0px'}, {duration:500,easing:'swing',queue:false});
		return false;
	});			
	//Loginformular
	$j('a.login').click(function(){
		if( $j('#login_popup').length == 0 || $j('#login_popup').text() == '' ){ return true; }
		$j('#login_popup').css('left',
			$j('#pagewrap').offset().left
			+ parseInt($j('#pagewrap').css('padding-left'))
		);
		if ($j('#login_popup:hidden').length > 0) {
			if(!isIE6) $j('#login_popup').addClass("npactive");
			showOverlay();
			$j('#login_popup').slideDown(500, function(){ showOverlay(); });
		} else {
			$j('#overlay').fadeTo(300,0,function(){
				$j('#overlay').hide();
				if(!isIE6) $j('#login_popup').removeClass("npactive");
			});
			$j('#login_popup').slideUp(500);
		}
		return false;
	});
	
	$j('#registerform').hide();
	$j('#openregisterform').click(function(){
		if($j('#registerform:hidden').length > 0) {
			$j('#registerform').slideDown('slow', function(){ showOverlay(); });
		} else {
			$j('#registerform').slideUp('middle', function(){ showOverlay(); });
		}
		return false;
	});
	
	if ( $j.getUrlVars()['contactformpopupUse'] || $j.getUrlVars()['tx_powermail_pi1[optinuid]']) {
		setTimeout(function(){ $j($j('a.contact').get(0)).click() },100);
	};
	if ( $j.getUrlVars()['tx_felogin_pi1[forgot]'] || $j.getUrlVars()['tx_felogin_pi1[popup]']) {
		$j($j('a.login').get(0)).click();
	}
	if ( $j.getUrlVars()["tx_srfeuserregister_pi1[openform]"] && !$j.getUrlVars()['tx_felogin_pi1[forgot]'] ) {
		$j($j('a.login').get(0)).click();
		$j('#openregisterform').click();
	} else if ( $j('#tx-srfeuserregister-pi1-fe_users_form').length > 0 ) {
		// openform an url anhängen, um das registrierungsformular nach abschicken wieder zu öffnen
		var action = $j('#tx-srfeuserregister-pi1-fe_users_form').attr('action');
		if(action.indexOf('?') != -1) { action += ('&'); } else { action += ('?'); }
		action += 'tx_srfeuserregister_pi1%5Bopenform%5D=1'
		$j('#tx-srfeuserregister-pi1-fe_users_form').attr('action', action);
	}
	
	function showOverlay(){
		$j('#overlay').css({width:$j(document).width(),height:$j(document).height()})
		if ($j('#overlay:hidden').length > 0 ){
			$j('#overlay').fadeTo(1,0,function(){$j('#overlay').show();$j('#overlay').fadeTo(800,0.6);});
		}
	}
	
	$j('.dealersearchlist ul.mkcontact-companys li:last-child').addClass('last');
	
	// first für mkcontacts-pager
	$j('#content .mkcontact-pagebrowser').each(function(i,e){
		 $j(e).find('li[class!=prevpage]:first').addClass('first');
	});
	
	/* dealerhöhe anpassen */
	var dHeight = 0
	$j('.dealersearchlist ul.mkcontact-companys li .box_down').each(function(i,e){
		var eh = $j(e).height();
		if ( eh > dHeight ) { dHeight = eh }
	});
	$j('.dealersearchlist ul.mkcontact-companys li .box_down').height(dHeight);
	
	// getincontact erste helpbox verschieben
	$j('#contactform h1').append($j('#powermaildiv_uid12 label a'));
	$j("#overlay").appendTo("#pagewrap");
});

function ieproductscroll(o) {
	if ($j('.navi_page:visible[id!=contactform]').length > 0) {
		var nt = o-$j(window).scrollTop();
		if(nt != parseInt($j('#navi_products').css('top'))) {
			$j('.navi_page').css('top',o-$j(window).scrollTop());
		}
	}
	setTimeout(function(){ ieproductscroll(o) },100);
}

$j(function() {
	// Tabs
	$j('.tabs').tabs();
	$j('.multimediatab').tabs();
	//Zebra Effect
	$j(".acc_box tr:nth-child(even)").addClass("even");
}); 

//Produkt-Bild-Slider
$j(document).ready(function(){
function multimediatabs(tabid,tabclass) {
	var count = 1;
	for (i=0;i<20;i++) {
	    if ($j('#'+tabid).length > 0 ) {
	    	$j('#'+tabid).attr("id",tabid+'_'+count);	    	
	    	$j('#'+tabid+'_'+count).parent().parent().children('.multimediatab').children('.' + tabclass).children('a').attr("href",'#' + tabid + '_' + count);
	    	//Inhalt???
	    	if ( $j('#'+tabid+'_'+count+' .pictureslider').children().length == 0 ) {
	    		$j('#'+tabid+'_'+count).parent().parent().children('.multimediatab').children('.' + tabclass).hide();
	    	}
	    	count++;
		} else {
			i=20;
		}
	}
	var uitabhide = false;
	for (j=1;j<=count;j++) {
		if ( $j('#' + tabid + '_' + j).hasClass('ui-tabs-hide') ) {
			uitabhide = true;
			$j('#' + tabid + '_' + j).removeClass('ui-tabs-hide')
		}
		$j('#' + tabid + '_' + j + ' .pictureslider').easySlider({
			controlsShow: true,
			controlsBoth: true,
			controlsFade: false,
			controlsBefore: '<span class="controls">',
			controlsAfter: '</span>',
			prevId: tabid + '-prev_' + j,
			nextId: tabid + '-next_' + j,
			prevClass: tabid + '-prev',
			nextClass: tabid + '-next',
			numeric: true,
			numericId: tabid + '-numeric_' + j,
			numericClass: tabid + '-numeric',
			continuous: true,
			speed: 500
		});
		if ( uitabhide ) {
			$j('#' + tabid + '_' + j).addClass('ui-tabs-hide')
		}
		//Picture Controls in pictures Tab Kopieren
		$j(function(){
			var ca = $j('#' + tabid + '_' + j + ' .controls');
			$j('#' + tabid + '_' + j).parent().parent().children('.multimediatab').children('.' + tabclass).append(ca);
		});
 }
}
// Slideshow fuer Bilder aufbauen
multimediatabs('pictab','picturetab');
// Slideshow fuer Videos aufbauen
multimediatabs('vidtab','videotab');
//Hover, um Kontent bei bildern anzuzeigen
$j('.multimediabox li').hover(
	function(){
		var n = $j(this).find('.cont');
		if (n.hasClass('cont')) {
			//wenn video, dann info oben anzeigen
			if($j(this).find('.image .rgmediaimages-player').length > 0) { n.addClass('ctop'); }
			n.show();
		}
	},
	function(){ 
		var n = $j(this).find('.cont');
		if (n.hasClass('cont')) {
			n.hide();
		}
	}
);
//Multimediabox ausblenden wenn kein inhalt
$j('.multimediabox').each(function(i,o){
	$j(o).tabs();
	if(( $j(o).find('.pictab').find('.pictureslider').children().length ==0 ) && ( $j(o).find('.vidtab').find('.pictureslider').children().length ==0 )){
		  $j(o).hide();
	  }
	var video = 0;
	var picture = 0;
	  if( $j(o).find('.vidtab').find('.pictureslider').children().length ==0 ) {
		  $j(o).find('.vidtab').addClass('ui-tabs-hide');
		  $j(o).find('.pictab').removeClass('ui-tabs-hide');
		  $j(o).find('.pictab').addClass('ui-tabs');
		  $j(o).find('.multimediatab').find('.videotab').hide();
		  video = 1
	  }	
	  if( $j(o).find('.pictab').find('.pictureslider').children().length ==0 ) {
		  $j(o).find('.pictab').addClass('ui-tabs-hide');
		  $j(o).find('.multimediatab').find('.picturetab').hide();
		  picture = 1
	  }	
	  if ((video==0) && (picture==0)) {
		  $j(o).find('.picturetab').children('a:last').click();	  
	  }
	  if (picture==1) {
		  $j(o).find('.picture').children('a:last').click();	  
		  }	 
	  if ((video==1) && (picture==1)) {
		  $j(o).find('.videotab').children('a:last').click();
	  }
});

// make it work!
$j('.multimediatab li').removeClass('ui-state-disabled');

}); 
//----------------
// Accordion
//----------------
$j(document).ready(function(){
	
	//wenn klick, dann auf-/zuklappen
	$j(".trigger").click(function(){
		if ($j(this).hasClass('triggerinactive')) {
			$j(this)
				.addClass("triggeractive")
				.removeClass("triggerinactive")
				.next(".toggle_container").slideDown("slow");
		} else {
			$j(this)
				.addClass("triggerinactive")
				.removeClass("triggeractive")
				.next(".toggle_container").slideUp("middle");
		}
		check_openclose($j('.accordionwrap'));
	});

	$j(".openall").click(function(){
		if($j(this).hasClass('disabled')) { return false; }
		var accordion = $j(this).parent().find('.accordion');
		accordion.find(".triggerinactive")
			.addClass("triggeractive")
			.removeClass("triggerinactive")
			.next(".toggle_container").slideDown("slow");
		check_openclose($j(this).parent());
		return false;
	});

	$j(".closeall").click(function(){
		if($j(this).hasClass('disabled')) { return false; }
		var accordion = $j(this).parent().find('.accordion');
		accordion.find(".triggeractive")
			.addClass("triggerinactive")
			.removeClass("triggeractive")
			.next(".toggle_container").slideUp("middle");
		check_openclose($j(this).parent());
		return false;
	});

	// alle Container verstecken beim Seitenstart
	$j(".toggle_container").hide();
	$j(".trigger").addClass("triggerinactive");

	check_openclose($j('.accordionwrap'));
	
	// Container mit dieser Klasse werden geoeffnet 
	$j(".toggle_head").click();
	$j(".toggle_head").removeClass("triggerinactive");
	
	function check_openclose(accordionwrap) {
		if ( accordionwrap.find('.triggerinactive').length > 0 ) {
			accordionwrap.find('.openall a').fadeTo("middle",1.0);
			accordionwrap.find('.openall').removeClass('disabled');
		} else {
			accordionwrap.find('.openall a').fadeTo("middle",0.3);
			accordionwrap.find('.openall').addClass('disabled');
		}
		if ( accordionwrap.find('.triggeractive').length > 0 ) {
			accordionwrap.find('.closeall a').fadeTo("middle",1.0);
			accordionwrap.find('.closeall').removeClass('disabled');
		} else {
			accordionwrap.find('.closeall a').fadeTo("middle",0.3);
			accordionwrap.find('.closeall').addClass('disabled');
		}
	}
});