var id_inst;

$(document).ready(function(){ 
	
	/* Boite login */
    $("a#customerloginbox").fancybox({
        'width' :   '500',
        'height':   '120',
        'autoDimensions' : false,
        'scrolling' : 'no'
    });
    
    /* Boite login */
    $("a#pwdforgottenbox").fancybox({
        'width' :   '500',
        'height':   '120',
        'autoDimensions' : false,
        'scrolling' : 'no'
    });


	//recherche
	$('#query').focus(function(){
		if($(this).val()=='Suche')
			$(this).val('');
	});
	$('#query').blur(function(){
		if($(this).val()=='')
			$(this).val('Suche');
	});


	// Navigation
	$(".Menu > ul > li").each(function() {
		var LI = $(this);
		if($(this).hasClass("DropDown")){
			$("#content").addClass("BackgroundNone");
			if($(".Menu").hasClass("SmallSubHeight")){
				$(".Menu").css({ height: 110 + "px" });
			}
			else{
				$(".Menu").css({ height: 154 + "px" });
			}
			$(this).addClass("AcitveMenu");
		}
	/*$(".IntroList").css({ opacity: 0.9 });*/
		
	/*	LI.bind("mouseover", function(evt) {
			$(this).addClass("AcitveMenu");
			closeSelectBox();
			if(!$(this).hasClass("OrangeHover")){
				$(".Menu").stop().animate({ height: 154 + "px" }, 700);
				$(".Menu > ul > li").removeClass("AcitveMenu");
				$(this).addClass("AcitveMenu");
				$("#content").addClass("BackgroundNone");
				evt.stopPropagation();
			}
			
		});
		LI.bind("mouseout", function() {
			var menuLi = $(this);
			if($(".MenuOpened").length > 0) {
				$(menuLi).removeClass("AcitveMenu");
			} else {
				if(!$(this).hasClass("OrangeHover")){
					$(".Menu").stop().animate({ height: 47 + "px" }, 700, function() { 
						$(menuLi).removeClass("AcitveMenu");
					$("#content").removeClass("BackgroundNone");
					});
				}
			}
		});  */
	});
		
	//End Navigation
	if($("#homeMenu").length > 0) {
		$("#content").addClass("HomeMenuBound");
	}
	
	if($(".HomeContent").length > 0) {
		$(".HomeContent").css({height:window.innerHeight  + 'px' });
	}
	
	
	if($(".SelectUI").length > 0) {
			$(".SelectUI").removeClass("HideThis");
			$(".SelectUI").addSelectUI({
				scrollbarWidth: 20 //default is 10
			});
			/*$(".SelectUI").jScrollPane({
				scrollbarWidth: 4,
				scrollbarMargin: 14
						   });*/
		}
		
		
	if($("#mycarousel").length > 0) {
		 $('#mycarousel').jcarousel({
				 vertical: true,
				 wrap: 'circular' ,
				 scroll: 1,
				 itemVisibleInCallback: itemScrollInCallbackFunction,
				 auto:5
		 }); 
	}
	
	//set width for test link
	/*if($(".Link").length > 0) {
		var maxwid = new Number(0);
		 $(".Link > a > span").each(function() {
			if(($(this).width()) > maxwid){
				maxwid = $(this).width();
			}
		 }); 
		 $(".Link > a > span").each(function() {
			$(this).css({width:maxwid + 'px' });
			$(".Link > a").css({width:maxwid + 44 +'px' });
		 }); 
	}
	*/
	
	if($(".LinkBoxWidth").length > 0) {
		
		var maxwid = new Number(0);
		 $(".LinkBoxWidth > .LinkBox01 > a ").each(function() {
			if(($(this).width()) > maxwid){
				maxwid = $(this).width();
			}
		 }); 
		 
		 $(".LinkBoxWidth > .LinkBox01 > a").each(function() {
			$(this).css({width:maxwid + 'px' });
		 }); 
	}
	/*if($("#mycarousel02").length > 0) {
		$('#mycarousel02').jcarousel({
			 wrap: 'circular',
			 scroll: 1
		 });
	}*/
	
	// label text
	if($(".SearchTextLabel").length > 0) {
		$(".SearchTextLabel").focus(function() {
		if($(this).val() == "Search") {
		$(this).val("");
		}
		});
		$(".SearchTextLabel").blur(function() {
		if($(this).val() == "") {
		$(this).val("Search");
		}
		});
	}

	if($(".CountryCodeLabel").length > 0) {
		$(".CountryCodeLabel").focus(function() {
		if($(this).val() == "Country code") {
		$(this).val("");
		}
		});
		$(".CountryCodeLabel").blur(function() {
		if($(this).val() == "") {
		$(this).val("Country code");
		}
		});
	}

	if($(".PhoneNumLabel").length > 0) {
		$(".PhoneNumLabel").focus(function() {
		if($(this).val() == "Phone number") {
		$(this).val("");
		}
		});
		$(".PhoneNumLabel").blur(function() {
		if($(this).val() == "") {
		$(this).val("Phone number");
		}
		});
	}
	
	
	// Create tabs
	/*if($(".MapLocation").length > 0) {
		$(".MapLocation").tabs();
	}
	*/
	// Create scroll
	/*if($(".Scroll").length > 0) {
		$(".Scroll").jScrollPane({
			scrollbarWidth: 13,
			showArrows: true
		});
	}*/
          if($("#theBasicShare").length > 0) {
		  $("#theBasicShare ul li").style.opacity = 0.5;
	  }
	
	if($(".IntroBox").length > 0) {
		jQuery(".IntroContent").hide();
		jQuery("#intro0").show();
		
		jQuery(".IntroList").css({
			display:'block'
		});

			jQuery(".IntroList li a").bind("mouseenter",function() {
				var get_box = jQuery(this).attr("rel");
				get_box = get_box.substring(1);

				jQuery(".IntroBox .Active").fadeOut(800)
				jQuery("#" + get_box).addClass("Active").stop(true,true).fadeIn(800)
				jQuery("#intro0").fadeOut(800);
			});
			jQuery(".IntroList li a").bind("mouseleave",function() {
				jQuery(".IntroBox .Active").stop(true,true).fadeOut(800)
			/*	jQuery("#intro0").addClass("Active").fadeIn(0);*/
			});
			
			jQuery(".IntroList").bind("mouseleave",function() {
				jQuery("#intro0").addClass("Active").stop(true,true).fadeIn(800);
			});

		
		
		jQuery('.IntroBox').hover(
			function(){
				clearTimeout(id_inst); 
				jQuery('.IntroBox a').removeClass('chover');
				if(jQuery('.IntroList').css('display')=='none')
				{
					jQuery('.IntroList').stop(true,true).fadeIn(400);
				}
			},
			function(){
				jQuery('.IntroList').fadeOut(400);
				jQuery("#intro0").fadeIn(400);
				id_inst=setTimeout(function() {carrousel(5000)},5000);
			}
		);
		
		jQuery('.IntroList').hide();
		id_inst=setTimeout(function() {carrousel(5000)},5000);
	}
	
	
	
	var w1 = $("a.Ferrous span").width();
	var w2 = $("a.NonFerrous span").width();
	if(w1 <= w2) {
		$("a.Ferrous span").width(w2);
	}
	else {
		$("a.NonFerrous span").width(w1);
	}
	
	if($(".Zoom").length > 0) {
		$(".Zoom").colorbox({innerWidth:700, innerheight:560, inline:true});
	}
	
	if($(".Zoomb").length > 0) {
		$(".Zoomb").colorbox({innerWidth:940, innerheight:609, inline:true});
	}

	
});

