var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
var bName = navigator.appName;
var bVer = parseFloat(navigator.appVersion);
var player = 0;
var speed = 0;
var sticky = 0;
var preloadFlag=0;
var mac = navigator.userAgent.indexOf("mac") > -1; 
var n = navigator.userAgent; 
var msVer = n.substr(n.indexOf("MSie ")+("MSie ").length, 3); 

if(document.images){
nav_arrow = newImage("images/spacer.gif");
nav_arrow_o = newImage("images/nav_arrow_o.gif");
preloadFlag=1;
}

function homeinitDiv(divName){
	homeplaceDiv(divName);
	controlObjectVisibility(divName, 1);
}

function homeplaceDiv(divName){
	if (document.layers) { 										//if Netscape 4.0
		var available_width = window.innerWidth;
		var available_height = window.innerHeight;
	} else { 										 			//if Anything else
		var available_width = document.body.clientWidth ;
		var available_height = document.body.clientHeight ;
	}
	

	(document.layers)?eval('document.layers["'+divName+'"].width='+available_width):eval('document.getElementById("'+divName+'").style.width='+available_width);
	(document.layers)?eval('document.layers["'+divName+'"].top='+ (available_height-206)):eval('document.getElementById("'+divName+'").style.top='+ (available_height-206));
}

function newImage(arg) {
	if (document.images) {
	rslt = new Image();
	rslt.src = arg;
	return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function on(imgName){
if (sticky == imgName) return;
 if (document.images) {
 	 document[imgName].src = eval(imgName + "_f2.src") ;
	 }
}

function off(imgName){
if (sticky == imgName) return;
 if (document.images) {
 	document[imgName].src = eval(imgName + "_f1.src") ;
 	}
 }
	
function down(imgName){
if(mac)if(ms == 'MSie') {alert('here i am');return;}

 if (document.images) {
 		if(sticky != 0){
	 	document[sticky].src = eval(sticky + "_f1.src") ;
		}	
 	}

sticky = imgName;

 if (document.images) {
 	document[imgName].src = eval(imgName + "_f3.src") ;
 	document.body.background = eval("bg_" + imgName + ".src") ;
 	}

}	

function initDiv(divName){
	placeDiv(divName);
	controlObjectVisibility(divName, 1);
}

function placeDiv(divName){

	if (document.layers) { 										//if Netscape 4.0
		var available_width = window.innerWidth;
		var available_height = window.innerHeight;
		var scroll_height = window.Height ;
	} else { 										 			//if Anything else
		var available_width = document.body.clientWidth ;
		var available_height = document.body.clientHeight ;
		var scroll_height = document.body.scrollHeight ;
	}
	

	//alert('the value of scroll_height is ' + scroll_height + ' the value of available_height is ' + available_height + ' the difference value is ' +  (scroll_height-available_height) );

	//(document.layers)?eval('document.layers["'+divName+'"].top='+(scroll_height-available_height)):eval('document.getElementById("'+divName+'").style.top='+(available_height-scroll_height));
	
	if ( (navigator.appVersion.indexOf("Mac") > 0) && (navigator.appName.substring(0,9) == "Microsoft") ) {
		document.getElementById(divName).style.width=(available_width-34);
	} else if(document.all) {
		//alert('internet explorer i presume');
		document.getElementById(divName).style.height=scroll_height;
		document.getElementById(divName).style.width=(available_width-34);
	} else if(document.layers){
		document.layers[divName].height=scroll_height;
		document.layers[divName].width=(available_width-34);
	} else if(document.getElementById) {
		//alert('netscape 6 i presume');
		document.getElementById(divName).style.height=scroll_height;
		document.getElementById(divName).style.width=(available_width-34);
	} else {
		
	}
}

function controlObjectVisibility (divName, control_visibility){
	if(control_visibility){
	(document.layers)?eval('document.layers["'+divName+'"].visibility="show"'):eval('document.getElementById("'+divName+'").style.visibility="visible"');
	} else {
	(document.layers)?eval('document.layers["'+divName+'"].visibility="hide"'):eval('document.getElementById("'+divName+'").style.visibility="hidden"');
	}
}

function getCookieValue(pref){
var allcookies = document.cookie;                            // read the cookie file
var search = pref + "=";			
var prefpos = allcookies.indexOf(search);                    // look for pref
	if(prefpos != -1){ 
	var start = prefpos;
	var end = allcookies.indexOf(";",start)
		if (end == -1){ end = allcookies.length; }
	var value = allcookies.substring(start,end);            //get the full name=value pair 
	value = unescape(value);
	value = value.substr( (1 + value.search(/=/i)) ) ;      //peel off the =

	return value;
	} else {
	return false;
	}
}

function getPrefsLoadFrames(subsegNum){
getPrefs()?loadAllFrames(speed,player,subsegNum):alert('please select a player');
}

function getPrefs(){
player = getCookieValue('player');
speed = getCookieValue('speed');
	if((!player) || (!speed)){
	return false;
	} else {
	return true;
	}
}

function saveCookie(name,value){
var nextyear = new Date();
nextyear.setFullYear(nextyear.getFullYear() + 1);
document.cookie = name + "= " + value + "; expires=" + nextyear.toGMTString();
}

function openWindow(url, w, h) {
	var options = "width=" + w + ",height=" + h + ",";
	options += "resizable=yes,scrollbars=yes,status=no,";
	options += "menubar=no,toolbar=no,location=no,directories=no";
	var newWin = window.open(url, 'newWin', options);
	newWin.focus();
}
