// Debug

var traceinjsTrace = false;
var traceInConsoles = true;

function trace(msg)
{
	if(traceinjsTrace && typeof(jsTrace)!='undefined'){
		jsTrace.send(msg);
	}
	if(traceInConsoles){
		if( typeof( console ) != 'undefined' && typeof( console.log ) != 'undefined' ){
			console.log(msg);
		}
		else if( typeof( window.console ) != 'undefined' && typeof( window.console.log ) != 'undefined' ){
			window.console.log( msg );
		}
	}
}

function inspecter(p_obj)
{
	for(prop in p_obj)
	{
		trace(prop + ": " + p_obj[prop]);
	}
}

// Read a page's GET URL variables and return them as an hash.

function getUrlVars()
{
	//traceFunctionName(arguments);

	var vars = new Hash();

	if(window.location.href.indexOf('?')>0)
	{
		var param;
		var params = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

		for(var i = 0; i < params.length; i++)
		{
			param = params[i].split('=');
			vars.set(param[0], param[1]);
		}
	}

	return vars;
}

// Cookies

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie (name,value,expireDays,path,domain,secure) {
	var expireDate=new Date();
	expireDate.setDate(expireDate.getDate() + expireDays);

	document.cookie = name + "=" + escape (value) +
	((expireDate) ? "; expires=" + expireDate.toUTCString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

// affiche ou masque le logo CPA verre selon la section courante pour le flash

function affiche_logo_cpa_verre(afficher)
{
	//trace('affiche_logo_cpa_verre(' + afficher + ')');

	if($('cpa_verre')!=null)
	{		
		if(afficher)
		{
			//trace('AFFICHER')
			
			// sur le premier load de la page html verre structurel, le logo ne fait pas de fade-in 
			
			if(window.logo_cpa_load_no_fade!=undefined && window.logo_cpa_load_no_fade==true)
			{
				$('cpa_verre').show();
				$('cpa_verre').setOpacity(1);
				logo_cpa_load_no_fade = false;
			}
			else
			{			
				$('cpa_verre').setOpacity(0);
				$('cpa_verre').show();
				$('cpa_verre').appear({ duration: 1 });
			}
		}
		
		if(!afficher && $('cpa_verre').visible())
		{
			//trace('MASQUER')
			
			$('cpa_verre').setOpacity(1);
			$('cpa_verre').fade({ duration: 1, afterFinish: function()
			{
				$('cpa_verre').hide();
			}});
		}
	}
}

// affiche le logo CPA verre selon la section courante pour le html

function affiche_logo_cpa_verre_onload()
{
	trace('affiche_logo_cpa_verre_onload()');
	
	document.observe('dom:loaded', function()
	{
		if(!loadFlash && $('cpa_verre')!=null)
		{
			$('cpa_verre').setStyle({left: '226px'});
			$('cpa_verre').show();
		}
	});
}

// Vérification du type de navigateur

var versionRequise = [8, 0, 0];

function verificationNavigateur()
{
	//trace('  ' + navigator.userAgent);

	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
	var isiPod = navigator.userAgent.match(/iPod/i) != null;

	var loadFlash = (isiPad || isiPhone || isiPod) ? false : DetectFlashVer(versionRequise[0], versionRequise[1], versionRequise[2]);

	if(loadFlash)
	{
		var urlVars = getUrlVars();

		if(urlVars.get('html')=='true')
		{
			loadFlash = false;
		}
	}

	document.observe('dom:loaded', function()
	{
		if(loadFlash)
		{
			if($('text_accueil') != null)
			{
				$('text_accueil').hide();
			}
			if($('sidebar-s') != null)
			{
				$('sidebar-s').hide();
			}
			if($('text-section') != null)
			{
				$('text-section').hide();
			}
			if($('text-portfolio') != null)
			{
				$('text-portfolio').hide();
			}
			if($('flashRequis') != null)
			{
				$('flashRequis').hide();
			}
			if($('content3') != null)
			{
				$('content3').setStyle({backgroundImage: 'url(/images/content_back_flash.jpg)'});
			}
		}
		else if(isiPad || isiPhone || isiPod && ($('flashRequis') != null))
		{
			$('flashRequis').hide();
		}
		
		
	});

	return loadFlash;
}

