/********************************************************
Name: 			javascript stylesheet
Description: 	loads javascript specific stylesheet
********************************************************/

document.write('<link rel="StyleSheet" href="css/leeMillerJavascript.css" type="text/css" media="screen" />');


function fnConfig() {
	fnSubmitBut();
	fnAnchorInit();
	initCompetition();
	}

function pop(a) {
	window.open(a.href);
	return false;
}

function gP(o) {
	var s = "[";
	for (var p in o) {
		s += p + "->" + o[p] + ",<br/>\n";
	}
	s += "]";
	return s;
}

var ua = navigator.userAgent.toLowerCase();


/******************************************************************************************
set bolean to detect safari on mac - the flash text does not seem to work with 
the opacity background on any gecko browsers on mac
******************************************************************************************/
mac = (ua.indexOf("windows") == -1)? true:false; 
safari = (ua.indexOf("safari") != -1)? true:false; 

/******************************************************************************************
set bolean to detect IE7 - the text sizing sniffer has problems with IE7 zoom.
******************************************************************************************/
ie7 = (ua.indexOf("msie 7") != -1)? true:false;

/******************************************************************************************
set bolean to detect Operas 
******************************************************************************************/
op7 = (ua.indexOf("opera/7") != -1)? true:false;
op9 = (ua.indexOf("opera/9") != -1)? true:false;

/******************************************************************************************
set bolean to detect IE5 Mac
******************************************************************************************/
ieMac = ((ua.indexOf("msie") != -1)&&(ua.indexOf("windows") == -1))? true:false;

/******************************************************************************************
set bolean to detect various ie browsers for use with fnMoveFocus()
******************************************************************************************/
iepc = (((ua.indexOf("msie 7") != -1)||(ua.indexOf("msie 6") != -1)||(ua.indexOf("msie 5.5") != -1))&&(ua.indexOf("windows") != -1)&&(ua.indexOf("opera") == -1))? true:false;


/******************************************************************************************
set bolean to detect Netscape - small:large class resize 
******************************************************************************************/
ns6 = (ua.indexOf("netscape6") != -1)? true:false;
ns7 = (ua.indexOf("netscape/7") != -1)? true:false;
ns8 = (ua.indexOf("netscape/8") != -1)? true:false;






/***********************************************************************************
Force Focus to move past iFrame

onFocus() event has minor browser compatability issues. Not used for Mozilla Browser.

Selects the moveTo ID and jumps to the first link within 

@param: moveTo - must be an ID within the page

************************************************************************************/

function fnMoveFocus(moveToID) {
	if(iepc) {
		document.getElementById(moveToID).getElementsByTagName("A")[0].focus();
	}
}


/********************************************************************************
 
Name:			fnAnchorShowHide
Description:	Show / Hide the tabbed content.  Non-Js fall back to link to page anchors. 
				Anchor contains link to ID of element to show/hide.  JS takes the 
				url, splits string to get ID after the "#", and uses this ID to target
				element to show/hide.  

*********************************************************************************/	

/* ID to show. Sets default shown item */	
var showShItem = "sh01";	
//var contentExtra = document.getElementById("section02Extra").innerHTML;


/* Called when link is clicked.  Gets ID from selected link */	
function fnAnchorShowHide(targ) {
	showShItem = targ.href.split("#")[1];	
	fnRunShowHide();
}	

/* Runs on load.  If anchor link is in URL, it hides all other IDs.  If no ID in URL, it hides all items except the default */	
function fnAnchorInit() {
	if(document.getElementById("showHideWrapper")) {	
		var stUrl = document.location.toString();	
		if(stUrl.match("#")) {
			showShItem = stUrl.split("#")[1];
		}		
		fnRunShowHide();
	}
}

