var sens = 'normal';
window.addEvent('domready', function() {
	var loc	= window.location;
	if(!$('div.critere_infos') && /stickers\/produit-[0-9]{1,4}\//.test(loc))
	{
				
			var flashvars = {'imageDefault': productDatas.sizes[currentSizeID].image,
							'coulhexasticker': productDatas.color[currentColorID].co_hexa.replace('#', ''),
							'backgroundColor': currentBackgroundColor,
							'currentCadre': currentCadre,
							'currentPlante': currentPlante,
							'currentFauteuil': currentFauteuil,
							'currentSol':currentSol,
							'currentMur':currentMur
				
			};
			var params =	{'allowscriptaccess':'always'
				};
			var attributes = {};
			swfobject.embedSWF("/templates/vision-deco/swf/header/patatatato.swf?v=0.96545436", "swf_header", "948", "300", "9.0.0", "", flashvars, params, attributes, loadSuccess);

			$('taillesticker').addEvent('change', function(e) {
				changeImageJS( this.get('value') );
			});

			$('flipstickers').addEvent('click', function(e) {
				if(sens == 'normal') sens = 'inverse';
				else sens = 'normal';
				$('sens').set('value',sens);
				flash.flipImage();
			});
			
			$$('a.tooltip').each(function(element,index) 
			{
				var content = element.get('title').split('::');
				
				element.store('tip:title', content[0]);
				element.store('tip:text', content[1]);
			});
			
			var tipz = new Tips('.tooltip',
			{
				className : 'tool-tip'
			});
	}

});

function loadPopup(url) {
	jspopup = true;
	var request = new Request.HTML({
		url: url,
		onComplete: function(data, data2, data3, data4) {
		//alert(data4);


			var div = new Element('div').set('html',data3);

			var data = div.getElement('div[id=ficheproduitsticker]');

			$('anim_fen').style.visibility = 'hidden';


			popupProduct = new PopUp(false, data, 'critere_infos', 970, 30);
				
			$$('a.closepopupProduct').addEvent('click', function(e) { e.stop(); setItem(); });
			//$$('div .productColor a').addEvent('click', function(e) { changeColor( });
			var flashvars = {'imageDefault': productDatas.sizes[currentSizeID].image,
							'coulhexasticker': productDatas.color[currentColorID].co_hexa.replace('#', ''),
							'backgroundColor': currentBackgroundColor,
							'currentCadre': currentCadre,
							'currentPlante': currentPlante,
							'currentFauteuil': currentFauteuil,
							'currentSol':currentSol,
							'currentMur':currentMur
				
			};
			var params =	{'allowscriptaccess':'always'
				};
			var attributes = {};
			swfobject.embedSWF("/templates/vision-deco/swf/header/patatatato.swf?v=0.96545436", "swf_header", "948", "300", "9.0.0", "", flashvars, params, attributes, loadSuccess);

			$('taillesticker').addEvent('change', function(e) {
				changeImageJS( this.get('value') );
			});

			$('flipstickers').addEvent('click', function(e) {
				if(sens == 'normal') sens = 'inverse';
				else sens = 'normal';
				$('sens').set('value',sens);
				flash.flipImage();
			});
			
			$$('a.tooltip').each(function(element,index) 
			{
				var content = element.get('title').split('::');
				
				element.store('tip:title', content[0]);
				element.store('tip:text', content[1]);
			});
			
			var tipz = new Tips('.tooltip',
			{
				className : 'tool-tip'
			});
			

		}
	}).get();
}
/*
voir : texte-personnalise.js - inclus all time



function loadSuccess() {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        flash = window['swf_header'];
    }
    else {
        flash = document['swf_header'];
    }
}

function setItem() {
	flash.getAllDatasSWF();
	// currentColorID
	
	alert(mur);
	alert(fauteuil);
	alert(plante);
	alert(cadre);
	alert(sol);
	alert(background);
	


}


function saveSWF(mur, fauteuil, plante, cadre, sol, background) {
	
	var postDatas = {'mur':mur, 'fauteuil':fauteuil, 'plante':plante, 'cadre':cadre, 'sol':sol, 'background':background, 'colorID':currentColorID};
	var request = new Request.JSON({
		url: '/user/save-swf.html',
		onComplete: function(data) {
			popupProduct.close();
		}
	}).post({'datasSWF':postDatas});
	
}
*/ 

function changeColorStickers(id, elem) {
	$$('div.productColor a img').dispose();
	$(elem).adopt(new Element('img', {'src':'/templates/vision-deco/images/btcoul.gif', 'width':20, 'height':18, 'border':0} ));
	$('hexa_color').set('html', productDatas.color[id].co_hexa);
	flash.changeColor( productDatas.color[id].co_hexa.replace('#', '') );
	$('in_colorID').set('value', id);
	currentColorID = id;
	changePriceStickers();
}

function changeImageJS(id) {
	flash.changeImage(productDatas.sizes[id].image);
	currentSizeID = id;
	$('in_sizeID').set('value', id);
	changePriceStickers();
}

function changePriceStickers() {
	var color_price		= productDatas.color[currentColorID].co_prix;
	var money			= productDatas.color[currentColorID].co_money;
	var price_promo		= productDatas.sizes[currentSizeID].prix_promo;
	var price			= productDatas.sizes[currentSizeID].prix;

	if(price_promo.toFloat() > 0) {
		var new_price	= priceWithColorStickers(price_promo, color_price, money);
		var old_price	= priceWithColorStickers(price, color_price, money);
		$('p_old_price').setStyle('visibility', 'visible')
		$('old_price').set('html', old_price);
	}
	else {
		var new_price	= priceWithColorStickers(price, color_price, money);
		$('p_old_price').setStyle('visibility', 'hidden');
	}
	
	$('new_price').set('html', new_price);
}

function priceWithColorStickers(price, color_price, money) {
	price = price.toFloat();
	color_price = color_price.toFloat();
	if(color_price > 0) {
		if(money ==1) {
			price = price + ((price / 100) * color_price);
		}
		else {
			price = price + color_price;
		}
	}
	return price.numberFormat(2, ',','');
}

/*
function redirectPrintPage(a) {
	//location.href = a.href;
}
*/

function saveSWFStickers(mur, fauteuil, plante, cadre, sol, background, sens, url) {
	if(currentSizeID < 1) currentSizeID = '0';
	if(productID < 1) productID = '0';
	if(!sens) sens = 'normal';
	var postDatas = {'mur':mur, 'fauteuil':fauteuil, 'plante':plante, 'cadre':cadre, 'sol':sol, 'background':background, 'colorID':currentColorID, 'imageID':currentSizeID, 'sens':sens, 'productID':productID};
	var request = new Request.JSON({
		url: '/user/save-swf.html',
		onComplete: function(data) {
			if(url) location.href = url;			
		}
	}).post({'datasSWF':postDatas});
	$('anim_fen').style.visibility = 'visible';
	popupProduct.close();
	
}

function partageFB() {
	flash.partageFB();
}

function partageFBresS(mur, fauteuil, plante, cadre, sol, background) {
	if(currentSizeID < 1) currentSizeID = '0';
	if(productID < 1) productID = '0';
	if(!sens) sens = 'normal';
	var postDatas = {'mur':mur, 'fauteuil':fauteuil, 'plante':plante, 'cadre':cadre, 'sol':sol, 'background':background, 'colorID':currentColorID, 'imageID':currentSizeID, 'productID':productID};
	var request = new Request({
		url: '/user/make-url-fb.html',
		onComplete: function(data) {
			window.open(data,"nom_popup");
			//alert(data);
		}
	}).post({'datasSWF':postDatas});
}
