/*
Author: Brendan Phillips [brendan.p.phillips@gmail.com]

All contents copyright 2009 by Brendan Phillips.
All rights reserved.
No part of this code or the related files may be reproduced or transmitted in any form, by any means without the prior written permission of the owner.

The code provided herein is provided "as is."
Brendan Phillips has used his best efforts in preparing this code, and makes no representation or warranties with respect to its accuracy or completeness and specifically disclaims any implied warranties of merchantability or fitness for any particular purpose.
In no event shall he be liable for any loss of profit or any other commercial damage, including but not limited to special, incidental, consequential, or other damages.

Steppin' Razor [steppin-razor.com] has recieved permission from Brendan Phillips to use this code.
*/
var siteURL="http:\/\/www.steppin-razor.com/";
var sectionsArray=["home","bio","images","links","contact"];//home must always go first
var sectionsLoadedArray=[0,0,0,0,0];
var sectionsTitlesArray=["Welcome To Steppin\' Razor\'s Homepage","Steppin\' Razor\'s Bio","Steppin\' Razor\'s Images","Links","Contact Steppin' Razor"];

String.prototype.trim=function(){return this.replace(/\s+/g,"").replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/g,"$1");}
String.prototype.removeCarriageReturns=function(replacementStr_isOptional){return this.replace(/\n+/g,"\r").replace(/\r+/g,(replacementStr_isOptional)?replacementStr_isOptional:"");}
String.prototype.trimToSingleSpaces=function(){return this.replace(/\s+/g," ").replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/g,"$1");}//only single spaces [no tabs/breaks]

var xmlHttp;
var browserIsIE=(navigator.userAgent.indexOf("MSIE")>=0);
var browserIsFireFox=(navigator.userAgent.indexOf("Firefox")>=0);
var fadeTimer,checkUrlInterval=false;
var useIFRAME=false;

function $(elmtIdStr){try{return (typeof(elmtIdStr)==='string')?document.getElementById(elmtIdStr):elmtIdStr;}catch(e){}}
function $$(tagNameStr,containerElmt_isOptional){try{return $GET_CONTAINER(containerElmt_isOptional).getElementsByTagName(tagNameStr);}catch(e){}}
function $GET_CONTAINER(containerElmt_isOptional){try{return (!containerElmt_isOptional)?document:$(containerElmt_isOptional);}catch(e){}}
function $$C(classNmStr,containerElmt_isOptional){
	try{
		var arr=[];
		var regEx=new RegExp('\\b' + classNmStr + '\\b');
		var elmts=$$("*",containerElmt_isOptional);
		for(var i=0;i<elmts.length;i++)if(regEx.test(elmts[i].className))arr.push(elmts[i]);
		return arr;
	}catch(e){}
}

var oldLocation=false;

