jQuery.noConflict();

/*
 * General DOM ready statemenets
 */
jQuery(function($) {
	
	$('li').mouseover(function(){
		$(this).addClass('over');
	}).mouseout(function(){
		$(this).removeClass('over');
	})
		

	$('.home-js .js_item').each(function(){
		$(this).css({'background':$(this).attr("title")+' url('+$(this).children('img').attr('src')+') no-repeat scroll 50% 0','width':'100%','height':'100%'});
		$(this).children('img').remove();
	})
	
	$('.home-js').cycle({
		fx: 'fade',
		speed: 'fast',
		timeout: 6000,
		pager: '#control_panel'
	}); 	
	

	//$('#nav').jScrollHorizontalPane({showArrows:true});
		
	
	//下拉菜单
	$("#select-language").selectbox();
	
	$(".IM_trier-par").selectbox();
	
	$(".IM_afficher").selectbox();

	//左右滑动
	$(".scrollable").scrollable({circular:true});
	
	
	

	if($(".IM_current-s-b ol.currently").length>0){
		$(".scrollable").css('width','500px');
	};

	if($(".category-tv-led").length>0){
		$("#nav .nav-1 a .IM_top-tv").css('background-position','-1px -64px');
	};
	if($(".category-dvd-blueray").length>0){
		$("#nav .nav-2 a .IM_top-dvd").css('background-position','-118px -32px');
	};
	if($(".category-micro-chaines").length>0){
		$("#nav .nav-3 a .IM_top-mc").css('background-position','-107px -124px');
	};
	if($(".category-station-d").length>0){
		$("#nav .nav-4 a .IM_top-sd").css('background-position','-218px -84px');
	};
	if($(".category-boombox").length>0){
		$("#nav .nav-5 a .IM_top-boom").css('background-position','-314px -93px');
	};
	if($(".category-radio-reveils").length>0){
		$("#nav .nav-6 a .IM_top-rr").css('background-position','-400px -87px');
	};
	if($(".category-test-1").length>0){
		$("#nav .nav-7 a .IM_top-t1").css('background-position','-1px -64px');
	};
	if($(".category-test-2").length>0){
		$("#nav .nav-8 a .IM_top-t2").css('background-position','-118px -32px');
	};
	if($(".category-test-3").length>0){
		$("#nav .nav-9 a .IM_top-t3").css('background-position','-107px -124px');
	};
	

	$(".form-language").hover(function () {
		$('.form-language ol').show();
	},function(){
		$('.form-language ol').hide();
	}); 
	
	
	
	//上下滚动条
	$('.block-layered-nav .scroll-pane').jScrollPane(); 
	
	//tabs
	$('.tab1').click(function(){
		$('.IM_tabs .tab').removeClass('actived');
		$(this).addClass('actived');	
		$('.product-view .product-collateral .box-collateral').css({"display":"none"});
		$('.product-view .product-collateral .box-description').css({"display":"block"});		
	});
	
	$('.tab2').click(function(){
		$('.IM_tabs .tab').removeClass('actived');
		$(this).addClass('actived');
		$('.product-view .product-collateral .box-collateral').css({"display":"none"});
		$('.product-view .product-collateral .box-additional').css({"display":"block"});
	});
	
	$('.tab3').click(function(){
		$('.IM_tabs .tab').removeClass('actived');
		$(this).addClass('actived');
		$('.product-view .product-collateral .box-collateral').css({"display":"none"});
		$('.product-view .product-collateral .box-manuel').css({"display":"block"});
	});
	
	$('.tab4').click(function(){
		$('.IM_tabs .tab').removeClass('actived');
		$(this).addClass('actived');
		$('.product-view .product-collateral .box-collateral').css({"display":"none"});
		$('.product-view .product-collateral .box-fiche').css({"display":"block"});
	});
	
	if(!$(".breadcrumbs").length>0){
		$('.col-main').before('<div class="IM_col-main-top"></div>');
	};
	
	/*
	 * Slider
	 */
	var $slideshow = $('#nav');
	width = 0;
	$slideshow.find('li').each(function(){
		var li = 151;
		width += li;
	}).end().width(width);
	ulwidth=width;
	leftdefault = 0;
	width -= 960+6;
	var step = width/99;
	$slideshow.css({'left':leftdefault*0.5,'width':ulwidth+'px'});
	if(ulwidth>960){
		var $slideBar = $('#slide-bar').slider({
			slide: function(event, ui){
				left = -ui.value*step;
				$slideshow.css('left',left);
				scrolling = false;
			},
			change: function(event, ui){
				left = -ui.value*step;
				$slideshow.css('left',left);
			}
		});
		$('#slide-bar').slider({ value: 0 });   
			
		$('#slider-next, #slider-prev').mousedown(function(event){
			scrolling = true;
			($(event.target).is('#slider-next'))?goNext():goPrev(); //See if we are going forward or backwards											
		}).mouseup(function(event){
			scrolling = false;
		});

	}
	
	
});


var scrolling = true;

function goNext(){
	var $slideBar = jQuery('#slide-bar');
	var value = $slideBar.slider('value'); //getting the slider value
	value += 1; //Going to the next step in the right direction
	$slideBar.slider('value',value); //Setting the new value
	if (scrolling) setTimeout('goNext()', 10);			
}

function goPrev(){
	var $slideBar = jQuery('#slide-bar');
	var value = $slideBar.slider('value'); //getting the slider value
	value -= 1; //Going to the next step in the right direction
	$slideBar.slider('value',value); //Setting the new value
	if (scrolling) setTimeout('goPrev()', 10);			
}

