// copyright (c) OALIA 2006
var doc							= window.document;
var agent						= navigator.userAgent.toLowerCase();
var ie							= (agent.indexOf("msie") != -1);
var caching					= true;														// do caching pictures
var cacheVisibity		= "hidden";											// hidden or visible
var	loading					= [];
var cookie_caching	= "oalia_caching_images";					// token
var cacheSrc				= "cache.html";										// cache.htm for IFRAME
evt									= ie ? "onreadystatechange" : "onload";

function openWindow(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';

  cookie_str = document.cookie;
  cookie_str.toString();

  pos_start  = cookie_str.indexOf(name);
  pos_end    = cookie_str.indexOf('=', pos_start);

  cookie_name = cookie_str.substring(pos_start, pos_end);

  pos_start  = cookie_str.indexOf(name);
  pos_start  = cookie_str.indexOf('=', pos_start);
  pos_end    = cookie_str.indexOf(';', pos_start);
  
  if (pos_end <= 0) pos_end = cookie_str.length;
  cookie_val = cookie_str.substring(pos_start + 1, pos_end);
  if (cookie_name == name && cookie_val  == "done")
    return;

  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}


function doCaching(){
		if(caching && !lireCookie(cookie_caching)){
			var cache			= doc.createElement( "IFRAME" );
			cache.style.visibility		= cacheVisibity;
			cache.id			= "cache";
			cache.allowTransparency		= true;
			cache.frameBorder		= 0;
			cache.marginHeight		= 0;
			cache.marginWidth		= 0;
			cache.src			= cacheSrc;
			cache[evt]	= function(){ this.removeNode(true) };
			doc.body.appendChild(cache);
	}
}

function accepteCookies() {
	cookies_ok=false;
	if (navigator.cookieEnabled) {
		cookies_ok=true;
	} else {
		ecrireCookie ("test_cookie", "ok");
		if (lireCookie("test_cookie")=="ok") { cookies_ok=true; }
		effacerCookie("test_cookie");
	}
	return (cookies_ok);
}

function lireCookie(nom) {
	if (!nom || nom=="") return ("");
	var nomEq=nom+"=";
	var tab=doc.cookie.split(";");
	for(var i=0; i<tab.length; i++) {
		var cook=tab[i];
		while (cook.charAt(0)==' ')
			cook=cook.substring(1, cook.length);
		if (cook.indexOf(nomEq)==0)
			return unescape(cook.substring(nomEq.length, cook.length));
	}
	return ("");
}

function ecrireCookie(nom, valeur, jours) {
	if (!nom || nom=="") return false;
	if (!valeur) { valeur=""; }
	if (!jours) { jours=0; }
	var expire;
	if (parseInt(jours)!=0) {
		var date=new Date();
		date.setTime(date.getTime()+(parseInt(jours)*24*60*60*1000));
		expire="; expires="+date.toGMTString();
	} else {
		expire="";
	}
	doc.cookie=nom+"="+escape(valeur)+expire+"; path=/";
	return true;
}

function effacerCookie(nom) {
	return (ecrireCookie(nom, "", -1));
}


//loading.push(doCaching);


	function animPopUp(){
		var obj	= document.getElementById("popup");
		var film = document.getElementById("snapshot");

		film.className = "s1";

		var m1	= new Tween(obj.style,'top',Tween.backEaseInOut,-1300,65,2,'px');
		var o1	= new OpacityTween(film,Tween.regularEaseInOut, 100, 0, 2);

		o1.onMotionFinished = function(event){

			function fn(){
				if(!event.target._pos)
					film.className = (film.className.indexOf('s2') != -1)? 's1' : 's2';
				o1.yoyo();
				
			}
			if(film.className.indexOf('s2') != -1)
				window.setTimeout(fn,1000);
			else
				fn();
		
		};
		m1.onMotionFinished = function(){
			o1.start();
		};
	
		m1.start();
		
	}
