var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


//alert(BrowserDetect.browser);
//alert(BrowserDetect.version);
//alert(BrowserDetect.OS);

function getElmtRef(strElmtId) {
	if (!document.getElementById) {
		return document.all[strElmtId];
	} else {
		return document.getElementById(strElmtId);
	}
}




function resetGuides(){	
	var allcookies = document.cookie;
	var bolHasCookie = false;
	if (allcookies.indexOf("setContentHeight") != -1 && allcookies.indexOf("setNewsBoxHeight") != -1){	
		bolHasCookie = true;
	}
	//alert(bolHasCookie);
	var height_difference = 40;
	
	
	if (BrowserDetect.browser == "Explorer"){ 	
		if(BrowserDetect.version < 6){
			window_height = parseInt(document.body.clientHeight)	
		}else{
			window_height = parseInt(document.documentElement.clientHeight);		
		}		
	}else{
		window_height = self.innerHeight;			
	}	
	
	
	
	if((window_height - height_difference - getElmtRef('logo').offsetHeight) > 400){		
			getElmtRef('content').style.height = (window_height - height_difference - getElmtRef('logo').offsetHeight) + 'px';
			getElmtRef('newsBox').style.height = (window_height - height_difference - getElmtRef('logo').offsetHeight - 200) + 'px';
			
			document.cookie = "setContentHeight=" + (window_height - height_difference - getElmtRef('logo').offsetHeight);
			document.cookie = "setNewsBoxHeight=" + (window_height - height_difference - getElmtRef('logo').offsetHeight - 200);		
	}else{
		getElmtRef('content').style.height = '400px';
		getElmtRef('newsBox').style.height = '200px';
		
		document.cookie = "setContentHeight=400";
		document.cookie = "setNewsBoxHeight=200";
	}
	
	//alert(window_height);
	//center_row_height = window_height - height_difference; 
	//if ((getElmtRef('mainNav').offsetHeight < center_row_height)&&(getElmtRef('logo').offsetHeight < center_row_height)&&(getElmtRef('content').offsetHeight < center_row_height)){
		//getElmtRef('wrapper').style.height = center_row_height + 'px';
	//}	
	//moveRollover();
	//setNameRollover();
	setMediaLink();
}
function setNameRollover(){
	var yPosition = findGlobalPosY(getElmtRef('logo'));
	var logoHeight = getElmtRef('logo').offsetHeight;
	var bottomOfPage = yPosition + logoHeight - 40;
	getElmtRef('rollChad').style.top = (bottomOfPage - 56) + 'px';
	getElmtRef('rollRebecca').style.top = (bottomOfPage - 42) + 'px';
	getElmtRef('rollEmily').style.top = (bottomOfPage - 384) + 'px';
	getElmtRef('rollPatti').style.top = (bottomOfPage - 39) + 'px';
}

function moveRollover(){
	var imageHeight = 458;
	//alert(imageHeight);
	var yPosition = findGlobalPosY(getElmtRef('logo'));
	var logoHeight = getElmtRef('logo').offsetHeight;
	//alert(logoHeight);
	if(yPosition >= 0 && logoHeight >= 0){
		//getElmtRef('bandRollover').style.top = ((xPosition + logoHeight) - imageHeight) + 'px';
		getElmtRef('bandRollover').style.top = ((yPosition + logoHeight) - imageHeight - 20) + 'px';
		getElmtRef('bandRollover').style.display = 'block';
	}	
}

function nameDisplay(ctl,ctl2){
	if(ctl2){
		//getElmtRef(ctl).style.display = 'block';
	}else{
		getElmtRef(ctl).style.display = 'none';
	}
	
}
	
	

	window.onload = new Function("resetGuides();");
	window.onresize = new Function("resetGuides();");

function findGlobalPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findGlobalPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
		curtop += 1;
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

//IMAGE ROLLOVERS
function imgOn(imgName) { document[imgName].src = eval(imgName + "_on.src"); }
function imgOff(imgName) { document[imgName].src = eval(imgName + "_off.src"); }

//IMAGE CACHING
var oImgPath = new Object();
oImgPath.topnav = "/img/nav/";

