jQuery.fn.nodeIndex=function(){return jQuery(this).prevAll().length};
function setLinks(){if(!document.getElementsByTagName)return false;var links=document.getElementsByTagName("a");if(links.length==0)return false;for(var i=0;i<links.length;i++){var relation=links[i].getAttribute("rel");if(relation=="external"){links[i].onclick=function(){return!window.open(this.href)}}}}

jQuery(document).ready(function($){
	setLinks();
	
	$('#menu ul ul li a.active').parents('ul').fadeIn(0);
	
	$('#menu ul ul').parent().addClass("avai");
	$('.avai > a').attr({href:"javascript:void(0)"});
	$('.avai').live('click',function(){
		$('#menu ul ul').fadeOut(0);
		$('ul',this).fadeIn(0);
	});
	
	
	if($('#bg_hide').length>0){
		var slide_bg = new Array;
		$('#bg_hide li').each(function(i){
			slide_bg[i]={image:$('img',this).attr('src')};
		});
		$.supersized({
			slide_interval:6000,
			transition_speed:800,
			new_window:0,
			fit_portrait:1,
			slides:slide_bg
		}); 
	}else{
		$('#supersized,#supersized-loader').css({display:"none"})
	}
	
	
	jQuery.carrousel(jQuery('.gamme:not(.elementVisuel)'),jQuery('.elementVisuel'));
	jQuery('.gamme:not(.elementVisuel) .scrol').each(function(){
		if(jQuery(this).height() > jQuery('.scrolto',this).height() )
			jQuery(this).parents('.dataa').addClass('off');
		jQuery(this).simplyScroll({className:'vert',horizontal:false,frameRaste:20,speed:5});
	});
	
	jQuery('.vfctn .scrol,#ctn_normal .scrol').each(function(){
		if(jQuery(this).height() > jQuery('.scrolto',this).height() ){
			jQuery(this).parents('.dataa').addClass('off')}
		jQuery(this).simplyScroll({className:'vert',horizontal:false,frameRaste:20,speed:5});
	});
	
	/* Make up class */
	jQuery.carrousel(jQuery('.look_0'));
	jQuery.carrousel(jQuery('.look_1'));
	jQuery.carrousel(jQuery('.blocTendances'));
	
	jQuery('.look_0 .visuel,.look_1 .visuel').live('click',function(){if(jQuery(this).hasClass('inAction'))return false;else{jQuery(this).addClass('inAction');var a=jQuery(this).attr('id').replace(/id/,'');jQuery.carrousselMoveTo(jQuery('.blocTendances'),a,jQuery(this))}return false});
	jQuery('.detailProduit .scroll').simplyScroll({className:'vert',horizontal:false,frameRaste:20,speed:5});
	jQuery('.detailInfos .scroll').simplyScroll({className:'vert',horizontal:false,frameRaste:20,speed:5});
	
	jQuery('.detailTendance ul li').each(function(){
		var c=jQuery(this).height();
		var d=jQuery('a',this).height();
		var t=Math.ceil((c-d)/2);
		jQuery('a',this).css('marginTop',t);
	});
	
	
	
	/* Histoire */
	jQuery('.listBloc .bloc:last').css({borderRight:'0 none',paddingRight:'0',marginRight:'0'});
	jQuery('.grandScroll .page').each(function(){jQuery('.bloc:last',this).css({borderRight:'0 none',paddingRight:'0',marginRight:'0'})});
	jQuery('.listBloc .bloc img[align=left],.grandScroll .page .bloc img[align=left]').css('marginRight','10px');
	jQuery('.listBloc .bloc img[align=right],.grandScroll .page .bloc img[align=right]').css('marginLeft','10px');
	jQuery('.grandScroll .page .bloc .story').css({width:'100%',height:'100%'});
	jQuery('.miniatureScroll .page:last').css('background','0 none');
	jQuery.carrousel(jQuery('.grandScroll'));
	jQuery.carrousel(jQuery('.miniatureScroll'),false,3);
	jQuery('.miniatureScroll .page img').live('click',function(){if(jQuery(this).hasClass('inAction'))return false;else{jQuery(this).addClass('inAction');var a=jQuery(this).attr('id').replace(/id/,'');jQuery.carrousselMoveTo(jQuery('.grandScroll'),a,jQuery(this))}return false});
	
	/* Produits */
	jQuery('.produit #bigimg').html('<img src='+$(".produit .itemlist:eq(0) li:eq(0) a").attr("href")+' alt="" />');
	jQuery('.produit .tabs_thumbs a').each(function(){
		var produitnode = $(this).nodeIndex();
		jQuery(this).click(function(){
			jQuery('.produit .tabs_thumbs a.active').removeClass('active');
			jQuery(this).addClass('active');
			jQuery('.produit .itemlist').removeClass('active');
			jQuery('.produit .itemlist:eq('+produitnode+')').addClass('active');
			jQuery('.produit .thumbslist').mouseScroller();
			return false
		})
	});
	jQuery('.produit .thumbslist').mouseScroller();
	
	jQuery('.descriptionProduit .scroll').simplyScroll({className:'vert',horizontal:false,frameRaste:20,speed:5});
	
	jQuery(".produit .itemlist a").each(function(){
		jQuery(this).click(function(){
			var $this = jQuery(this)
			jQuery('.produit #bigimg').html('<img src='+$($this).attr("href")+' alt="" />');
			return false;
		});
	});
	
	function align(){
		var a=document.getElementById('wra');
		var b=document.documentElement;
		if(a&&b){
			var c;
			if(b.innerWidth)
				c=b.innerHeight;
			else 
				c=b.clientHeight;
				
			var d;
			if(a.innerWidth)
				d=a.innerHeight;
			else 
				d=a.offsetHeight;
				
			var y=Math.ceil((c-d)/2);
			if(y<0)
				y=0;
			
			a.style.position="relative";
			a.style.top=y+"px"
		}
		if(document.getElementById)
			document.body.style.visibility='visible';
		jQuery('#Content').css('visibility','visible');
	}
	
	function addevent(a,b,c,d){if(a.addEventListener){a.addEventListener(b,c,d);return true}else if(a.attachEvent){a.attachEvent('on'+b,c);return true}else return false}
	if(document.getElementById&&document.getElementsByTagName){addevent(window,'load',align,false);addevent(window,'resize',align,false)}
})
