var baseWebRqst = '';


var LaBaseUrl = document.location.href;

var rgx = new RegExp ('http://', 'i');
baseWebRqst = LaBaseUrl.replace(rgx, '');


var Araj = '/';
var rgx = new RegExp ('localhost|(([0-9]{1,3}\.){3})[0-9]{1,3}', 'i');
if (baseWebRqst.match(rgx))
	Araj = '/AoTo/';
	
var rgx = new RegExp ('/.+$', 'i');
var baseWebRqst = 'http://'+baseWebRqst.replace(rgx, '')+Araj;


var BaseDossGraph = baseWebRqst+'_A_WebSite_Demo/_AoTo/Graphisme/';

// var BaseDossGraph = 'http://ns34264.ovh.net/~rlucas/Graphisme/';
// var baseWebRqst = 'http://ns34264.ovh.net/~rlucas/';

function affMenuLook(sioui){
	if (sioui == 'oui')
    {
		function AffML() {
			document.getElementById('MenuDesLooks').style.display = 'block';
//			alert ('apparition');
		}
		setTimeout("document.getElementById('MenuDesLooks').style.display = 'block';",1400);
	//		alert ('apparition oh');
		
   	}
    else
    {
		document.getElementById('MenuDesLooks').style.display = 'none';
    }
	
	
	
}


function ScrollPage() 
{ 
	var VitesseMSec = 40;
	var NbPixelsDep = 10;
	
	var timerCount = 0;
	var TimerID = setInterval (Scrollla,VitesseMSec);


	var BodyTaille = window.document.body.offsetHeight;
	var FentTaille = window.innerHeight - 20;
	
	if (  Math.abs(FentTaille) >= 0)
		var ok = 'ok';
	else
		FentTaille = document.body.clientHeight;
		
//alert (BodyTaille+' ; '+FentTaille);

	function Scrollla ()
	{
		
		
		BodyTaille = window.document.body.offsetHeight;
		FentTaille = window.innerHeight - 5;
		
		if (  Math.abs(FentTaille) >= 0)
			var ok = 'ok';
		else
			FentTaille = document.body.clientHeight;
		
		if (timerCount>=(BodyTaille-FentTaille))
		{
			window.clearInterval(TimerID);
			window.clearTimeout();
		}
		else
		{
			window.scrollBy(0,NbPixelsDep);
			timerCount = timerCount+NbPixelsDep;
		}

	}
	
//alert (timerCount+" >= "+(BodyTaille-FentTaille)+" ("+BodyTaille+" - "+FentTaille+")");
}

function ScrollPageMod_Page ()
{
	setTimeout("new Effect.BlindDown($('CreaWeb_Module_Graf'));",1200);
	setTimeout("ScrollPage();",1000);

	setTimeout("affMenuLook('oui');",1300);
	
	setTimeout("AffFlashViewer();",1400);
	
	
}
		
function ApplyCSS (LookVoulu)
{

	var LinksCSS = window.document.getElementsByTagName('link');

	for (t=0;t<LinksCSS.length;++t)
	{

		var lelinkdcss = LinksCSS[t].href;
		if(lelinkdcss.match(/\.css$/));
		{
			if (lelinkdcss.match(/Menu\.css$/))
			{
				LinksCSS[t].href = BaseDossGraph+LookVoulu+'Menu.css';
			}
			else
			{
				LinksCSS[t].href = BaseDossGraph+LookVoulu+'.css';
			}

		}
								  
	}
}

function ChangeLookLinks(LookPHrf)
{
	var TabloALink = window.document.getElementsByTagName('a');
	for (l=0;l<TabloALink.length;++l)
	{
		var lehrefLien = TabloALink[l].href;
		if (lehrefLien = '' && lehrefLien.match(/\WC=\w*\/w*/)) 
		{
			if (!lehrefLien.match(/ChgLkD/))
			{
				var LexLien = lehrefLien ;
				TabloALink[l].href = lehrefLien+'&ChgLkD='+LookPHrf;
			}
		}
		
		
	}
}
	
function WaittTestFunc (LookVoulu)
{
	if ( FonctionExecute != 'OK')
	{
		window.location.href = baseWebRqst+'?'+ContenuAAff+'&ChgLkD='+LookVoulu+'&OnLJS=ScrollPageMod_Page';
	}
}


