/* ************************************************
Javascript Functions for www.stephanesednaoui.com

Coded by Bill Hanff, input nine interactive
www.inputnine.com

************************************************ */
var req;
var numberOfProjects = 4;
var br = getBrowser();
var os = getOS();
var copyWidth;
var copyHeight;
		
function getDims() {
	var winW = 0;
	var winH = 0;
	
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	
	return(Array(winW, winH));
}


function hasFlashVersion(reqVersion) {
	if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object") {
			var desc = navigator.plugins["Shockwave Flash"].description;
			if (desc) {
				var descArr = desc.split(" ");
				var majorArr = descArr[2].split(".");
				var major = majorArr[0];
				if (descArr[3] != "") {
					var minorArr = descArr[3].split("r");
				}
				else {
					var minorArr = descArr[4].split("r");
				}
				var minor = minorArr[1] > 0 ? minorArr[1] : 0;
				var flashVersion = parseFloat(major + "." + minor);
			}
		}
		else if (window.ActiveXObject) {
			try {
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				var desc = flash.GetVariable("$version");
				if (desc) {
					var descArr = desc.split(" ");
					var versionArr = descArr[1].split(",");        
					var major = versionArr[0];
					var minor = versionArr[2];
					var flashVersion = parseFloat(major + "." + minor);
				}
			}
			catch(e) {}
		}
		if (typeof flashVersion != "undefined"){
			return (flashVersion >= reqVersion ? true : false); 
		}
		return false;
	}

//var acquanatasa = "assets_img/acqua_photo.jpg";
//var anthroposexomorphic = "assets_img/anthro1.jpg,assets_img/anthro2.jpg";
//var armyofme = "assets_img/armyofme.jpg";
var project0_var = "assets_img/armyofme.jpg";
var project1_var = "assets_img/anthro1.jpg,assets_img/anthro2.jpg";
var project2_var = "assets_img/acqua_photo1.jpg,assets_img/acqua_photo2.jpg,assets_img/acqua_photo3.jpg";


var curPage = "";

function showhide(nodeName){
	
	var node = document.getElementById(nodeName);
	if(node.className == "hide"){
		node.className = "show";
	} else {
		node.className = "hide";
		if(curPage!=""){ resetSite(); }
	}
}

function languageSwitch(lang){
	document.getElementsByTagName("body")[0].id = lang;
	
	document.getElementById('englishLink').className = "active";
	document.getElementById('frenchLink').className = "active";
	document.getElementById('mandarinLink').className = "active";
	//document.getElementById('cantoneseLink').className = "active";
	
	document.getElementById(lang+'Link').className = "inactive";
	
	setLangCookie(lang);
}

function photoSet(state, assets){
	var node = document.getElementById('textcopy');
	//alert(node +" | "+ node.style.width);
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	HTMLtext = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+copyWidth+'" height="'+copyHeight+'" id="img_holder" align="middle">';
	HTMLtext += '	<param name="allowScriptAccess" value="sameDomain" />';
	HTMLtext += '	<param name="movie" value="assets_swf/img_holder.swf" />';
	HTMLtext += '	<param name="quality" value="high" />';
	HTMLtext += '	<param name="wmode" value="transparent" />';
	HTMLtext += '	<param name="bgcolor" value="#ffffff" />';
	HTMLtext += '	<param name="FlashVars" value="list='+assets+'" />';
	HTMLtext += '	<embed src="assets_swf/img_holder.swf" flashvars="list='+assets+'" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+copyWidth+'" height="'+copyHeight+'" name="img_holder" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	HTMLtext += '</object>';
	
	var flshDiv = document.createElement( 'div' );
	flshDiv.setAttribute("id","flshDiv");
	node.appendChild(flshDiv);
	document.getElementById('flshDiv').innerHTML = "&nbsp;";
	document.getElementById('flshDiv').innerHTML = HTMLtext;
}