function cacheImg(name,src,rollover,type){
	if (!type) var type = "gif";
	if (rollover==true){
		eval(name + "_off =  new Image");
		eval(name + "_off.src = \'" + src + name + "_off." + type + "\'");
		eval(name + "_on =  new Image");
		eval(name + "_on.src = \'" + src + name + "_on." + type + "\'");
	} else {
		eval(name + " = new Image");
		eval(name + ".src = \'"+src+name+"."+type+"\'");
	}
}



//-----Main Nav
cacheImg('nav_bio',oImgPath['topnav'],true,'jpg');
cacheImg('nav_contact',oImgPath['topnav'],true,'jpg');
cacheImg('nav_links',oImgPath['topnav'],true,'jpg');
cacheImg('nav_media',oImgPath['topnav'],true,'jpg');
cacheImg('nav_photos',oImgPath['topnav'],true,'jpg');
cacheImg('nav_shows',oImgPath['topnav'],true,'jpg');


function timeStamp(){
	tempTheDate = new Date;
	tempTheTimeStamp = "";
	tempTheTimeStamp = String(tempTheDate.getDay()) +  String(tempTheDate.getFullYear()) + String(tempTheDate.getHours()) + String(tempTheDate.getMinutes()) + String(tempTheDate.getSeconds()) + String(tempTheDate.getMonth());
	return tempTheTimeStamp
}

function setShows(ctl){
	if(ctl == 'past'){
		tempHTMLUrl = '/inc/updateShows.asp?showsDispay=past&timeStamp=' + timeStamp();
	}else{
		tempHTMLUrl = '/inc/updateShows.asp?showsDispay=current&timeStamp=' + timeStamp();
	}	
	//makeRequest(tempHTMLUrl);
	loadXMLDoc(tempHTMLUrl)
}
function updateShows(){
	getElmtRef('newsBox_inner').innerHTML = req.responseText;
}


var http_request = false;


function loadXMLDoc(url) {
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    }
 else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            updateShows();
         }
 else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
         }
    }
}


function popWindow(url, width, height, name, scrollbars){
	if (!scrollbars) scrollbars = false;
	if (!width) width = 500;
	if (!height) height = 500;
 	var realW = (width)/2;
	var realH = (height)/2;
 	if (document.all){		
        var xMax = screen.width, yMax = screen.height;
    }else if (document.layers){       
        var xMax = screen.width, yMax = screen.height;
    }else if (document.getElementById){
		var xMax = screen.width, yMax = screen.height;
	}else{
		var xMax = 800, yMax=600;
	}
	var xOffset = ((xMax)/2) - realW, yOffset = (((yMax)/2)) - realH; 
	if (yMax==600){
		yOffset = 0;
	}	
	
	if (scrollbars) {
		var options = "directories=no,status=no,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
	}else{
		var options = "directories=no,status=no,location=no,scrollbars=no,menubar=no,toolbar=no,resizable=no" + ",screenX=" + xOffset + ",screenY=" + yOffset + ",top=" + yOffset + ",left=" + xOffset + ",width=" + width + ",height=" + height;
	}
	
	if (!name) name = "default_window";
	
	popup = window.open(url,name,options);
	popup.focus();	
}


function isEmail(input) {
	return /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9_]+((\.|-)[A-Za-z0-9_]+)*\.[A-Za-z0-9]+$/.test(input);
}

function trim(input) {
  var start = 0;
  while ((start < input.length) && (input.charAt(start) == ' ')) {
    ++start;
  }

  var end = input.length;
  while ((end > 0) && (input.charAt(end - 1) == ' ')) {
    --end;
  }

  return input.substring(start, end);
}

function trySubmit() {	
	f = document.email_form;
	for (i=0; i < f.elements.length; i++) {
		if (f.elements[i].type == "text") f.elements[i].value = trim(f.elements[i].value);
	}

	with(document.email_form) {
		if (!isEmail(email_address.value)) {
			alert("Please enter a correct Email Address.");
			email_address.focus();
		}else if (email_address.value == "email@email.com"){
			alert("Please enter a Email Address.");
			email_address.focus();
		} else {			
			submit();
		}
	}
}

function setMediaLink(){	
	if(BrowserDetect.browser == "Safari"){		
		var pageURL = document.URL;	
		var e=document.getElementsByTagName("a");
		for(var i=0;i<e.length;i++){
			if(e[i].href.indexOf("media.asp") != -1){				
				//e[i].href = "javascript:popWindow('/pop_media.asp', 460, 608, 'media');";	
			}			
		}		
	}
}


