var curPage = "home";
var curLang = readCookie('lang');


function readCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function setcookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" + escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );

	url = "http://www.euricamedialab.org/" + curUser + "_" + value + ".php";
	//url = "http://www.paxpictura.com/eurica/" + curUser + "_" + value + ".php";
	curLang = value;
	
	// nav to new page
	window.location.href=url;
}



// for rollover with code not gifs.  still have to figure out how to downstate the selected page.
function roll(obj, highlightcolor, textcolor) {
   	obj.style.backgroundColor = highlightcolor;
    //obj.style.color = textcolor;
}


// pre-cache all "roll" button images
if (document.images) {       // if image object is available     
	img1on = new Image();        // MouseOver Images
	img1on.src = "images/nav/home_roll_" + curLang + ".gif"; 
	img2on = new Image();
	img2on.src = "images/nav/aboutus_roll_" + curLang + ".gif";  
	img3on = new Image();
	img3on.src = "images/nav/ourprogram_roll_" + curLang + ".gif";
	img4on = new Image();
	img4on.src = "images/nav/ourpeople_roll_" + curLang + ".gif";
	img5on = new Image();
	img5on.src = "images/nav/news_roll_" + curLang + ".gif"; 
	img6on = new Image();
	img6on.src = "images/nav/contactus_roll_" + curLang + ".gif";  
	img7on = new Image();
	img7on.src = "images/nav/donate_roll_" + curLang + ".gif";

	img1off = new Image();        // MouseOut Images
	img1off.src = "images/nav/home_up_" + curLang + ".gif"; 
	img2off = new Image();          
	img2off.src = "images/nav/aboutus_up_" + curLang + ".gif";
	img3off = new Image();
	img3off.src = "images/nav/ourprogram_up_" + curLang + ".gif";
	img4off = new Image();
	img4off.src = "images/nav/ourpeople_up_" + curLang + ".gif";
	img5off = new Image();
	img5off.src = "images/nav/news_up_" + curLang + ".gif"; 
	img6off = new Image();          
	img6off.src = "images/nav/contactus_up_" + curLang + ".gif";
	img7off = new Image();
	img7off.src = "images/nav/donate_up_" + curLang + ".gif";
}





function imgOn(imgName) {
	if (document.images) {
    	document[imgName].src = eval(imgName + "on.src");
    }
    //alert(img1on.src);
}



            
function imgOff(imgName) {
	if (document.images) {
		if (!cancelSwap(imgName)) {  // test to see if the btn is for that page, then don't swap but keep roll state alive
    		document[imgName].src = eval(imgName + "off.src");
    	}
    }
}




function cancelSwap(imgName) {  // test to see if the btn is for that page, then don't swap but keep roll state alive
	flag = 0

	if ( (document.title.match("Eurica Media Lab: Home") || document.title.match("Eurica Media Lab: Accueil")) && (imgName=="img1")) {
		flag = 1
	}

	if ( (document.title.match("Eurica Media Lab: About Us") || document.title.match("Eurica Media Lab: Qui sommes-nous?")) && (imgName=="img2")) {
		flag = 1
	}

	if ( (document.title.match("Eurica Media Lab: Our Program") || document.title.match("Eurica Media Lab: Notre programme")) && (imgName=="img3")) {
		flag = 1
	}

	if ( (document.title.match("Eurica Media Lab: Our People") || document.title.match("Eurica Media Lab: Notre ˇquipe")) && (imgName=="img4")) {
		flag = 1
	}

	if ( (document.title.match("Eurica Media Lab: Latest News") || document.title.match("Eurica Media Lab: Latest News")) && (imgName=="img5")) {
		flag = 1
	}

	if ( (document.title.match("Eurica Media Lab: Contact Us") || document.title.match("Eurica Media Lab: Contactez nous")) && (imgName=="img6")) {
		flag = 1
	}

	if ( (document.title.match("Eurica Media Lab: Donate") || document.title.match("Eurica Media Lab: Nos bienfaiteurs")) && (imgName=="img7")) {
		flag = 1
	}

	return flag
}






function cleanUp(btn, pg) {
	curUser = pg;

 	for (i=1; i<=4; i++) {  // clear the rollstate buttons if user hits back button
 		filePrefix = "img" + i
		document[filePrefix].src = eval(filePrefix + "off.src");
	}

	imgOn(btn) // this is to downstate the home button in case a fast roll doesn't call the function d
}