function photofilmSwitch(state, assets, flashVars){
	var node = document.getElementById('textcopy');
	//alert(node +" | "+ node.style.width );
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	if(state=="photo"){
		document.getElementById('flmLink').className = "showDisplay";
		document.getElementById('phtLink').className = "clearDisplay";
		document.getElementById('stateTitle').innerHTML = "photographies"; 
		
		HTMLtext = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+copyWidth+'" height="'+copyHeight+'" id="img_holder" align="middle">';
		HTMLtext += '	<param name="allowScriptAccess" value="sameDomain" />';
		HTMLtext += '	<param name="movie" value="assets_swf/img_holder.swf" />';
		HTMLtext += '	<param name="quality" value="high" />';
		HTMLtext += '	<param name="wmode" value="transparent" />';
		HTMLtext += '	<param name="bgcolor" value="#ffffff" />';
		HTMLtext += '	<param name="FlashVars" value="list='+assets+'" />';
		HTMLtext += '	<embed src="assets_swf/img_holder.swf" flashvars="list='+assets+'" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+copyWidth+'" height="'+copyHeight+'" name="img_holder" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		HTMLtext += '</object>';
		
		var flshDiv = document.createElement( 'div' );
		flshDiv.setAttribute("id","flshDiv");
		node.appendChild(flshDiv);
		document.getElementById('flshDiv').innerHTML = "&nbsp;";
		document.getElementById('flshDiv').innerHTML = HTMLtext;
		//document.getElementById('flshDiv').style.width = copyWidth;
		//document.getElementById('flshDiv').style.height = copyHeight;
	} else {
		document.getElementById('flmLink').className = "clearDisplay";
		document.getElementById('phtLink').className = "showDisplay";
		document.getElementById('stateTitle').innerHTML = "film"; 
		//alert(copyWidth + ' || ' + copyHeight);
		HTMLtext = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+copyWidth+'" height="'+copyHeight+'" id="scrubber" align="middle">';
		HTMLtext += '	<param name="allowScriptAccess" value="sameDomain" />';
		HTMLtext += '	<param name="movie" value="assets_swf/scrubber.swf" />';
		HTMLtext += '	<param name="quality" value="high" />';
		HTMLtext += '	<param name="wmode" value="transparent" />';
		HTMLtext += '	<param name="bgcolor" value="#ffffff" />';
		HTMLtext += '	<param name="FlashVars" value="vidName=../'+assets+'&'+flashVars+'" />';
		HTMLtext += '	<embed src="assets_swf/scrubber.swf" flashvars="vidName=../'+assets+'&'+flashVars+'" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+copyWidth+'" height="'+copyHeight+'" name="img_holder" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		HTMLtext += '</object>';
		//alert(HTMLtext);
		var flshDiv = document.createElement( 'div' );
		flshDiv.setAttribute("id","flshDiv");
		node.appendChild(flshDiv);
		document.getElementById('flshDiv').innerHTML = "&nbsp;";
		document.getElementById('flshDiv').innerHTML = HTMLtext;
		//document.getElementById('flshDiv').style.width = copyWidth;
		//document.getElementById('flshDiv').style.height = copyHeight;
	}
}

