var page = document.location.href.split("http://www.graemefife.com/")[1].split("/")[0].split("#")[0];
var genre = document.location.href.split("http://www.graemefife.com/")[1].split("/")[1];

function _GET(variable){
	var querys = document.location.href.split("?")[1].split("&");
	for (var i=0;i<querys.length;i++){
		if(querys[i].split("=")[0] == variable){
			return querys[i].split("=")[1].split('#')[0];
			//return querys[i].split("=")[1];
		}
	}
}

function setMiniHeight() {
	var contentElement = document.getElementById('page');
	var contentHeight = contentElement.offsetHeight;
	
	if(contentHeight < 290){
		contentElement.style.height = "305px";
	}
}

function applyShowHideTo(navigater, container){
	//alert('sss');
	var onload = document.location.href.split("#")[1];

	var navigaterDiv	= document.getElementById(navigater);	
	var navigaterDivA	= navigaterDiv.getElementsByTagName('a');
	var containerDiv	= document.getElementById(container);
	var containerDivLi	= containerDiv.getElementsByTagName('li');
		
	applyScriptToLinks();
	showInfo(onload);
	
	function applyScriptToLinks(){
		for(var i=0;i<navigaterDivA.length;i++){
			if(navigaterDivA[i].className == "showhidelink"){
				navigaterDivA[i].onclick = function(){
					activate(this);
					var str = this.href.toString();
					showInfo( str.split('#')[1] );
				}
			}
		}
	}
	
	function activate(thisOne){
		//alert(thisOne);
		for(var i=0;i<navigaterDivA.length;i++){
			if(navigaterDivA[i].className == "showhidelink"){
				navigaterDivA[i].style.color = "#444";
				var str = navigaterDivA[i].toString();
				if(str.split('#')[1] == thisOne){
					navigaterDivA[i].style.color = "#60afc2";
				}
			}
		}
	}
	
	function showInfo( id ){
		activate( id );
		containerDiv.style.display="block";
		for(var i=0;i<containerDivLi.length;i++){
			var thetag		= containerDivLi[i];
			var thetagid	= containerDivLi[i].id;
			
			if( thetagid == id ){
				thetag.style.display = "inline";
			}
			else if( thetagid ){
				thetag.style.display = "none";
				thetag.style.height = "0";
			}
		}
	}
}
function externallinks(){
	links = document.getElementsByTagName('a');
	for(var i=0;i<links.length;i++){
		if(links[i].className=="external"){
			links[i].onclick = function(){
				var url    = this.href;
                var left   = 0;
                var top    = 0;
                var width  = 440;
                var height = 240;
                left = (screen.width-width)/2;
                top = (screen.height-height)/2;

                newwindow = window.open( url, 'popup','width='+width+',height='+height+',left='+left+',top='+top+',menubar=no,location=no,resizable=no,scrollbars=no,status=no' );
                if ( window.focus ) {
                    newwindow.focus();
                }
                return false;
			}
		}
	}
}

function antispam(name, domain){
	//alert(name+'@'+domain);
	document.location = "mailto:" + name + "@" + domain;
}

window.onload = function() {
	if(page != "contact"){
		setMiniHeight();
	}else{
		document.getElementById('page').style.background = "transparent";
	}
	externallinks();
	if(page == "biography"){
		applyShowHideTo("content", "footer");	
	}
	if(genre){
		applyShowHideTo("work_list", "work_item");
	}
}