function closeSelectBox(){
	if( jQuery(".DropListUI").length > 0 ) { //hard code !!!
		if($selectDroplist_Manager.els[$selectDroplist_Manager.activeName]){
			$selectDroplist_Manager.els[$selectDroplist_Manager.activeName].hideList(); 
		}
	}
};


function carrousel(pause)
{
	var current, newcurrent;
	current=parseInt(jQuery('#carrousel_current').html());
	
	jQuery(".IntroList > li > a").removeClass('chover');
	jQuery('#intro_'+current).addClass('chover');
	//alert(jQuery('#intro_'+current).attr('id'));
	
	
	if(jQuery('.IntroList').css('display')=='none')
	{
		jQuery('.IntroList').stop().fadeIn(500);
	}
	
	jQuery(".IntroBox").fadeIn();
	jQuery(".IntroBox .Active").stop().fadeOut(500).removeClass("Active");
	jQuery("#intro" + current).addClass("Active").stop().fadeIn(500);

	newcurrent=current;
	if(newcurrent<jQuery('.IntroList li').length)
		newcurrent=current+1;
	else
		newcurrent=1;
	
	jQuery('#carrousel_current').html(newcurrent);
	
	id_inst=setTimeout(function() {carrousel(pause)},pause);
}

function itemScrollInCallbackFunction(carousel, state, evt)
{
	 var liObj = carousel.get(carousel.last);
	 var carouselitem = liObj.children();
	 var linkmore = carouselitem.children(".LinkRef").attr("href");
//	  var linkSee = carouselitem.children(".LinkRef").attr("rel");
	$(".LinkReadMore").attr("href",linkmore);
//	$(".LinkSeeCom").attr("href",linkSee);
	
};