function photofilmSwitchWide(state, assets, flashVars){
	var node = document.getElementById('wideimg');
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	if(state=="photo"){
		document.getElementById('flmLink').className = "showDisplay";
		document.getElementById('phtLink').className = "clearDisplay";
		HTMLtext = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="910" height="300" id="img_holder" align="middle">';
		HTMLtext += '	<param name="allowScriptAccess" value="sameDomain" />';
		HTMLtext += '	<param name="movie" value="assets_swf/img_holder.swf" />';
		HTMLtext += '	<param name="quality" value="high" />';
		HTMLtext += '	<param name="wmode" value="transparent" />';
		HTMLtext += '	<param name="bgcolor" value="#ffffff" />';
		HTMLtext += '	<param name="FlashVars" value="list='+assets+'" />';
		HTMLtext += '	<embed src="assets_swf/img_holder.swf" flashvars="list='+assets+'" quality="high" wmode="transparent" bgcolor="#ffffff" width="910" height="300" name="img_holder" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		HTMLtext += '</object>';

		var flshDiv = document.createElement( 'div' );
		flshDiv.setAttribute("id","flshDivWide");
		node.appendChild(flshDiv);
		document.getElementById('flshDivWide').innerHTML = "&nbsp;";
		document.getElementById('flshDivWide').innerHTML = HTMLtext;
		//alert(document.getElementById('flshDivWide').innerHTML);
		//document.getElementById('flshDivWide').style.width = 910;
		//document.getElementById('flshDivWide').style.height = 300;
	} else {
		document.getElementById('flmLink').className = "clearDisplay";
		document.getElementById('phtLink').className = "showDisplay";
		HTMLtext = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="910" height="300" id="scrubber" align="middle">';
		HTMLtext += '	<param name="allowScriptAccess" value="sameDomain" />';
		HTMLtext += '	<param name="movie" value="assets_swf/scrubber.swf" />';
		HTMLtext += '	<param name="quality" value="high" />';
		HTMLtext += '	<param name="wmode" value="transparent" />';
		HTMLtext += '	<param name="bgcolor" value="#ffffff" />';
		HTMLtext += '	<param name="FlashVars" value="vidName=../'+assets+'&'+flashVars+'" />';
		HTMLtext += '	<embed src="assets_swf/scrubber.swf" flashvars="vidName=../'+assets+'&'+flashVars+'" quality="high" wmode="transparent" bgcolor="#ffffff" width="910" height="300" name="img_holder" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		HTMLtext += '</object>';
		//alert(HTMLtext);
		var flshDiv = document.createElement( 'div' );
		flshDiv.setAttribute("id","flshDivWide");
		node.appendChild(flshDiv);
		document.getElementById('flshDivWide').innerHTML = "&nbsp;";
		document.getElementById('flshDivWide').innerHTML = HTMLtext;
		//document.getElementById('flshDivWide').style.width = 910;
		//document.getElementById('flshDivWide').style.height = 300;
	}
}



//Reset the site is used by the homepage to setup the site.
function resetSite() {
	curPage = "";
	document.getElementsByTagName("body")[0].className = "whitePage";

	document.getElementById('homelink').className = "inactive";
	
	for(var i=0; i<numberOfProjects; i++){
		document.getElementById('project'+i).className = "show inactive";
	}
	document.getElementById('infoNode').className = "show";
	document.getElementById('infoList').className = "hide";
	
	document.getElementById('exhibitions').className = "inactive";
	document.getElementById('bio').className = "inactive";
	document.getElementById('contact').className = "inactive";
	
	document.getElementById('textContent').innerHTML = "";
	
	if(hasFlashVersion(8)){ setHomeFlash(); }				
}

function setPage(url, sectionName, pageName, pagecolor) {
	if(curPage!=pageName){
		document.getElementsByTagName("body")[0].className = pagecolor+"Page";
		curPage = pageName;
	
		switch(sectionName){
		case "info":
			for(var i=0; i<numberOfProjects; i++){
				document.getElementById('project'+i).className = "hide";
			}
			document.getElementById('exhibitions').className = (pageName=='exhibitions') ? "inactive" : "active";
			document.getElementById('bio').className = (pageName=='bio') ? "inactive" : "active";
			document.getElementById('contact').className = "active";
		
			break    
		case "project":
			document.getElementById('infoList').className = "hide";
			for(var i=0; i<numberOfProjects; i++){
				if(('project'+i) != pageName){
					document.getElementById('project'+i).className = "hide";
				}
			}
			document.getElementById('infoNode').className = "hide";
			break
		default:
			resetSite();
			return false;
		}
		
		loadXMLDoc(url);
		urchinTracker(url);
	} else {
		resetSite();
	}
}


function processReqChange() {
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
        		document.getElementById('textContent').innerHTML = req.responseText; 
        		//eval(curPage+"_var");
        		//var FO = { movie:"assets_swf/img_holder.swf", width:"100%", flashvars:"list="+eval(curPage+"_var"), height:"100%", wmode:"transparent", majorversion:"8", build:"0" };
				//UFO.create(FO, "textcopy");
        } else {
            alert("There was a problem retrieving the XML data: " + req.statusText);
        }
    }
}

function loadXMLDoc(url) {
    document.getElementById('textContent').innerHTML = ""; 
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
		req.open("GET", url);
        req.send(null);	
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url);
            req.send();
        }
    }
}

function setLinks(){
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		links[i].alt = "";
		var lnk = links[i].href.split("html_");
		links[i].href = lnk.join("");
	}
}	

