//alert("cartouche");

//variables graphiques à personnaliser par cleint transmises à flash
var colorCartPlie="#AC6232";
var alphaColorCartPlie="0";
var alphaCartPlie="95";
var alphaOmbreCartPlie="50";

var colorCartDeplie="#AC6232";
var alphaColorCartDeplie="0";
var alphaCartDeplie="95";
var alphaOmbreCartDeplie="50";


var positionGauche="origineCentre";  
//origineCentre : sites centrés, la calcul se fait par rapport au centre de la page, ex http://www.tourisme-midi-pyrenees.com/fr/index.php
//bordGauche : site calée à guache, le calcul se fait par rapport au bord gauche, http://www.tourisme-aveyron.com/fr/index.php

//peut etre contredit par le site partenaire en amont sur son style de div style="", c'est le style définit par le site qui gagne par rapport à cette valeur
var topY=300; /*remettre 260 quand on enlevera la phrase "refonte" en haut de page*/
var leftX=290; //distance par rapport au bord gauche ou par rapport au centre suivant la valeur précédente positionGauche

//indique si le cartouche est envoyé auto en fin de chargement (true)
//ou par le développeur (false)
//false : cas de l'intégration experte (ex : cahors avnat refonte)
var gsAfficheSurOnload=false;

//indique qi on a le deplie ou si on envoi directement vers le site sans déplier
var gsDeplieBool="true";

//tags xiti
var tagXiti="from";
var swfIdGs = "";

//parametres generaux
var listeLangues=["fr","en", "es", "it", "nl", "de"];
var baseNomDiv="gsCartouche";
var defaultLang="fr";
var divGsContainer;

//indique si le posionnement est auto, ou à l'intérieur d'un div existant 
//créé par le développeur du site qui accueille le cartouche
var gsPositionnementAuto=true;



function afficheGs()
{
	//alert("maintenance en cours");
	swfIdGs=baseNomDiv+defaultLang;
	if(window.top.document.getElementById(swfIdGs)!=null)
	{
		divGsContainer=window.top.document.getElementById(swfIdGs);
		gsPositionnementAuto=false;
	}
	else
	{
		divGsContainer=creatediv(swfIdGs);	
	}

	//ecriture et positionnement du cartouche Gs
	var fo = new FlashObject("http://www.grandsites.midipyrenees.fr/cartouches/cartouche-gs-" + defaultLang + "-v02.swf", swfIdGs, "190", "170", 9, "#FFFFFF");
	fo.addParam("wmode","transparent");
	fo.addParam("allowScriptAccess", "always");
	fo.addVariable("colorCartPlie",colorCartPlie);
	fo.addVariable("alphaColorCartPlie",alphaColorCartPlie);
	fo.addVariable("alphaCartPlie",alphaCartPlie);
	fo.addVariable("alphaOmbreCartPlie",alphaOmbreCartPlie);
	fo.addVariable("colorCartDeplie",colorCartDeplie);
	fo.addVariable("alphaColorCartDeplie",alphaColorCartDeplie);
	fo.addVariable("alphaCartDeplie",alphaCartDeplie);
	fo.addVariable("alphaOmbreCartDeplie",alphaOmbreCartDeplie);
	fo.addVariable("gsDeplieBool",gsDeplieBool);
	var flashok=fo.write(swfIdGs);
	if(flashok && gsPositionnementAuto)
	{
		positionneCartoucheGsFirstTime();
		divGsContainer.style.display="block";
	}
}





var tempWinId = 0;

function openWindowGs(pageUrl) {
	//alert("openWindowGs");
	tempWinId=tempWinId+1;
	var winName = "popgs"+tempWinId; //Math.round(9999*Math.random()) + new Date().getTime();
	var winNew = window.open(pageUrl,winName,"toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=700,left=200,top=100");

	if(!winNew) {
		//alert("ouvre");
		window.location.href=pageUrl;
		//alert(swfIdGs + "--" + getSwfGs(swfIdGs) + "--" + pageUrl);
		//getSwfGs(swfIdGs).openWindowFromGsSwf(pageUrl);
	}
	else {
		winNew.focus();
	}
}

function getSwfGs(id) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[id];
	} 
	else {
		return document[id];
	}
}    


function positionneCartoucheGsFirstTime()
{
	//on affiche si et seulement si falsh est disponible en bonne version
	//alert(divGsContainer.style.top);
	if(!divGsContainer.style.top)
	{
		divGsContainer.style.top=topY+"px";
	}
	else
	{
		positionGauche="bordGauche";
		topY=divGsContainer.style.top.substring(0,divGsContainer.style.left.length-2);
	}
	
	if(!divGsContainer.style.left)
	{
		if(positionGauche=="origineCentre")
		{
			var largeurTemp=Math.round(f_clientWidth()/2);
			//alert(largeurTemp);
			var posX=largeurTemp+leftX;
			divGsContainer.style.left=posX+"px";
			window.onresize=positionneCartoucheGs;
		}
		else
		{
			 
			divGsContainer.style.left=leftX+"px";
		}
	}
	else
	{
		positionGauche="bordGauche"; 
		leftX=divGsContainer.style.left.substring(0,divGsContainer.style.left.length-2);
	}
	
}

function positionneCartoucheGs()
{
	//on affiche si et seulement si falsh est disponible en bonne version
	divGsContainer.style.top=topY+"px";

	if(positionGauche=="origineCentre")
	{
		var largeurTemp=Math.round(f_clientWidth()/2);
		//alert(largeurTemp);
		var posX=largeurTemp+leftX;
		divGsContainer.style.left=posX+"px";
	}
	else
	{
		divGsContainer.style.left=leftX+"px";
	}

	
}



// fonction laetis, globales

function checkLangue()
{
	//cheque le nom du cartouche pour connaître la langue
	for(i=0; i<listeLangues.length; i++)
	{
		defaultLang=listeLangues[i];
		if(window.document.getElementById(baseNomDiv+defaultLang))
		{
			
			return window.document.getElementById(baseNomDiv+defaultLang);
		}
	}
	
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
};
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
};


function creatediv(id) {

   DIVtoRemove = window.top.document.getElementById(id);
   //alert(DIVtoRemove);
	if(DIVtoRemove!=null)
	{
		window.top.document.body.removeChild(DIVtoRemove);
	}
	var newdiv = window.top.document.createElement('div');
	newdiv.setAttribute('id', id);
	newdiv.style.width = '190px';
	newdiv.style.height = '170px';
	newdiv.style.position = "absolute";
  window.top.document.body.appendChild(newdiv);
  return newdiv;

} 

if(gsAfficheSurOnload)
{
	window.onload=afficheGs;
	//alert('GS');
}


//affiche Gs
//afficheGs();