//test Navigator
ie6 = navigator.appVersion.indexOf("MSIE 6") != -1 ? 1 : 0; 

//gestion des PNG sous ie6
pngManage = document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&  document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule ? true : false;

function hg_init(){
	//chargement du flash sur la home
	/*if(document.getElementById('productEx'))
	{
		swfobject.embedSWF("swf/anim-eng-4.swf?t=t1", "flashAnim", "961", "266", "9.0.0", "swf/expressInstall.swf");
		swfobject.embedSWF("swf/world-wide-v6.swf?t=t12", "map", "388", "163", "9.0.0", "swf/expressInstall.swf");
	}*/
	//init affichage contenus home
	/*if(!ie6 && document.getElementById('productEx'))
	{
		var productEx = document.getElementById('productEx').getElementsByTagName('li');
		if (productEx.length > 0) 
		{
			for(i= 0 ; i < productEx.length ; i++)
			{
				if(productEx[i].id.indexOf('D') == -1)
				{
					productEx[i].onclick	=	function()
					{
						zone	=	this.id.split('_');					
						if(document.getElementById(zone[0]+'D_'+zone[1]).style.display == 'block')
						{
							if(document.getElementById(zone[0]+'A_'+zone[1]))
							{
								url						=	document.getElementById(zone[0]+'A_'+zone[1]).href;
								urlTarget				=	document.getElementById(zone[0]+'AT_'+zone[1]).innerHTML == 'I' ? '_SELF' : '_BLANK';
								if(urlTarget == '_BLANK')
									window.open(url,'');
								else
									document.location	=	url;
							}
						}
						productExJs(zone[0],zone[1]);
					}
				}
			}
		}
	}*/
	//home Product Tour bt Play
	/*if(document.getElementById('contProductTour'))
	{
		div = document.getElementById('contProductTour').getElementsByTagName('span');
		if (div.length > 0) 
		{
			for(i= 0 ; i < div.length ; i++)
			{
				if(div[i].id.indexOf('pTourVidPlay') != -1)
				{
					changeOpac(50, div[i].id);
					
				}
			}
		}
	}*/

	//print and email
	if(document.getElementById('print'))
		document.getElementById('print').onclick = function(){ callPrintPage(); }
	if(document.getElementById('emailFriend'))
		document.getElementById('emailFriend').onclick = function(){ callEmailPage(); }
		
		
	//liste des News - liens
	if(document.getElementById('listNews'))
	{
		var news = document.getElementById('listNews').getElementsByTagName('div')
		if (news.length > 0) 
		{
			for(i= 0 ; i < news.length ; i++)
			{
				if(news[i].id.substr(0,2) == 'st')
				{
					news[i].onclick	=	function() 
					{ 
						num		=	this.id.replace('st','');
						a		=	document.getElementById('ns'+num).href;
						document.location = a;
					}
				}
			}
		}
	}
	//list clients
	if(document.getElementById('customers'))
	{
		listImg	=	document.getElementById('zoneMobile').innerHTML;
		img		=	document.getElementById('zoneMobile').getElementsByTagName('img');
		if(img.length > 0)
		{
			largeurTot 			= 	0;
			for(i = 0 ; i < img.length ; i++)
			{
				largeur			=	$(img[i]).css("width");
				if(largeur.indexOf('px') != -1)
				{
					largeur			=	parseInt(largeur.replace('px',''));	
					largeurTot		+=	largeur+15;
				}
			}
		}
		if(!isNaN(largeurTot))
		{
			$('#zoneMobile').css("width",largeurTot+70+'px');
			animateCustomers(largeurTot);
		}
		
		document.getElementById('zoneFixe').onclick = function(){
			document.location	=	'customers-and-partners.htm';
		}
		

	}
	//lien email chaché
	if(document.getElementById('contactemail'))
		document.getElementById('contactemail').href	=	'mailto:contact@hotgrinds.com';
	
	//faq
	/*if(document.getElementById('faqList'))
	{
		var faq = document.getElementById('faqList').getElementsByTagName('li')
		if (faq.length > 0) 
		{
			for(i= 0 ; i < faq.length ; i++)
			{
				if(faq[i].id.substr(0,3) == 'ali')
				{
					num		=	faq[i].id.replace('ali','');
					faq[i].onclick = function(){
						num		=	this.id.replace('ali','');
						div		=	document.getElementById('li'+num);
						if(div.style.display == 'block')
						{
							div.style.display 	= 	'none';
							document.getElementById('ali'+num).style.color 	=	'#666';
						}
						else
						{
							div.style.display 	= 	'block';
							document.getElementById('ali'+num).style.color 	=	'#207698';
						}
						
					}
				}
			}
		}
	}*/
	
	if(pngManage && fd_PATH == '../')
		 document.styleSheets[0].addRule('img', 'behavior: url(../js/iepngfix.htc)');
	else if(pngManage && fd_PATH == '')
		document.styleSheets[0].addRule('img', 'behavior: url(js/iepngfixh.htc)');	
		

}

