/* JS Starter (c) almö */
var zplayer;

function loadMenu(obj,param)
{
	$(obj).addClass('act');
	$(obj).css("z-index","9999"); 
	if(!param)return false;

	var L = ( $.url.param("L") != undefined ) ? $.url.param("L"): 0;
	var closeAction = function(){$("#hidden_layer").hide();$('#navilist a.act').removeClass('act');Cufon.refresh('#navigation a.level1');};
	$.get('index.php?id=65&L='+L+'&tx_amdbtmenu_pi1[menuType]='+param, function(data) 
	{
  		$('#hidden_layer').html(data);
  		$('#hidden_layer table').addClass("pos_"+param);
  		if( param == 'active_speaker' || param == 'passive_speaker')
  		{
			var api = $("#hidden_layer").fadeIn().expose({
			    	maskId: "mask", 
			    	color: "#666", 
			    	opacity: 0.8, 
			    	api: true,
			    	onClose: closeAction
			    });
			    api.load();
			    
			    $('#hidden_layer').prepend('<a href="#" class="closebtnred closemain"></a>');
  				$('a.closebtnred').click(function(){ $('#hidden_layer').hide(); api.close(); return false; });
		}
		else
		{
			$("#hidden_layer").fadeIn();
			$("#hidden_layer").mouseenter(function(){$(this).show();}).mouseleave( closeAction );
		}


  		$('#hidden_layer li.link a').mouseover(function(){
			var imageSrc = $(this).attr("rel");
			var imageTitle = $(this).attr("title");
			var img = $(this).parent().parent().children('.images').children('img');
				img.attr('src',imageSrc);
				img.attr('title',imageTitle).attr('alt',imageTitle);
		});
	});
}

function loadTechnologyLayer( url )
{
	$('#hidden_layer').html('');
	if(!url)return false;
	$.get(url, function(data) 
	{
  		$('#hidden_layer').html(data).fadeIn();
  		$('#hidden_layer').prepend('<a href="#" class="closebtnred closetechnology"></a>');
  		$('a.closebtnred').click(function(){ $('#hidden_layer').hide(); return false; });
  		$('#hidden_layer table').css({"-moz-box-shadow":"0 0 50px 0px #555555", "-webkit-box-shadow":"0 0 50px 0px #555555"});
  		  		
	});
}

