var menuShown;
$(document).ready(function(){
	$("#navigation ul li a.level1").hover(function() {

	$(this).parent().find("ul").show(); 
	
		$(this).parent().hover(function() {
			}, function(){	
			menuShown=$(this).parent().find("ul").hide();
                       //window.setTimeout("hideMenu()",500)
		});
	});

	$(".langselect").click(function(event){
		$(".lang ul").show();
		$(".lang ul li.selected").hide();
	event.stopImmediatePropagation();


	});
	//$("body").click(function(){
		//$(".lang ul").hide('fast')
	 //});
});


function hideMenu(){
	if (menuShown){
		menuShown.slideUp('fast'); 
	}
}

//CYCLE
var itemsToAnimate
var currentNum=0
$(document).ready(function(){
//home page animation
$('#slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:5000
		
});

$('#texts-home #product_slide').cycle({
		fx: 'none', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:1000
		});

$('#texts-index-test #product_slide').cycle({
		fx: 'none', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout:1000
		});
	
	
});

function animate(){
//preppare next div
if(currentNum+1>= itemsToAnimate.length){
	NextNum=0;
}else{
	NextNum=currentNum+1
}
mHeight=(-1)*parseInt($('#slideshow .item').height());
//$(itemsToAnimate[NextNum]).css({marginTop: mHeight+'px'});
$(itemsToAnimate[currentNum]).hide();
currentNum++
	if(currentNum>=itemsToAnimate.length)
	currentNum=0

	$(itemsToAnimate[currentNum]).fadeIn('slow');
	
}





//Accordian

$(document).ready(function(){
$('#accordion .item h2:first-child').show();
$('#accordion .item h2').click(function(ev){	
$(this).addClass('selected');
var el = $(ev.target).next("#accordion .section-text");
var els= $('#accordion .section-text'); /*get a reference to all products*/
var hds=$('#accordion .item h2'); /*get a reference to all headings*/
var open=true;
if($(el).css("display")=="block"){
 open=false;
}

/*close all open accordion panels*/
for (i=0;i<els.length;i++){
if ($(els[i]).css("display")=="block") {
	$(els[i]).slideToggle('fast',fixright);
	$(hds[i]).removeClass('selected');
}}

	if(open){
	/*slide the selected product open*/
	el.slideToggle('fast',fixright);
	}
});
});
 
//fix rightmargin alignment
$(document).ready(function(){
	fixright()
	//for some reason if highlight is loaded from magento 
	//page needs fixing little later.
	window.setTimeout("fixright()",500);
})
function fixright(){
 	 ht=$("#highlights").height();
	 ht=ht+12;
	 $('#content').attr("style","min-height:"+ht+"px");
      //	$(".footer").css({display:'block'});
	 /* ht2=$('#content').height();
	
	 if(ht2+20<ht){
		$("#content").css({height:ht+"px"})
		ht3=$('#content').height();
		$("#content").css({height:ht3+"px"});
		$("#content").css({marginBottom:20+"px"})
	} else{
		$(".footer").css({marginTop:30+"px"})
	}*/
	}
//to keep fade effect in highlight's teaser image
$(document).ready( 
    function(){    
     $('#highlights .teaser').innerfade({ speed: 5000, timeout: 10000, type: 'sequence', containerheight: '320px' }); 
     } 
   ); 

//equal height for product overview page
$(document).ready(function(){
	//ht=$('.short-description').setToMaxHeight();
	//$('.product-image').height((ht+32)+"px");
})

$(document).ready(function(){
	$('#texts-mein-salomon-30-jahre td.food-action').each(function(){
				//ht=$(this).height();
                                    //$(this).children().height(ht+"px")
				  })
});

// code to open send a friend with lighbox effect
$('#sendAFriend').live('click',function(){ 
$('#overlay_image').show();
	$.ajax({ url: this.href,cache:false,success:function(data){					
				$('#overlay_image').show();
				$('#ajax_window').show();
				
				var top=$(document).scrollTop()+5;
				
				$('#ajax_window').attr('style','top:'+top+'px;')
				$('#overlay_image').height($(document).height());
				$('#ajax_window').html(data);

		$('#ajax_window span a').live('click',function(){
			$('#overlay_image').hide();
			$('#ajax_window').hide();
			return false;
		});
		$('#ajax_window a.close').live('click',function(){
			$('#overlay_image').hide();
			$('#ajax_window').hide();
			return false;
		});	
							
	}})

		
		return false;
});

//intercool swf loader
$(document).ready(function(){
$('#intercool-countdown').html('<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="312" height="198">'+
  '<param name="movie" value="/swf/intercool-countdowntimer.swf" />'+
  '<param name="quality" value="high" />'+
  '<param name="wmode" value="opaque" />'+

  '<param name="swfversion" value="9.0.45.0" />'+
  '<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->'+
  '<param name="expressinstall" value="Scripts/expressInstall.swf" />'+
  '<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->'+
  '<!--[if !IE]>-->'+
  '<object type="application/x-shockwave-flash" data="/swf/intercool-countdowntimer.swf" width="312" height="198">'+
   ' <!--<![endif]-->'+
    '<param name="quality" value="high" />'+
    '<param name="wmode" value="opaque" />'+

    '<param name="swfversion" value="9.0.45.0" />'+
    '<param name="expressinstall" value="Scripts/expressInstall.swf" />'+
    '<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->'+
    '<div>'+
      '<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>'+
     '<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>'+
    '</div>'+
    '<!--[if !IE]>-->'+

 ' </object>'+
  '<!--<![endif]-->'+
'</object>'
)
})


//news accordion
function initMenu() {
  jQuery('#news-accordion div.item').hide();
  jQuery('#news-accordion div.item:first').show();
  jQuery('#news-accordion li h3').click(
    function() {
      var checkElement = jQuery(this).next();
      if((checkElement.is('div.item')) && (checkElement.is(':visible'))) {
        return false;
        }
      if((checkElement.is('div.item')) && (!checkElement.is(':visible'))) {
        jQuery('#news-accordion div.item:visible').slideUp('slow');
        checkElement.slideDown('slow');
        return false;
        }
      }
    );

 jQuery('#produkte .item:even').addClass("even");
  //jQuery('#award .awards').hide();
  //jQuery('#awards .awards:first').show();
  
  jQuery('#award li a').click(
    function() {
      var checkElement = jQuery(this).next();
      if((checkElement.is('.awards')) && (checkElement.is(':visible'))) {
        return false;
        }
      if((checkElement.is('.awards')) && (!checkElement.is(':visible'))) {
        jQuery('#award .awards:visible').slideUp('slow');
        checkElement.slideDown('slow');
        return false;
        }
      }
    );
  }
jQuery(document).ready(function() {initMenu();});



// lightbox effect for video
jQuery(document).ready(function(){
			//Examples of how to assign the ColorBox event to elements
			jQuery("#news-accordion .section-image a").colorbox({iframe:true, innerWidth:480, innerHeight:385});
	jQuery("#news-accordion .section-image a").click(function(){jQuery('#cboxOverlay').height(jQuery(document).height());})

});

 function showUrkunde(n){
jQuery(document).ready(function(){
jQuery('#unternehmen .item:nth-child('+n+') a').click();
})
}

jQuery(document).ready(function(){
	jQuery("#unternehmen .item:nth-child(4)").addClass("alt");
})
