// JavaScript Document

$(window).load(function(){
	
/* LOGIN CONNEXION*/
	// réaffiche le form de connexion au clic.
	$('#connexion h3').click(function() {
		$('#connexion form').toggle('slow', function() {});
	});
	
/* SMENU COLLECTIONS */
	if($("#smenuCollection").length > 0){
		// masque le menu de gaughe au chargement,
		if( $('#smenuCollection.hide_smenu_false').length > 0 ) { $('.arrLeft').fadeIn(1000); }
		$('#smenuCollection.hide_smenu_false')
			.animate({ left: '0px' }, 1000, function(){ 
				$(this).delay('3000').animate({ left: '-190px' }, 1500 );
				$('.arrRight').delay('3000').fadeIn(1000); 
				$('.arrLeft').delay('3000').fadeOut(1000); 
			});
			
		
		if( $('#smenuCollection.hide_smenu_true').length > 0 ) { $('.arrRight').fadeIn(1000); }
		$('#smenuCollection.hide_smenu_true').animate({ left: '-190px' }, 1000);
	
		$('#smenuColShow').toggle(function() {
			if ($('#header:animated').length > 0) { return false; }
			$('#smenuCollection').animate({ left: '0px' }, 1000);
			$('.arrRight').fadeOut(1000);
			$('.arrLeft').fadeIn(1000);	
		}, function() {
			if ($('#header:animated').length > 0) { return false; }
			$('#smenuCollection').animate({ left: '-190px' }, 1000);
			$('.arrRight').fadeIn(1000); 
			$('.arrLeft').fadeOut(1000);		
		});
		
		//masque la col gauche si on clique dans le menu
		$('#smenuCollection ul').click(function() {
			if ($('#header:animated').length > 0) { return false; }
			$('#smenuCollection').animate({ left: '0px' }, 1000, function(){ $('.arrRight').fadeOut(1000); $('.arrLeft').fadeIn(1000); });		
		});
		
	}
	
/* SCROLL DES THUMBS DU FLOWPLAYER */
	$('#flowpanes').css({'min-height' : function(index, value) { return $('#flowpanes .item:first').height(); }});
	if($("#thumbs").length > 0){
	$("#thumbs").smoothDivScroll({
		scrollingHotSpotLeft: 'a.pageLink.prev',
		scrollingHotSpotRight: 'a.pageLink.next',
		scrollWrapper: 'div#thumbs-container',
		scrollableArea: 'ul.thumbs',
		visibleHotSpots: '',
		startAtElementId: $('.navigation-container ul.thumbs li.selected').attr('id')
	});
	}
	
/* ZOOM */
	if($('.zoomObject').length > 0){
	//initialise le zoom pour les images du produit
	$('.zoomObject').ddxZoom();
	$('#leftCol div:first').css("display","block");
	
	$('#otherviews a').click(function(){
		$(".zoomImages").css("display","none");	
		$('#otherviews a.active').removeClass('active');
		$(this).addClass('active');		
		$( $(this).attr('rel') ).css("display","block");		
		return false;
	});
	}
	
/* FLOWPLAYER : GALERIE D'IMAGES */		
	if($("#flowpanes").length > 0){
	$("#flowpanes").scrollable({
			mousewheel: false,
			keyboard: false
		}).navigator({
		navi: "#flowtabs",
		naviItem: 'a',
		activeClass: 'current',
		history: true
	});
	}

/* MEDIA PLUGIN : lecture des flv */
	if($('#flv').length > 0){
	$('#flv a').media({
		bgColor:'transparent'
	}); 
	}


/* MENU ANIMATION : underline */
	$('#globalnav').slidingMenu();

/* MANUFACTURE */
	if( $('body.manufacture').length > 0 ){
		$(".manufatureItem.current").show();
		
		$("#leftCol li a").click(function(){
			if( ! $(this).parent().hasClass('current') ){
				clickedItem = $(this).parent();
				$("#leftCol li.current").removeClass('current').slideUp(500, function(){
					$(this).appendTo("#leftCol ul");
					$(this).slideDown(500);
				});
				var clickedItem = $(this); 
				$(".manufatureItem.current").removeClass('current').fadeOut(500, function(){
					clickedItem.parent().addClass('current');
					$( clickedItem.attr('rel') ).addClass('current').fadeIn(500, function(){
						Scrollbar.update();
					});
				});
			}
			return false;
		});
	}

/* CONTENT DRAG SCROLLER : descriptif mouvement montre 	*/
	if($('.scrollcontent').length > 0){
		var Scrollbar = $('.scrollcontent');
		Scrollbar.tinyscrollbar({ axis: 'y'});
	}
	
/* COMMANDE : en pop-up */
	if( $(".fiche_detail #commander").length > 0){
		
		$("#commander a[rel]").overlay({
			top: "20%",
			left: "38%",
			onLoad: function() {
				//remplit le champ hidden avec la ref
				$(".contentWrap #comm_ref").attr('value', $("#montre_ref").text());
			}
	
		});
	}	
	
	if( $("#commande-form").length > 0){	
		if($("#commande-form p.no-error").length > 0){
			$('form#commande').hide();
		}else{
			// show/hide forms selon si l'utilisateur veut renseigner son tel/mail
			if( ! $('#comm_contact_tel').is(':checked') ){
				$('#commander_tel').css({"display":"none"});
			}
			if( ! $('#comm_contact_mel').is(':checked') ){
				$('#commander_mail').css({"display":"none"});
			}
			
			$("#comm_contact_tel").click(function() {
				// this function will get executed every time the #home element is clicked (or tab-spacebar changed)
				if($(this).is(":checked")) // "this" refers to the element that fired the event
				{
					$("#commander_tel").show('slow');
				}else{
					$("#commander_tel").hide('slow');
				}
			});
			
			$("#comm_contact_mel").click(function() {
				// this function will get executed every time the #home element is clicked (or tab-spacebar changed)
				if($(this).is(":checked")) // "this" refers to the element that fired the event
				{
					$("#commander_mail").show('slow');
				}else{
					$("#commander_mail").hide('slow');
				}
			});
		}
	}
	
/* LINK SEIKO -> to SeikoFrance */
$("#linkToSeikoFrance[rel]").overlay({top: '35%'});

$('#boxToSeikoFrance li a').click(function(){ window.open( $(this).attr('href') ); return false; });

/*end $(window).load */
});