function setHomeFlash(){
  				var node = document.getElementById('textContent');
				HTMLtext = '<div id="textnav">&nbsp;</div>';
				HTMLtext += '<div id="textcopy">';
				HTMLtext += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+copyWidth+'" height="'+copyHeight+'" id="img_holder" align="middle">';
				HTMLtext += '	<param name="allowScriptAccess" value="sameDomain" />';
				HTMLtext += '	<param name="movie" value="assets_swf/img_holder_main.swf" />';
				HTMLtext += '	<param name="quality" value="high" />';
				HTMLtext += '	<param name="wmode" value="transparent" />';
				HTMLtext += '	<param name="bgcolor" value="#ffffff" />';
				HTMLtext += '	<param name="FlashVars" value="dir=assets_img/HomeImgs&num=14" />';
				HTMLtext += '	<embed src="assets_swf/img_holder_main.swf" flashvars="dir=assets_img/HomeImgs&num=13" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+copyWidth+'" height="'+copyHeight+'" name="img_holder" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
				HTMLtext += '</object>';
				HTMLtext += '</div>';
				var flshDiv = document.createElement( 'div' );
				flshDiv.setAttribute("id","flshDiv");
				node.appendChild(flshDiv);
				document.getElementById('flshDiv').innerHTML = "&nbsp;";
				document.getElementById('flshDiv').innerHTML = HTMLtext;
		}

function setExhibit(ttl, file){
  				var node = document.getElementById('textcopy');
				while(node.firstChild){
					node.removeChild(node.firstChild);
				}
				
				//HTMLtext = '<div id="textnav">&nbsp;</div>';
				HTMLtext = '<div id="flashElm">';
				HTMLtext += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+copyWidth+'" height="'+copyHeight+'" id="img_holder" align="middle">';
				HTMLtext += '	<param name="allowScriptAccess" value="sameDomain" />';
				HTMLtext += '	<param name="movie" value="assets_swf/exb_img_holder.swf" />';
				HTMLtext += '	<param name="quality" value="high" />';
				HTMLtext += '	<param name="wmode" value="transparent" />';
				HTMLtext += '	<param name="bgcolor" value="#ffffff" />';
				HTMLtext += '	<param name="FlashVars" value="list='+file+'&ttlVar='+ttl+'" />';
				HTMLtext += '	<embed src="assets_swf/exb_img_holder.swf" flashvars="list='+file+'&ttlVar='+ttl+'" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+copyWidth+'" height="'+copyHeight+'" name="img_holder" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
				HTMLtext += '</object>';
				HTMLtext += '</div>';
				var flshDiv = document.createElement( 'div' );
				flshDiv.setAttribute("id","flshDiv");
				node.appendChild(flshDiv);
				document.getElementById('flshDiv').innerHTML = "&nbsp;";
				document.getElementById('flshDiv').innerHTML = HTMLtext;
		}


//Function to set cookie with the username if the checkbox is set
function setLangCookie(lang){
	createCookie('languageToUse',lang,85);
	return true;
}

//Function to set the username field  with the username from the cookie if it is there
function getLang(){
	getLang = (readCookie('languageToUse')==null) ? "french" : readCookie('languageToUse');
	languageSwitch(getLang);
	}

function hoverContact(){
	document.getElementById('contact').innerHTML = "studio@stephanesednaoui.com";
	}
function unhoverContact(){
	document.getElementById('contact').innerHTML = "contact";
	}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie( name ){ createCookie(name,"",-1); }

function checkBrowserHome(){
		checkBrowser();
		if(hasFlashVersion(8)){ setHomeFlash(); }				
	}
function checkBrowser(){
				windim = getDims();
				if(windim[0] < 1900 || windim[1] < 800){
					setActiveStyleSheet('small'); 
					copyWidth = 525;
					copyHeight = 475;
				} else {
					setActiveStyleSheet('regular'); 
					copyWidth = 800;
					copyHeight = 650;
				}
				//alert(windim[0]+" || "+windim[1]);
				//alert(copyWidth+" || "+copyHeight);
				
	}

function maximizeWin() {
			if (window.screen) {
				var aw = screen.availWidth;
				var ah = screen.availHeight;
				window.moveTo(0, 0);
				window.resizeTo(aw, ah);
			}
		}

function reScale() {
			if (window.screen) {
				var aw = screen.availWidth;
				var ah = screen.availHeight;
				window.resizeTo(aw, ah);
			}
		}
		