$('html').addClass('js'); 


$(function(){

	
	news_rotation(4000);	
	
	
	/* lang_nav*/
	$('#lang_nav').addClass('activated');
	$('#lang_nav').hover(function(){
		$(this).addClass('expand');
	}, function(){
		$(this).removeClass('expand');
	});
	
	
	/* load cycle script if id "visuals" is set */
	if( $('.cycle').length > 0 ) {
		$.getScript("../js/lib/jquery.cycle.js", function(){
		
			// homepage
			$('#homepage .cycle').cycle({
					delay: 0,
					speed: 2000,
					timeout: 6000
				});
				
			// productpage
			$('.productpage .cycle').cycle({
					delay: 0,
					speed: 2000,
					timeout: 6000
				}).append('<span id="cycle-panel" class="play"/>').before('<div id="product-wrapper"></div>').hover(
				function () { 
					$(this).addClass('cycle-hover'); 
				},  
				function () { 
					$(this).removeClass('cycle-hover'); 
				} 
			);
			
			
			// homepage
			$('#inspiration .cycle').cycle({
					delay: 0,
					speed: 2000,
					timeout: 4000
			});
		
			
			// cycle-panel action
			$('#cycle-panel').toggle( 
      		function () { 
      			$('.cycle').cycle('pause');
        			$(this).toggleClass('play').toggleClass('pause'); 
      		}, 
      		function () { 
      			$('.cycle').cycle('resume');
        			$(this).toggleClass('play').toggleClass('pause'); 
      		} 
    		); 
    		
    		$('#colorpanel a').click(function(){
    			var img_url = this.href;
    			var img = new Image();
    			var productBox = $('#product-wrapper');
    			var cycleBox = $('.cycle');
    			
    			cycleBox.cycle('pause');
    			productBox.empty().addClass('active loading');
    			   			
    			$(img).load(function () {
            	$(this).hide();
            	productBox.append(this).find('img').stop().fadeIn('slow').animate({opacity: 1.0}, 4000,function(){    
            		productBox.removeClass('loading').find('img').fadeOut('slow', function(){
        					productBox.removeClass('active');
        					cycleBox.cycle('resume');
        				});        				
    				});    				
        		}).error(function () {
            	alert('Bild konnte nicht geladen werden!');
            	productBox.removeClass('active');
        			cycleBox.cycle('resume');
        		}).attr('src', img_url);
        		return false;
    		});
    		
    		
    					
						
		});
	}/*end of cycle script */
	
}); /* end of dom:ready */




function news_rotation(mseconds){
	if ( $('#news li').length > 1) {
		var active_elem = $('#news li:visible');
		if (active_elem.length != 1 || $(active_elem).next('li').length == 0) {
			active_elem = $('#news li:first');
		} else {
			active_elem = $(active_elem).next('li');
		}  
		$('#news li:visible').hide().removeClass('active');
		$(active_elem).fadeIn('slow').addClass('active');
		window.setTimeout('news_rotation('+mseconds+')', mseconds);
	} else {
		$('#news li:first').addClass('active');
	}
}