function quickFadeIn()
{
	if(document.getElementById('widget'))
		$('#widget').fadeIn(2000);
}

function productExJs(zone,num)
{
	var col = document.getElementById(zone).getElementsByTagName('li'); 
	if (col.length > 0) 
	{
		for(i= 0 ; i < col.length ; i++)
		{
			numCont		=	col[i].id.split('_');
			//on cache les autres zoom
			if( num != numCont[1] && col[i].id.indexOf('D') != -1 && zone != 'colL')//+ pas caché pour colonne gauche
				col[i].style.display = 'none';
			if( num != numCont[1] && col[i].id.indexOf('D') == -1 && zone != 'colL')//+ pas caché pour colonne gauche
				applyCSS(col[i].id,'');
		}
		
		//on affiche le bloc demandé
		document.getElementById(zone+'D_'+num).style.display = 'block';
		applyCSS(zone+'_'+num,'zoom');
	}
}

function applyCSS(obj,classe)
{
	document.getElementById(obj).setAttribute("class",classe);
	document.getElementById(obj).setAttribute("className",classe);
}

function prepareUrl(addVal)
{
	//valeur récupérer en chaine
	initUrl		=	document.location+'';
	//découpe de la derniè-re partie de la chaine
	cutUrl		=	initUrl.split('/');
	cutUrl		=	cutUrl[cutUrl.length-1];
	//ajout de la valeur __PRINT__ à l'URL
	printUrl	=	initUrl.replace(cutUrl,'');
	return	printUrl+addVal+cutUrl;
}

function callPrintPage()
{
	document.getElementById('zoneJs').innerHTML = '<iframe style="width:1px;height:1px;visibility:hidden;" src="'+prepareUrl('__PRINT__')+'" scrolling="no"></iframe>';
}

function callEmailPage()
{
	fd_ajax('showEmailSend','lien='+document.location);
}

function changeOpac(opacity, id)//de 0 à 100
{
    obj = document.getElementById(id).style;
    obj.opacity = (opacity / 100);
    obj.MozOpacity = (opacity / 100);
    obj.KhtmlOpacity = (opacity / 100);
    obj.filter = "alpha(opacity=" + opacity + ")";
}

function showPlayBt(num,action)
{
	switch(action)
	{
		case 'show' : 	changeOpac(60, 'pTourVidPlay'+num);
						document.getElementById('pTourVidPlay'+num).style.display = 'inline';
						break;
		case 'hide' : 	document.getElementById('pTourVidPlay'+num).style.display = 'none';
						break;							
	}
}



function animateCustomers(largeurTot)
{
	//alert('left: -'+(parseInt(largeurTot)-360)+'px');
	$('#zoneMobile').animate({ left: '-'+(parseInt(largeurTot)-200)+'px' }, 40000 ,'linear',function() {animateCustomers(largeurTot) }  );
	$('#zoneMobile').fadeOut("slow");
	$('#zoneMobile').animate({ left: '0px' }, 0 );
	$('#zoneMobile').fadeIn("slow");
	
	//animateCustomers(largeurTot);
}
