//var mm=open("","mm");
function debuger(obj){for(var i in obj){mm.document.write(i+"="+obj[i]+"<br>");}mm.document.write("<hr>");}
function debug(value){ mm.document.write(value+"<br>"); mm.document.write("<hr>");}
var addthis_config = {data_track_clickback:true,ui_language:"fr",data_ga_property: 'UA-6217900-5',data_ga_social : true};
function rgb2hex(rgb) {
	var reg=new RegExp("^#.{6}$","g");
	if(!reg.test(rgb)){
   		var rgbTmp = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    	return "#" + hex(rgbTmp[1]) + hex(rgbTmp[2]) + hex(rgbTmp[3]);
	}
	return rgb;
}
function hex(x) {return ("0" + parseInt(x).toString(16)).slice(-2);}
function pixelToPoint(pixel){ return pixel*1/1.3;}
function pointToPixel(point){return  point*1.3/100;}
function socialTracking(network, action, url){if(typeof(_gaq)!='undefined'){var aConf = ['_trackSocial', network, action, url];_gaq.push(aConf);/*alert(aConf);*/}}
$(document).ready(function() {
setMenu();
setLoupeProduit();
			/*iniSousMenu();   
			initTitreProduit();
			initSousTitreProduit();*/
});
window.comfMenu = {timer:50,timeout:null,menu:null,selected:null}
function setMenu(){
	$("#menu ul > li").each(function(){	
		if(!$(this).parent().hasClass('menu-fils')){
			 
			$(this).mouseover(function(event){	
					fermeMenu();
					window.comfMenu.selected=$(this).find('a').hasClass('selected');
					if(this.id=='mProduit'){
						$('#menu-gauche').css({opacity:0.2})
					}
					$(this).find('a').first().addClass('selected')		  
					$fils = $(this).find('ul.menu-fils');
					var pos =$(this).position(); 
					/*if($fils.length>0){
						//debuger($(this)[0]);
						//$(this).css({'display':'relative'});
					}*/
					$fils.css({display:'block',position:'absolute',top:'25px',left:pos.left+'px'});
					$($fils).find('li a').mouseover(function(){	
									clearTimeout(window.comfMenu.timeout);			   
								})
								.mouseout(function(){	
									clearTimeout(window.comfMenu.timeout);		
									window.comfMenu.timeout = setTimeout('fermeMenu()',window.comfMenu.timer);
							 	})
			
				 clearTimeout(window.comfMenu.timeout);
				 window.comfMenu.menu = $(this);
				 
			}) .mouseout(function(){	
			clearTimeout(window.comfMenu.timeout);		
				window.comfMenu.timeout = setTimeout('fermeMenu()',window.comfMenu.timer);
			 });
		}
	});

}
function fermeMenu(){

	$(window.comfMenu.menu).find('ul.menu-fils').css({display:'none'});
	if(window.comfMenu.selected!=true){
	 	$(window.comfMenu.menu).find('a').first().removeClass('selected');	
	}
	window.comfMenu.menu = null;
	window.comfMenu.selected = null;
	clearTimeout(window.comfMenu.timeout);
	$('#menu-gauche').css({opacity:1})
	
}