function ChgGrafisms (LookVoulu)
{

	FonctionExecute = '';

	LienLookActu = window.location.href ;
	var expLook = /(L=[0-9a-zA-Z]+)/;
	expLook.exec(LienLookActu);
	LookAEchap = RegExp.$1;
	
	if (LookAEchap == '' || LookAEchap == undefined)
		LookAEchap = LookActuel;
		
	var expresRG = /(C=\w+\/\w+)/;
	expresRG.exec(LienLookActu);
	ContenuAAff = RegExp.$1;
	
	
	AJAXLoadGraphisme (LookVoulu);
	setTimeout("WaittTestFunc ('"+LookVoulu+"');", 1000);

}


if (typeof LookActuel == "undefined")
{
	LookActuel = gdft;
	ExLook = '';	
}

function AJAXLoadGraphisme (LookVoulu)
{
	
	if (ContenuAAff != '' && ContenuAAff != 'null')
		lesParams = ContenuAAff+'&ChgLkD='+LookVoulu;
	else
		lesParams = 'ChgLkD='+LookVoulu;
		
	var AncienLieContLook = ContenuAAff+'&'+LookAEchap;
		
	var LogoName = document.getElementById('NomWebS').value;		
	lesParams += '&NomWebS='+LogoName;
	
	
	
	
	
		
	ExLook = LookActuel;
	LookActuel = LookVoulu;
		
	o_options = new Object();
	o_options = {method: 'get',parameters:lesParams,onComplete:afficherReponse};
	
	var laRequete = new Ajax.Request(baseWebRqst,o_options); 
	
	function afficherReponse(requete) 
	{ 
		var htmExPage = document.documentElement.innerHTML;
		var HtmPgeVoulue = requete.responseText;
		HtmPgeVoulue = HtmPgeVoulue.replace(/\n/g," ");
		HtmPgeVoulue = HtmPgeVoulue.replace(/\r/g," ");


		var regLinkCSS = /<link[^>]*>/gi;
		var lesLinkscssVoulues = HtmPgeVoulue.match(regLinkCSS);
		var lesLinkscss = htmExPage.match(regLinkCSS);

		var lebodyExPg = htmExPage.replace(/\r/g,""); 
		lebodyExPg = lebodyExPg.replace(/\n/g, ""); 
		var lebodyExbody = lebodyExPg.replace( /.*<body[^>]*>/i , " ");
		lebodyExbody = lebodyExbody.replace( /<\/body.*/i , " ");
		
			  
		var LinkscssExPage = '';
		
		for(yi=0;yi<lesLinkscss.length;++yi)
		{
			var LexCSS = lesLinkscss[yi];
			
			LexCSS = LexCSS.replace(/href="\//,"href=\"");
			LexCSS = LexCSS.replace(/href="/,"href=\""+baseWebRqst);
			
			LinkscssExPage = LinkscssExPage + LexCSS;
		}
		
		
//		var LeDivQuiSeFerme = '<div id="ChargeLook" style="position: absolute; z-index:100; top:0px; left:0px; width:100%; height:100%; display:block; background:#FFFFFF;">'+LinkscssExPage+lebodyExbody+'</div>';
		
		var LeDivQuiSeFerme = '<div id="ChargeLook" style="position: absolute; z-index:100; top:0px; left:0px; width:100%; height:100%; display:block; background:#CCCCCC; color:#CCCCCC; margin:0px; padding:0px;"></div>';
				
		
		var LeDocArecompo = HtmPgeVoulue.replace(/<\/body/i , LeDivQuiSeFerme+"</body");
//		var LeDocArecompo = HtmPgeVoulue.replace(/<body([^>]+)>/i , "<body $1 >"+LeDivQuiSeFerme);
		
		document.body.innerHTML = LeDocArecompo ;
		FonctionExecute =  'OK';	
		



		setTimeout("GoAnime ('"+LookVoulu+"');",1000);

	} 

}


function GoAnime (LookVoulu)
{
		ApplyCSS (LookAEchap);

		new Effect.BlindUp($('ChargeLook'));

		setTimeout("ApplyCSS ('"+LookVoulu+"');",300);
		setTimeout("Element.remove('ChargeLook');",2000);
		ScrollPageMod_Page ();

	
	
}


function AffFlashViewer ()
{
//	var lesLooks = document.getElementById('tlook').value;
//	alert (TouslLooks);
	
	var foaa = swfobject.embedSWF(baseScripts+"Image/viewer.swf?Looks="+TouslLooks+"&ch="+baseScripts, "flashcontent", "350", "130", "9.0.0", false, {loaderColor:"0x666666"}, {wmode: "transparent"});
	
	
}