function slideSwitch() {
    var $active = $('#blender .active');
    if ( $active.length == 0 ) $active = $('#blender img:last');
    var $next = $active.next('img').length ? $active.next('img') : $('#blender img:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
        
        
}

function play_video(pdiv, plist) {
	flowplayer(pdiv, {src: '/fileadmin/templates/res/7d/f/flowplayer-3.1.5.swf', wmode: 'transparent'}, { onBeforeFullscreen : function() { this.pause(); clip = this.getClip(); seek = this.getTime(); this.stopBuffering(); $("#hidden_layer").show(); $("#hidden_layer").html("<div id='zoomplayer'>&nbsp;</div>"); $("#hidden_layer").expose({ maskId: "mask", color: "#000", opacity: 0.8, api: true, onClose: function(event) { zplayer.unload(); $("#hidden_layer").html(""); } }).load(); zplayer = $f("zoomplayer", "/fileadmin/templates/res/7d/f/flowplayer-3.1.5.swf", { clip: { autoPlay: true, autoBuffering: true, scaling: 'fit' }, playlist: [ clip.completeUrl ] }); zplayer.load(); return false; }, clip: { autoPlay: false, autoBuffering: true, scaling: 'fit' },
		playlist: plist });
}
function play_video_mini(pdiv, plist) {
	flowplayer(pdiv, {src: '/fileadmin/templates/res/7d/f/flowplayer-3.1.5.swf', wmode: 'transparent'}, { plugins: { controls: { time: false } }, onBeforeFullscreen : function() { this.pause(); clip = this.getClip(); seek = this.getTime(); this.stopBuffering(); $("#hidden_layer").show(); $("#hidden_layer").html("<div id='zoomplayer'>&nbsp;</div>"); $("#hidden_layer").expose({ maskId: "mask", color: "#000", opacity: 0.8, api: true, onClose: function(event) { zplayer.unload(); $("#hidden_layer").html(""); } }).load(); zplayer = $f("zoomplayer", "/fileadmin/templates/res/7d/f/flowplayer-3.1.5.swf", { clip: { autoPlay: true, autoBuffering: true, scaling: 'fit' }, playlist: [ clip.completeUrl ] }); zplayer.load(); return false; }, clip: { autoPlay: false, autoBuffering: true, scaling: 'fit' },
		playlist: plist });
}

/* DOM READY CODE */
Cufon.DOM.ready (
	function() {
		Cufon.replace('a.series', { hover: true });
		Cufon.replace('#navigation a.level1', { hover: true });
		//Cufon.replace('#extras_1', { hover: true });
		//Cufon.replace('#extras_2', { hover: true });
		Cufon.replace('#footer');
		Cufon.replace('#content_main h1');
		Cufon.replace('#content_main h2');
		Cufon.replace('#content_main_products h1');
		Cufon.replace('#content_main_products h2');
		Cufon.replace('.content_main_news h1');
		Cufon.replace('.content_main_news h2');
		Cufon.replace('#content_left h2');
		Cufon.replace('#content_left div.section_grey span');
		Cufon.replace('#content_left_products h2');
		Cufon.replace('#content_right_products h2');
	}
);

$(function() { 

	/* Navigation */
		
	$("#serieslist li").mouseover(function()
	{
		//if($('#hidden_layer').css('display') != 'none')
		//{
			$('#hidden_layer').fadeOut();
		//}
		$(this).children("a.series").addClass('act');
		$("ul.layer").css('display','none');
		$(this).children('ul.layer').css('display','block');

		$(this).children("li.link a").mouseover(function(){
			var imageSrc = $(this).attr("rel");
			var imageTitle = $(this).attr("title");
			var img = $(this).parent().parent().children('.images').children('img');
				img.attr('src',imageSrc);
				img.attr('title',imageTitle).attr('alt',imageTitle);
		})
	}).mouseout(function(){
			$(this).children("a.series").removeClass('act');
			$(this).children('ul.layer').css('display','none');
		 
	});
	
 
 	
 	$("#distributorfilter").change(function()
	{										
		$("#distributorfilter option:selected").each(function () 
		{
			var v = $(this).val();			
			if(v == '' )
			{	
				$("div.sale").show();
			}
			else
			{
				$("div.sale").hide();
				$( "div[dBTCountry="+v+"]" ).show();
			}
		});
	});
	
	$("#distributorfilterAdd").change(function()
	{										
		var country = $("#distributorfilter option:selected").val();
		var sortBy = $("#distributorfilterAdd option:selected").val();
		
		if(sortBy != '')
		{
			
			$( "div[dBTCountry="+country+"]" ).tsort({attr:sortBy});
			$("h2[dBTHeadline="+country+"]").remove();
			$( '<h2 dBTHeadline="'+country+'">'+country+'</h2>' ).prependTo("div[dBTCountry="+country+"]:first");
			Cufon.refresh('#content_main_products h2');
		}		
	});
	
 	
 
	
	$("#nav_aspeakers").click(function(event){ loadMenu(this, 'active_speaker'); return false;});
	$("#nav_pspeakers").click(function(){ loadMenu(this, 'passive_speaker');return false;});
	$("#nav_amplifier").click(function(){ loadMenu(this, 'amplifier');return false;});
	$("#nav_wirelessmicro").click(function(){ loadMenu(this, 'wmicrophone');return false;});
	$("#nav_inear").click(function(){ loadMenu(this, 'inear');return false;});
	$("#nav_controller").click(function(){ loadMenu(this, 'controller');return false;});
	
	
	//$(obj).overlay({ target: '#hidden_layer', expose: '#000000',left: '0',absolute:false,onBeforeLoad:function(event){loadMenu(this, 'active_speaker');},});
	
	// Bind Technology links
	
$("ul.technologylist li a").click( function(){ loadTechnologyLayer( $(this).attr('href') ); return false; });

if( $(".scrollable").length > 0 )
{
	$(".scrollable .items div a").click( function(){ loadTechnologyLayer( $(this).attr('href') ); return false; });
	$(".scrollable").scrollable({circular:true, prev:'.scrollableCnt .prev',next:'.scrollableCnt .next'});
}

/*
overlay({ 
		    target: '#hidden_layer', 
		    // optional exposing effect 
		    expose: '#000',
		    left: '0',
			absolute:false,
			onBeforeLoad:function(event){ loadTechnologyLayer( this.getTrigger().attr('href') );},
		})
*/
	

	


	/* Product Template */
	$("#showDesc").click( function(){ 
			$(this).hide();
			$("#hideDesc").show();
			$("span.more").show('slow');
	});
	
	$("#hideDesc").click( function(){ 
			$(this).hide();
			$("#showDesc").show();
			$("span.more").hide();
		});
		
	
	/* Generic */

  //  $("#series ul.layer").dropShadow({left: 2, top: 2, opacity: 0.5, blur: 2});
  
  
  	//$('#gallery').bind('mouseenter mouseleave mouseup', function() {
  	//	$(this).children('.info').css({"width":"100%"});
	//});

  
  // Home Fader
  if ($('#fader').length == 0) {
  	$('#blender img:first').addClass('active');
  	$('#blender img').click( function(){ if( $(this).attr('longdesc') )location.href=$(this).attr('longdesc'); });
  	$('#blender img').mouseover( function(){ if( $(this).attr('longdesc') ){$(this).css('cursor','pointer') }else{ $(this).css('cursor','')}; });
  	setInterval( "slideSwitch()", 7500 );
  }
  //language Navigation
  
  var langhtml = '<div id="langlayer"><ul><li><a href="index.php?L=0" id="enlink">English</a></li><li><a href="index.php?L=1" id="delink">Deutsch</a></li><li><a href="index.php?L=2" id="itlink">Italiano</a></li><li><a href="/fileadmin/catalogues/fr/web/index.html" id="frlink" target="_blank">Français</a></li><li><a href="/fileadmin/catalogues/es/web/index.html" id="eslink" target="_blank">Español</a></li><li class="last"><p><span>&nbsp;</span></p></li></ul></div>';
  
  	$('#nav_country').click(
  		function()
  		{
  			if ($('#langlayer').length == 0) $(langhtml).insertBefore('#hidden_layer');
  			$('#langlayer').show();
  			$('#langlayer').mouseenter().mouseleave(function(){$(this).hide();});
  			my_url = location.href;
  			my_url = my_url.replace(/#.*$/,"");
  			/* needs realurl parsing */
  			my_idx = my_url.search(/[?&]L=[0-9]/);
  			if (my_idx > 0) {
  				$('#enlink').attr("href", my_url.replace(/L=[0-9]/, "L=0"));
  				$('#delink').attr("href", my_url.replace(/L=[0-9]/, "L=1"));
  				$('#itlink').attr("href", my_url.replace(/L=[0-9]/, "L=2"));		
  			} else {
  				my_gap = "?";
  				my_idx2 = my_url.indexOf("?"); 
  				if (my_idx2 > 0) my_gap = "&"; 
				$('#enlink').attr("href", my_url+my_gap+"L=0");
				$('#delink').attr("href", my_url+my_gap+"L=1");
				$('#itlink').attr("href", my_url+my_gap+"L=2");
  			}
  			return false;
  		}
  	);
  	
  	/* Grab Language */
	$("#navigation form:first").attr("action",'/index.php?id=34&L=0');
  	$("#navigation form:first input[name=tx_indexedsearch[lang]]").val(0);
	my_idx = location.href.search(/[?&]L=1/);
	if (my_idx>0) {
		$("a#nav_country").text("Sprache");
		$("a#nav_search").text("Suche");
		$("a#nav_home").attr("href",'/index.php?L=1');
		$("a#nav_search").attr("href",'/index.php?id=34&L=1');
		$("#logo a:first").attr("href",'/index.php?L=1');
		$("#navigation form:first").attr("action",'/index.php?id=34&L=1');
		$("#navigation form:first input[name=tx_indexedsearch[lang]]").val(1);
	}
	my_idx = location.href.search(/[?&]L=2/);
	if (my_idx>0) {
		$("a#nav_country").text("Language");
		$("a#nav_search").text("Cerca");
		$("a#nav_home").attr("href",'/index.php?L=2');
		$("a#nav_search").attr("href",'/index.php?id=34&L=2');
		$("#logo a:first").attr("href",'/index.php?L=2');
		$("#navigation form:first").attr("action",'/index.php?id=34&L=2');
		$("#navigation form:first input[name=tx_indexedsearch[lang]]").val(2);	
	}
	Cufon.refresh("#navigation a.level1");
});