/* Re-writes anchors with class .popLink to append a query string indicating which sub-page the click came from */
function fnRewritePopLinks() {
	var as = document.getElementsByTagName("a");
	if (as) {
		for (var a=0; a<as.length; a++) {
			if (as[a].className == "popLink") {
				if (as[a].href && as[a].href.indexOf("?") != -1) {
					// already has a query string, remove it
					as[a].href = as[a].href.substr(0, as[a].href.indexOf("?"));
				}
				as[a].href += "?showShItem=" + showShItem;
			}
		}
	}
}

/* Hides all items, then shows whichever ID the variable "showShItem" refers to */
function fnRunShowHide() {
	
	var shItems = document.getElementById("showHideWrapper").getElementsByTagName("DIV");
	for (i=0;i<shItems.length;i++) { /* Loop through to hide all items */
		if(shItems[i].className == "anc") {
			fnHideItem(shItems[i].parentNode);
			
		}
	}	
	fnShowItem(document.getElementById(showShItem).parentNode);		
	fnSelectNav(showShItem);
	fnRewritePopLinks();
	//fnMoveIntroExtra()
}


/* Sets navigation select state dependent on whichever ID the variable "showShItem" refers to */
function fnSelectNav(navToSelect) {
	var navLinks = document.getElementById("shNav").getElementsByTagName("A");	
	for (i=0;i<navLinks.length;i++) {
		navLinks[i].parentNode.className = "";		
		if(navLinks[i].href.split("#")[1] == showShItem) {
			navLinks[i].parentNode.className = "selected";
		}
	}	
}

/* Places item on screen */
function fnShowItem(targ) {
	if (typeof(targ) == "string") {
		targ = document.getElementById(targ);
	}
	targ.style.position = "static";	
	targ.style.top = "0";	
	targ.style.left = "0";	
	targ.style.display = "block";
	}

/* Moves item off of the screen */	
function fnHideItem(targ) {
	if (typeof(targ) == "string") {
		targ = document.getElementById(targ);
	}
	targ.style.position = "absolute";	
	targ.style.top = "-3000px";
	targ.style.left = "-3000px";
	targ.style.display = "block";
	}



/* competition functions */
function initCompetition() {
	var e = document.getElementById("terms");
	var l = document.getElementById("termsLink");
	if (e && l) {
		// Dont hide it if someone has linked directly to it.
		if (document.URL.indexOf("#terms") <= 0) {
			fnHideItem(e);
			l.onclick = function() { fnShowItem("terms"); }
		}
	}
}
	
	
function fnSubmitBut() {

	if((document.getElementById("submitRow")) && (document.getElementById("competition").parentNode.className == "graphicText")) {
		document.getElementById("submitRow").innerHTML  = '<input type="image" src="images/uploadPhotoBut.gif" name="Submit" value="Upload your photo" />';
	}
	if((document.getElementById("submitRow")) && (document.getElementById("competition").parentNode.className == "defaultText")) {
		document.getElementById("submitRow").innerHTML  = '<input type="submit" name="Submit" value="Upload your photo" />';
	}
	if((document.getElementById("searchCompBut")) && (document.getElementById("competition").parentNode.className == "graphicText")) {
		document.getElementById("searchCompBut").innerHTML  = '<input type="image" src="images/goBut.gif" name="Submit" value="Upload your photo" />';
	}
	if((document.getElementById("searchCompBut")) && (document.getElementById("competition").parentNode.className == "defaultText")) {
		document.getElementById("searchCompBut").innerHTML  = '<input type="submit" name="Submit" value="Go" />';
	}

}



function fnMoveIntroExtra() {

	alert(contentExtra);

	/* if((document.getElementById("intro"))&&(showShItem == "sh02")){
		document.getElementById("contentExtra").innerHTML = contentExtra;
		document.getElementById("section02Extra").innerHTML = "";
	} else {
		document.getElementById("contentExtra").innerHTML = "";
		document.getElementById("section02Extra").innerHTML = contentExtra;
	} */
}




function fnNewWindow(targ) {
	var obj = targ.href;
	window.open(obj);	
	}