function initMain(){
	try{
		resetMainLinkHrefs('mainLinks');
		resetMainLinkHrefs('footer');
		replaceEmailsAddrs();
		if(forceNoJS)return;
		setContentAsLoaded(initialPageName);
		var sectIdStr=getSectionIdStrFromURL();
		try{if(sectIdStr=="images")imagesInit();}catch(e){}
		if(getSectionsArrayIndex(sectIdStr)<0){
			sectIdStr=initialPageName;
			try{if(sectIdStr=="images")imagesInit();}catch(e){}
			setHashAnchor(sectIdStr);
		}
		oldLocation=sectIdStr;
		setPageTitle(sectIdStr);
		if(!sectionLoadedByPHP(sectIdStr))getContent(sectIdStr);
	}catch(e){}
}
function checkURL(){
	try{
		var sectIdStr=getSectionIdStrFromURL();
		if(oldLocation!=sectIdStr){
			oldLocation=sectIdStr;
			linkReplacementFncShowSectionContent(sectIdStr);
		}
	}catch(e){}
}
function getSectionIdStrFromURL(){
	try{
		var splitURL=location.href.toLowerCase();
		var t1=splitURL.replace(/.*#(.*)/gi,"$1");
		if(!t1||splitURL==t1)t1=splitURL.replace(/.*?page=(.*)/gi,"$1");
		if(!t1||splitURL==t1)return initialPageName.toLowerCase();
		else return t1;
	}catch(e){}
}



function sectionLoadedByPHP(sectIdStr){
	try{
		if(contentIsLoaded(sectIdStr))return true;
		else if($(sectIdStr+'ContentContainerContentDIV')){
			var contentTargetNodesCounter=0;
			var contentTargetNodes=$(sectIdStr+'ContentContainerContentDIV').childNodes;
			for(var i=0;i<contentTargetNodes.length;i++){
				if(contentTargetNodes[i].nodeType==1 || (contentTargetNodes[i].nodeType==3 && contentTargetNodes[i].nodeValue.trim()!="")){
					setContentAsLoaded(sectIdStr);
					//showContentSection(sectIdStr);
					return true;
				}
			}
		}
		return false;
	}catch(e){}
}
function getSectionsArrayIndex(sectIdStr){
	try{
		for(var i=0;i<sectionsArray.length;i++)
			if(sectionsArray[i]==sectIdStr)return i;
		return -1;
	}catch(e){return -1;}
}
function contentIsLoaded(sectIdStr){
	try{
		for(i=0;i<sectionsArray.length;i++)
			if(sectIdStr==sectionsArray[i]){
				if(sectionsLoadedArray[i]!=0)return true;
				else return false;
			}
		return false;
	}catch(e){return false;}
}
function contentIsVisible(sectIdStr){
	try{
		return ($$C("contentTableContainer")[0].id==sectIdStr+"ContentContainer");
	}catch(e){return false;}
}
function setContentAsLoaded(sectIdStr){
	try{
		for(i=0;i<sectionsArray.length;i++)
			if(sectIdStr==sectionsArray[i]){
				sectionsLoadedArray[i]=1;
				return;
			}
	}catch(e){}
}

var mainLinkHrefsSet=[];//because this function called on mouseover of header & footer links (to prevent issues from occuring prior to body onload) and called in initMain() [fnc called on load of BODY].
function resetMainLinkHrefs(containerElmtIdStr){
	try{
		try{resetListenAnchors();}catch(e){}
		if(mainLinkHrefsSet.length==2||(mainLinkHrefsSet.length==1&&containerElmtIdStr==mainLinkHrefsSet[0]))return;
		mainLinkHrefsSet.push(containerElmtIdStr);
		var As=$$("A",containerElmtIdStr);
		var p;
		if(forceNoJS){
			for(var i=0;i<As.length;i++){
				//p=As[i].getAttribute("content");
				//p=As[i].getAttribute("class");
				p=As[i].className;//fake CSS class for w3c validation purposes
				if(p)As[i].setAttribute("href","index.php?page="+p+"#"+p);		
			}
			return;
		}
		for(var i=0;i<As.length;i++){
			//p=As[i].getAttribute("content");
			//p=As[i].getAttribute("class");
			p=As[i].className;//fake CSS class for w3c validation purposes
			if(p){
				var splitURL=false;
				try{
					splitURL=location.href.toLowerCase().split("#")[0];
				}catch(e){}
				if(!splitURL)splitURL=location.href.toLowerCase();
				splitURL+="#"+p
				As[i].setAttribute("href",splitURL);
				As[i].onclick=function(){ eval("linkReplacementFncShowSectionContent(this.href.split('#')[1])") };
			}
		}
	}catch(e){}
}
function setPageTitle(sectIdStr){
	try{
		if(!sectIdStr)sectIdStr=getSectionIdStrFromURL();
		var sectionsArrayIndex=getSectionsArrayIndex(sectIdStr);
		if(sectionsArrayIndex>-1)document.title=sectionsTitlesArray[sectionsArrayIndex];
	}catch(e){}
}
function linkReplacementFncShowSectionContent(sectIdStr){
	try{
		setPageTitle(sectIdStr);
		if(sectIdStr!="images")closeImagePopupDiv();
		if(contentIsLoaded(sectIdStr)){
			if(!contentIsVisible(sectIdStr))showContentSection(sectIdStr);
		}
		else getContent(sectIdStr);
	}catch(e){}
}
function getSectionIdStrFromIFrameURL(){
	try{
	
		var iFrame=getIFrame();
		var iFrameHref=false;
		try{
			iFrameHref=iFrame.location.href.toLowerCase();
		}catch(e){}
		if(!iFrameHref){
			try{
				iFrameHref=iFrame.src.toLowerCase();
			}catch(e){}
		}
		if(!iFrameHref || iFrameHref==location.href.toLowerCase() || iFrameHref.substring(iFrameHref.length-5, iFrameHref.length).toLowerCase()!=".html")
			return false;
		
		iFrameHref=iFrameHref.substring(0,iFrameHref.length-5);//for ".html"
		//iFrameHref=iFrameHref.substring(0,iFrameHref.length-4);//for ".txt"
		try{
			iFrameHref=iFrameHref.split("\/")[iFrameHref.split("\/").length-1];
		}catch(e){}
		if(getSectionsArrayIndex(iFrameHref)<0)return false;
		return iFrameHref.toLowerCase();
	}catch(e){return false;}
}
function getContent(sectIdStr){
	try{
		if(sectIdStr=="images")$('loadingMsgSpan').innerHTML="Photos";
		else $('loadingMsgSpan').innerHTML=sectIdStr.substring(0,1).toUpperCase()+sectIdStr.substring(1,sectIdStr.length)+" Page";
		fadeLoadingSection(true);
		//var url="PAGETEXT\/"+sectIdStr+".txt";
		var url="PAGECONTENT\/"+sectIdStr+".html";
		try{
			xmlHttp=new XMLHttpRequest();
			useIFRAME=false;
		}catch(e){}
		if(!xmlHttp||xmlHttp==null){//browser can't handle XMLHttpRequest
			useIFRAME=true;
			$('IFRAME_FOR_BACK_BUTTON_AND_NO_ACTIVEX').src=url;
		}
		else{
			xmlHttp.onreadystatechange=function(){stateChanged(sectIdStr)};
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		}
	}catch(e){redirectInCatch(sectIdStr)}
}
function stateChanged(sectIdStr){
	try{
		if(xmlHttp.readyState==4||xmlHttp.readyState=="complete"){
			var ajaxResponse=xmlHttp.responseText;
			setContentToAjaxResp(ajaxResponse,sectIdStr);
			checkUrlInterval=setInterval("checkURL()",100);
			replaceEmailsAddrs();
		}
	}catch(e){redirectInCatch(sectIdStr)}
}

function checkIFrameState(sectIdStr,timeAmt){
	try{
		if(forceNoJS)return;
		if(useIFRAME){
			if(!sectIdStr){
				sectIdStr=getSectionIdStrFromIFrameURL();
				if(!sectIdStr){
					sectIdStr=initialPageName;
					setContentAsLoaded(sectIdStr);
					try{
						setHashAnchor(sectIdStr);
					}catch(e){}
					linkReplacementFncShowSectionContent(sectIdStr);
					return;
				}
			}
			var iFrame=getIFrame();
			timeAmt=timeAmt||2;
			var ajaxResponse=getIFrameContents();//iFrame.document.body.innerText;
			if(!ajaxResponse || ajaxResponse.trim()=="")return;//ignore blank - page not loaded by default
			else{
				setContentToAjaxResp(ajaxResponse,sectIdStr);
				try{
					setHashAnchor(sectIdStr);
				}catch(e){}
				checkUrlInterval=setInterval("checkURL()",100);
				replaceEmailsAddrs();
			}
		}
	}catch(e){redirectInCatch(sectIdStr)}
}

function setContentToAjaxResp(ajaxResponse,sectIdStr){
	try{
		if(sectIdStr=="images"){
			ajaxResponse=ajaxResponse.removeCarriageReturns(" ").trimToSingleSpaces().split(/\s/g);
			var imagesPageInnerHTML="";
			for(var i=0;i<ajaxResponse.length;i++)
				imagesPageInnerHTML+="<a href='image.php?img="+ajaxResponse[i]+"' valuetype='IMAGES/LARGE/"+ajaxResponse[i]+"'><img src='IMAGES/PREVIEW/"+ajaxResponse[i]+"' border='0' align='middle' alt='"+ajaxResponse[i]+"'></a>";
			$(sectIdStr+"ContentContainerContentDIV").innerHTML=imagesPageInnerHTML;
			imagesInit();//from bp.js
		}
		else $(sectIdStr+"ContentContainerContentDIV").innerHTML=ajaxResponse;
		setContentAsLoaded(sectIdStr);
		linkReplacementFncShowSectionContent(sectIdStr);
		fadeLoadingSection(false);
	}catch(e){redirectInCatch(sectIdStr)}
}
function getIFrame(){
	if(useIFRAME){
		var iFrame=$('IFRAME_FOR_BACK_BUTTON_AND_NO_ACTIVEX');
		try{
			if(document.frames)iFrame=document.frames['IFRAME_FOR_BACK_BUTTON_AND_NO_ACTIVEX'];
		}catch(e){}
		return iFrame;
	}
}
function getIFrameContents(){
	try{
		var ajaxResponse="";
		
		var iFrame=getIFrame();
		try{
			if((!ajaxResponse || ajaxResponse.trim()=="")&&iFrame.document.body.innerHTML)ajaxResponse=iFrame.document.body.innerHTML;
		}catch(e){}
		try{
			if((!ajaxResponse || ajaxResponse.trim()=="")&&iFrame.contentWindow.document.body.innerHTML)ajaxResponse=iFrame.contentWindow.document.body.innerHTML;
		}catch(e){}
		try{
			if((!ajaxResponse || ajaxResponse.trim()=="")&&iFrame.document.body.innerText)ajaxResponse=iFrame.document.body.innerText;
		}catch(e){}
		try{
			if((!ajaxResponse || ajaxResponse.trim()=="")&&iFrame.contentWindow.document.body.textContent)ajaxResponse=iFrame.contentWindow.document.body.textContent;
		}catch(e){}
		
		if(!ajaxResponse || ajaxResponse.trim()=="")redirectInCatch(false);
		return ajaxResponse;
	}catch(e){}
}
function showContentSection(sectIdStr){
	//don't catch errors here. Handle in calling fnc.
	//fade out old
	var contentTableContainer=$$C("contentTableContainer");
	contentTableContainer=contentTableContainer[0];
	fadeContentSection(contentTableContainer.id,false);
	contentTableContainer.className="hide";
	
	//fade in new
	$(sectIdStr+"ContentContainer").className="contentTableContainer";
	fadeContentSection(sectIdStr+"ContentContainer",true);
}
function fadeContentSection(elmtIdStr,fadeInBool,fadeCnt){
	try{
		clearTimeout(fadeTimer);
		if(!fadeCnt)fadeCnt=0;
		fadeCnt++;
		if(fadeCnt>30)return;
		else{
			if(fadeInBool)setOpacity(Math.abs(3.33*fadeCnt),elmtIdStr);
			else setOpacity(100-(3.33*fadeCnt),elmtIdStr);
			fadeTimer=setTimeout("fadeContentSection(\""+elmtIdStr+"\","+fadeInBool+","+fadeCnt+")", 3);
		}
	}catch(e){
		try{
			if(elmtIdStr){
				var newOpacity=0;
				if(fadeInBool){
					newOpacity=100;
					setOpacity(newOpacity,elmtIdStr);
				}
				else if($(elmtIdStr))$(elmtIdStr).className="hide";
			}
		}catch(e){redirectInCatch(false);}//no sectIdStr so pass false
	}
}



var loadingFadeTimer,fadingIn,loadingFadeOutIsWaiting=false;

function fadeLoadingSection(fadeInBool,fadeCnt){
	try{
		if(fadeInBool)fadingIn=true;
		if(fadingIn && !fadeInBool)loadingFadeOutIsWaiting=true;
		else{
			clearTimeout(loadingFadeTimer);
			if(!fadeCnt){
				fadeCnt=0;
				if(fadeInBool)$('loadingBPholder').className="";
			}
			fadeCnt++;
			var newOpacity=(3.33*fadeCnt);
			if(fadeInBool)setOpacity(newOpacity,'dialogReplacementInteractionBlocker');
			else setOpacity((50-newOpacity),'dialogReplacementInteractionBlocker');
			if(newOpacity<51)loadingFadeTimer=setTimeout("fadeLoadingSection("+fadeInBool+","+fadeCnt+")", 3);
			else{
				if(fadeInBool){
					fadingIn=false;
					if(loadingFadeOutIsWaiting){
						loadingFadeOutIsWaiting=false;
						fadeLoadingSection(false);
					}
				}
				else $('loadingBPholder').className="hide";
			}
		}
	}catch(e){
		$('loadingBPholder').className="hide";
	}
}
function resetListenAnchors(){
	var a;
	try{
		a=$('listenLink')
		a.setAttribute("href","javascript:openListenChildWindow()");
		a.setAttribute("target","_self");
	}catch(e){}
	try{
		a=$('listenLinkFooter')
		a.setAttribute("href","javascript:openListenChildWindow()");
		a.setAttribute("target","_self");
	}catch(e){}
	try{
		a=$('streetTeamLink')
		a.setAttribute("href","javascript:openStreetTeamWindow()");
		a.setAttribute("target","_self");
	}catch(e){}
	try{
		a=$('streetTeamLinkFooter')
		a.setAttribute("href","javascript:openStreetTeamWindow()");
		a.setAttribute("target","_self");
	}catch(e){}
	try{
		a=$('scheduleLink')
		a.setAttribute("href","javascript:openScheduleWindow()");
		a.setAttribute("target","_self");
	}catch(e){}
	try{
		a=$('scheduleLinkFooter')
		a.setAttribute("href","javascript:openScheduleWindow()");
		a.setAttribute("target","_self");
	}catch(e){}
}
var listenWindow=false;
function openListenChildWindow(){
	try{
		if(listenWindow&&!listenWindow.closed)listenWindow.focus();
		else listenWindow=window.open('listen.htm','Listen','width=434,height=415,toolbar=no,menubar=no,scrollbars=no,resizable=no,left=10,top=10,location=0,toolbar=0,directories=0');
	}catch(e){}
}
var streetTeamWindow=false;
function openStreetTeamWindow(){
	try{
		if(streetTeamWindow&&!streetTeamWindow.closed)streetTeamWindow.focus();
		else streetTeamWindow=window.open('StreetTeam.htm','StreetTeam','width=430,height=80,toolbar=no,menubar=no,scrollbars=no,resizable=no,left=10,top=10,location=0,toolbar=0,directories=0');
	}catch(e){}
}
var scheduleWindow=false;
function openScheduleWindow(){
	try{
		if(scheduleWindow&&!scheduleWindow.closed)scheduleWindow.focus();
		else scheduleWindow=window.open('Schedule.htm','StreetTeam','width=433,height=247,toolbar=no,menubar=no,scrollbars=no,resizable=no,left=10,top=10,location=0,toolbar=0,directories=0');
	}catch(e){}
}
function setOpacity(opacity, elmtIdStr){
	//don't catch errors here. Handle in calling fnc.
	if(!elmtIdStr)elmtIdStr="expandableImgDiv";
	elmtIdStr=$(elmtIdStr);
	if(browserIsIE)elmtIdStr.style.filter="alpha(opacity="+opacity+")";
	else{
		if(browserIsFireFox&&(opacity==100))opacity=99.9999;
		elmtIdStr.style.opacity=opacity/100;
	}
}
function setHashAnchor(sectIdStr){
	try{
		if(!sectIdStr)sectIdStr=getSectionIdStrFromURL();
		if(!sectIdStr)location.href=siteURL;
		else location.href=location.href.toLowerCase().replace(/#.*/gi,"")+"#"+sectIdStr;
	}catch(e){redirectInCatch(sectIdStr)}
}
function replaceEmailsAddrs(){
	var SPANs=document.getElementsByTagName("SPAN");
	var currEmailAddrSPAN;
	var emailAddr;
	for(var i=0;i<SPANs.length;i++){
		//if(SPANs[i].getAttribute("name") && SPANs[i].getAttribute("name")=="emailAddrSPAN"){
		if(SPANs[i].getAttribute("title") && SPANs[i].getAttribute("title")=="emailAddr"){
			currEmailAddrSPAN=SPANs[i];
			emailAddr=currEmailAddrSPAN.innerHTML.replace("[at]","@");
			emailAddr="<A href=\"mailto:"+emailAddr+"\">"+emailAddr+"<\/A>";
			currEmailAddrSPAN.innerHTML=emailAddr;
		}
	}
}
function redirectInCatch(sectIdStr){
	try{
		if(!sectIdStr)sectIdStr=getSectionIdStrFromURL();
		if(!sectIdStr)location.href=siteURL;
		else location.href=location.href.toLowerCase().replace(/\?page=.*/gi,"").replace(/#.*/gi,"")+"?page="+sectIdStr+"#"+sectIdStr;
	}catch(e){location.href=siteURL;}
}