
$(document).ready(function(){
	$('#autresvuesZoom .autresvues_d .listpicto img').live('click', function(){
		var oldImageZoomSrc	= $('#autresvuesZoom .autresvues_g').attr('src');
		var newImageZoomSrc	= $(this).attr('src');
		//var newImageZoomSrc	= $(this).attr('src').replace('/normal/', '/zoom/');
		var divImage		= '<img width="390" height="430" title="" alt="" src="' + newImageZoomSrc + '" onmouseover="TJPzoom(this);" style="width: 390px; height: 430px;"/>';
		$('#autresvuesZoom .autresvues_g').html(divImage);
		return;
	});

	$('#couleur').live('mousedown', showColor );

});

function showProduitsComplementaires(){
	$('#produits-complementaires').slideToggle('slow');
}

function showColor(){
	$(this).blur();
	
	var displayColor = $('#showColors').css('display');
	if(displayColor == 'none'){$('#couleur').css('display', 'none');
		autoShowHide('showColors', 'show', true);$('#couleur').css('display', 'none');
	}else{
		$('#couleur').css('display', 'inline');
		autoShowHide('showColors', 'hide', true);
	}
	//$('.showColors').slideToggle('slow');
}


function assistanttaillecollant(){
	var at_taille		= $('form#get-assistant-taille #at-taille').val();
	var at_poids		= $('form#get-assistant-taille #at-poids').val();
	var at_WebService	= '/fr/webservices/assistant-taille-collant.htm';
	var at_divReload	= ".resultAssistantTaille";
	if(at_taille != '-1' && at_poids != '-1'){
		$.ajax({
			type		: "GET",
			url			: at_WebService,
			data		: "at-taille=" + at_taille + "&at-poids=" + at_poids,
			beforeSend	: function(){
				autoShowHide('bg_fonce', 'show', false);
			},
			success		: function(newContent){
				$(at_divReload).html('Taille du collant : '+newContent);
			},
			error		: function(xhr,sta,err){
				$(at_divReload).html('<strong>Service indisponible.</strong>');
			},
			complete	: function(){
				autoShowHide('bg_fonce', 'hide', false);
			}
		});
	}
}

function setColor(couleur){
	if(couleur != ''){
		$('form#adding select#couleur').val(couleur);
		showColor();
		webstock();
	}
}

/**
 * Permet de raffraichir le contenu de la div .ajaxReload
 * Quand l'utilisateur change un parametre de selection ( couleur ou taile ),
 * On fait appel au WebService interne
 * Afin de vérifier que le produit est en stock.
 * Une fois le webservice appelé, on raffraichi tout le contenu de la div.
 */
 function webstock(){
	var divReload			= '.ajaxReload';
	var fichierWebService	= '/fr/webservices/ws-collection.htm';

	var tailleValue		= $('#taille').val();
	var couleurValue	= $('#couleur').val();
	var quantiteValue	= $('#quantite').val();
	var collectionID	= $('#idCollection').val();
	if(tailleValue=='assistant'){
		javascript:autoShowHide('assistant-taille', 'show', true);
		$('#taille').val('default');
		return false;
	}
	// Envoi Ajax Webservice..
	$.ajax({
		type		: "GET",
		url			: fichierWebService,
		data		: "idCollection=" + collectionID + "&taille=" + tailleValue + "&couleur=" + couleurValue + "&quantite=" + quantiteValue,
		beforeSend	: function(){
			autoShowHide('bg_fonce', 'show', false);
		},
		success		: function(newContent){
			$(divReload).html(newContent);
		},
		error		: function(xhr,sta,err){
			$(divReload).html('<strong>Service indisponible.</strong>');
		},
		complete	: function(){
			autoShowHide('bg_fonce', 'hide', false);
			autoShowHide('assistant-taille', 'hide', true);
		}
	});
	return true;
}

function flashPopUp(data, titreCol, packCol){
	this.node	= document.createElement("div");
	$(this.node).attr({
		id: "flashPopin"
	});
	/*
	$(this.node).addClass('hide');
	*/
	$(this.node).appendTo("body");

	this.node	= document.createElement("div");
	$(this.node).addClass('box');
	$(this.node).appendTo("#flashPopin");

	this.node	= document.createElement("div");
	$(this.node).addClass('title');
	$(this.node).appendTo(".box");
	$('#flashPopin .box .title').html("<p id=\"popintitle\"></p><div class=\"boxright\"><a href='#'  onclick=\"flashPopInDesctruct();return false;\" title=\"Accéder à la fiche produit\">JE COMMANDE / + D'INFOS</a></div>");

	this.node	= document.createElement("div");
	$(this.node).addClass('titreCol');
	$(this.node).appendTo(".box");
	$('#flashPopin .box .titreCol').html(titreCol);

	this.node	= document.createElement("div");
	$(this.node).addClass('packCol');
	$(this.node).appendTo(".box");
	$('#flashPopin .box .packCol').html(packCol);

	this.node	= document.createElement("div");
	$(this.node).addClass('content');
	$(this.node).appendTo(".box");
	$('#flashPopin .box .content').html("<div class=\"animation-flash\">" + data + "</div>");

}

function flashPopinResize(){
	var screenW = 0, screenH = 0, sizeW = 1024, sizeH = 475, sizeHfull = 580, rapport = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		screenW = window.innerWidth;
		screenH = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		screenW = document.documentElement.clientWidth;
		screenH = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		screenW = document.body.clientWidth;
		screenH = document.body.clientHeight;
	}
	rapport = sizeH/sizeHfull;
	screenH = screenH*rapport;
	if (screenH<=sizeH)
		screenH=sizeH;
	/*Animation FLash - Fiche produit*/
	if ($("#flashPopin")){
		if (screenH/screenW <= sizeH/sizeW){
			//100% largeur
			$("#flashPopin").css('width', Math.round(screenW-17) +"px");
			$("#flashPopin").css('height', Math.round(screenH) +"px");
		}else if (screenH/screenW > sizeH/sizeW){
			//100% hauteur
			$("#flashPopin").css('width', Math.round(screenW) +"px");
			$("#flashPopin").css('height', Math.round(screenH) +"px");
		}
		$("#flashPopin").css('height', Math.round(screenH) +"px");
		//alert('Height: ' + $("#flashPopin").height() + ' - Width: ' + $("#flashPopin").width());
	}
	if ($("#flashPopin")){
		if (screenH/screenW <= sizeH/sizeW){
			/*document.getElementById("BackgroundImage").style.width  = (screenH*sizeW/sizeH) +"px";*/

			$('#flashPopin embed').attr('width', Math.round(screenW-17) + "px");
			$('#flashPopin embed').attr('height', Math.round(screenH ) + "px");
		}
		else if (screenH/screenW > sizeH/sizeW){
			//100% hauteur
			$('#flashPopin embed').attr('width', Math.round(screenH*sizeW/sizeH) + "px");
			$('#flashPopin embed').attr('height', Math.round(screenH) + "px");
		}
	}
}

function flashPopInDesctruct(){
	$("#flashPopin").remove();
}