//function for keeping movie in the right place
var FLASHLOCATION;
function locateContent(){
	var SCREENWIDTH;
	SCREENWIDTH = parseInt(document.getElementById("Main").clientWidth);
	FLASHLOCATION = parseInt(document.getElementById("SubMain").style.width);
	if (SCREENWIDTH >= 1130) {
		FLASHLOCATION = 100;
		document.getElementById("SubMain").style.marginLeft = "";
		document.getElementById("SubMain").style.marginRight = "";
		document.getElementById("SubMain").style.width = 100 + "%";
		document.getElementById("SubMain").style.left = 0 + "px";
	} else {
		FLASHLOCATION = 900;
		document.getElementById("SubMain").style.left = "";
		document.getElementById("SubMain").style.width = 900 + "px";
		document.getElementById("SubMain").style.marginLeft = "auto";
		document.getElementById("SubMain").style.marginRight = "auto";
	}	
}

//functions for manipulating addresses and other web page attributes
function getHref(){return window.location.href;}
function setHref(newhref){window.location.href = newhref;}
function getTitle(){return document.title;}
function setTitle(newtitle){document.title = newtitle;}
function getHash(){return window.location.hash;}
var flashHash;
function setHash(newhash){flashHash = newhash; window.location.hash = newhash;}

//the next two functions go together to set the title based on hash value, checks hash first and compares it to JSHASH set by flash
function startInterval(){
	var intervalID;
	if (intervalID){
		clearInterval(intervalID);
	}
	intervalID = setInterval("intervalFunctions()", 200);
}

function intervalFunctions(){
	checkWidth();
	checkHash();
	checkTitle();
}
var oldScreenWidth = -1;
function checkWidth(){
	if (oldScreenWidth != FLASHLOCATION){
		setWidthFlag = true;
		oldScreenWidth = FLASHLOCATION;
		if (document.AATSLoader){
			document.AATSLoader.jsSetScreenWidth(FLASHLOCATION);
		} else if (document.embeds.AATSLoader){
			document.embeds.AATSLoader.jsSetScreenWidth(FLASHLOCATION);
		} else if (document.getElementById("AATSLoader")){
			document.getElementById("AATSLoader").jsSetScreenWidth(FLASHLOCATION);
		}
	}
}

function checkHash(){
	var currentHash = window.location.hash.toLowerCase();
	if (currentHash.indexOf(flashHash) == -1){
		if (document.AATSLoader){
			document.AATSLoader.jsSetHash(window.location.hash);
		} else if (document.embeds.AATSLoader){
			document.embeds.AATSLoader.jsSetHash(window.location.hash);
		} else if (document.getElementById("AATSLoader")){
			document.getElementById("AATSLoader").jsSetHash(window.location.hash);
		}	
	}
}

function checkTitle(){
	switch (window.location.hash){
		case "#AboutUs":
			if (getTitle() != "AATS / About Us"){setTitle("AATS / About Us");}
			break;
		case "#SpayAndNeuter":
			if (getTitle() != "AATS / Spay and Neuter"){setTitle("AATS / Spay and Neuter");}
			break;
		case "#AnimalRescue":
			if (getTitle() != "AATS / Animal Rescue"){setTitle("AATS / Animal Rescue");}
			break;
		case "#KittyHeaven":
			if (getTitle() != "AATS / Kitty Heaven"){setTitle("AATS / Kitty Heaven");}
			break;
		case "#LocalEvents":
			if (getTitle() != "AATS / Local Events"){setTitle("AATS / Local Events");}
			break;
		case "#Videos":
			if (getTitle() != "AATS / Videos"){setTitle("AATS / Videos");}
			break;
		case "#ContactUs":
			if (getTitle() != "AATS / Contact Us"){setTitle("AATS / Contact Us");}
			break;
		case "#Donate":
			if (getTitle() != "AATS / Donate"){setTitle("AATS / Donate");}
			break;
		case "#AnimalNetwork":
			if (getTitle() != "AATS / Animal Network"){setTitle("AATS / Animal Network");}
			break;
		default:
			setTitle("Amigos de los Animales de Todos Santos");
			break;
	}
}