function initFont(){
	$('.Stymie').each(function(){
	/*var so = new SWFObject("/img/font/exemple_par_classt.swf", "fltext", "500", "75", "8");
	  swfobject.embedSWF("/img/font/exemple_par_classt.swf", "fltext", "300", "120", "8.0.0");

			so.addParam("wmode", "transparent");
			so.addVariable('texte', escape(this.innerHTML));
			so.addVariable('couleur', '0x09002F');
			so.addVariable('taille', '35');
			so.write(this);
			*/
			var obj = $(this);
			
			var bgColor = rgb2hex(obj.css('backgroundColor'));
		
			var color = (rgb2hex(obj.css('color'))).replace("#",'0x')
			
			var width=obj.outerWidth();
			var height=obj.outerHeight();
			var paddingLeft=pixelToPoint((obj.css('paddingLeft')).replace('px',''));
			var paddingRight=pixelToPoint((obj.css('paddingRight')).replace('px',''));
			
var width=obj.outerWidth()+pointToPixel(paddingRight)+pointToPixel(paddingLeft);
			var flashvars = {'bordure':'true','id':this.id,'nowrap':'false','leftmargin':paddingLeft,'rightmargin':paddingRight,'taille':'13','couleur':color,'multiline':'false','texte':escape(this.parentNode.innerHTML)};
 var params = {"bgcolor":bgColor,wmode:"transparent"};
 var attributes = {};

 swfobject.embedSWF("img/font/exemple_par_classt.swf", this.id, width, height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	});		
}
function initTitreProduit(){
	$('#titre-produit').each(function(){
				var objMe = $(this);
			var objSpan= objMe.children("span");
			var texteLien = escape(objSpan[0].innerHTML);
			objSpan.attr('id',"sp"+this.id)		
			var _aConf = {
				swf:'exemple_par_classt.swf',
				id:"sp"+this.id,
				paddingLeft:pixelToPoint((objMe.css('paddingLeft')).replace('px','')),
				paddingRight:pixelToPoint((objMe.css('paddingRight')).replace('px','')),
				bordure:false,
				nowrap:false,
				bgColor: "#ffffff",
				height:objMe.outerHeight(),
				width:objMe.outerWidth(),
				color :(rgb2hex(objMe.css('color'))).replace("#",'0x'),
				multiline:false,
				oldwidth:objMe.outerWidth(),
				oldheight:objMe.outerHeight(),
				texte:texteLien,
				taille:(objMe.css('fontSize')).replace('px','')
				}
			
			setSwf(_aConf);				
	});
}
function initSousTitreProduit(){
	$('#sous-titre-produit').each(function(){
			var objMe = $(this);
			var objSpan= objMe.children("span");
			var reg=new RegExp("<br>","gi");
			var texteLien =((objSpan[0].innerHTML).replace(reg,"\n"));// escape
			objSpan.attr('id',"sp"+this.id)		
			var _aConf = {
				swf:'exemple_par_classt.swf',
				id:"sp"+this.id,
				paddingLeft:pixelToPoint((objMe.css('paddingLeft')).replace('px','')),
				paddingRight:pixelToPoint((objMe.css('paddingRight')).replace('px','')),
				bordure:'true',
				nowrap:'false',
				bgColor: "#ffffff",
				height:objMe.outerHeight(),
				width:objMe.outerWidth(),
				color :(rgb2hex(objMe.css('color'))).replace("#",'0x'),
				multiline:'true',
				oldwidth:objMe.outerWidth(),
				oldheight:objMe.outerHeight(),
				texte:texteLien,
				taille:(objMe.css('fontSize')).replace('px','')
				}
			setSwf(_aConf);				
	});
}
function iniSousMenu(){
	$('#sous-menu ul li').each(function(){
			var objMe = $(this);
			var objLien = objMe.children("a");	
			var texteLien = escape(this.innerHTML);
	 		objLien.attr("id","a"+this.id);	
			var _aConf = {
				swf:'exemple_par_classt.swf',
				id:"a"+this.id,
				paddingLeft:pixelToPoint((objLien.css('paddingLeft')).replace('px','')),
				paddingRight:pixelToPoint((objLien.css('paddingRight')).replace('px','')),
				bordure:false,
				nowrap:false,
				bgColor: rgb2hex(objLien.css('backgroundColor')),
				height:objLien.outerHeight(),
				width:objLien.outerWidth(),
				color :(rgb2hex(objLien.css('color'))).replace("#",'0x'),
				multiline:false,
				oldwidth:objMe.outerWidth(),
				oldheight:objMe.outerHeight(),
				texte:texteLien,
				taille:(objLien.css('fontSize')).replace('px','')
				}
				
			setSwf(_aConf);
			
			
	});

}
function setTaille(id,oldwidth,oldheight,textwidth, textheight,width,height) {

	if(id=='spsous-titre-produit'){	//alert(id)
		 //$("#"+id).css({'width':width})
		 // $("#"+id).css({'heigt':height})
	}else{
		if(oldwidth<width){
		$("#li"+id.replace("a",'')).css({'width':width})
		$("#"+id).css({'width':width})
		}
	}
    return true;
} 

function setSwf(_aConf){
	var flashvars = {'oldWidth':_aConf.oldwidth,'oldHeight':_aConf.oldheight,'bordure':_aConf.bordure,'id':_aConf.id,'nowrap':_aConf.nowrap,'leftmargin':_aConf.paddingLeft,'rightmargin':_aConf.paddingRight,'taille':_aConf.taille,'couleur':_aConf.color,'multiline':_aConf.multiline,'texte':_aConf.texte};
	var params = {"bgcolor":_aConf.bgColor,"wmode":"transparent"};
	var attributes = {};
	swfobject.embedSWF("img/font/"+_aConf.swf, _aConf.id, _aConf.width, _aConf.height, "8.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function setLoupeProduit(){
	var parents= $('#imgproduit0').parent();
	if(parents.length>0){if(parents[0].tagName.toUpperCase()=='A'){
		$('#imgproduit0').before('<img id="loupe" src="/img/template/loupe.png"/>');
	}}
}
function initForm(objForm,aIdChamp){
		for(var i =0;i<aIdChamp.length;i++){
			var oLabel = $('#'+aIdChamp[i]).parent().find('.libelle');
			var value = oLabel.html()
			oLabel.css({display:'none'});
			
			var oInput = document.getElementById(aIdChamp[i]);
			if(oInput.value ==''){
				oInput.defaultValue = value;
				if(oInput.value==''){
					oInput.value = value;
				}
			}
			$(oInput).focus(function(ele){
				if(ele.target.value==$(ele.target).parent().find('.libelle').html()){
					ele.target.value='';
				} 
			}).blur(function(ele){
				if(jQuery.trim(ele.target.value)==''){
					ele.target.value= $(ele.target).parent().find('.libelle').html();
				} 
			});
		}
		 var oLabel = $('#produit').parent().find('.libelle');
		oLabel.css({display:'none'}); 
		
}
