/*
	Northfire - Copyright 2006
	Created By: Matthew Simpson (graveyardpc@gmail.com)
	"main.js"
*/

var Body={
	load:function(sID){
		Menu.init();
		Contact.init();
		switch(sID){
			case "front":
				Screenshot.init();
				break;
			default:
				break;
		}
	}
};

var Menu={
	init:function(){
		vInc=1;
		while(oBut=document.getElementById("menu_"+vInc)){
			oBut.style.backgroundColor="#101010";
			oBut.onmouseover=Menu.over;
			oBut.onmouseout=Menu.out;
			vInc++;
		}
	},
	over:function(){
		this.style.backgroundColor="#242424";
	},

	out:function(){
		this.style.backgroundColor="#101010";
	}
};

var Contact={
	init:function(){
		Contact.oSend=document.getElementById("contact_send");
		Contact.oSend.style.backgroundColor="#1A1A1A";
		Contact.oSend.onmouseover=Contact.over;
		Contact.oSend.onmouseout=Contact.out;
	},
	over:function(){
		this.style.backgroundColor="#5A0000";
	},

	out:function(){
		this.style.backgroundColor="#1A1A1A";
	},
	send:function(vIP){
		sName=document.getElementById("contact_name").value;
		sEmail=document.getElementById("contact_email").value;
		sComment=document.getElementById("contact_comment").value;

		if(sName!="" && sEmail!="" && sComment!=""){
			sVars="name="+sName+"&email="+sEmail+"&comment="+sComment+"&ip="+vIP;
			XMLHTTP.request("mail.php",sVars);
		}

		document.getElementById("contact_name").value="";
		document.getElementById("contact_email").value="";
		document.getElementById("contact_comment").value="";
	}
};

var Screenshot={
	init:function(){
		Screenshot.oSSImg=document.getElementById("ss_img");
		Screenshot.oSSImg.onclick=function(){Screenshot.click();};
		Screenshot.oSSBox=document.getElementById("ss_box");
		Screenshot.load(true);
	},
	over:function(){
		this.style.color="#555555";
	},

	out:function(){
		this.style.color="#CCCCCC";
	},
	click:function(){
		if(Screenshot.vNum){
			location.href=Screenshot.sSrc;
		}
	},
	clear:function(){
		vInc=1;
		while(oBut=document.getElementById("ss_but"+vInc)){
			if(Screenshot.vNum==vInc){
				oBut.style.backgroundColor="#5A0000";
				oBut.onmouseover=function(){};
				oBut.onmouseout=function(){};
			}else{
				oBut.style.backgroundColor="#1A1A1A";
				oBut.onmouseover=Screenshot.over;
				oBut.onmouseout=Screenshot.out;
			}
			oBut.style.color="#CCCCCC";
			oBut.onclick=Screenshot.load;
			vInc++;
		}
	},
	load:function(bInit){
		Screenshot.oSSBox.style.backgroundImage="url('images/loading.gif')";
		Screenshot.vNum=(bInit==true)?1:this.innerHTML;
		Screenshot.sSrc="images/screen"+Screenshot.vNum+".png";
		Screenshot.oSSImg.style.display="none";
		
		Screenshot.clear();
		XMLHTTP.request(Screenshot.sSrc,"null",Screenshot.done);
	},
	done:function(){
		Screenshot.oSSImg.style.backgroundImage="url('"+Screenshot.sSrc+"')";
		Screenshot.oSSImg.style.display="block";
	}
};

var XMLHTTP={
	request:function(sURL,sVars,fnRet,vTout,fnTout){
		clearTimeout(XMLHTTP.Timer);
		var oHTTP;
  		try{oHTTP=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){
		try{oHTTP=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){
		try{oHTTP=new XMLHttpRequest();}catch(e){oHTTP=false;}}}
	
		if(oHTTP){
      			oHTTP.onreadystatechange=function(){
        			if (oHTTP.readyState==4){
					if(fnRet){fnRet(oHTTP.responseText);}
        			}
			};
			XMLHTTP.timeout=function(){
				if(oHTTP.readyState!=4){
					oHTTP.abort();
					if(fnTout){fnTout();}
				}
			};
        		oHTTP.open("POST",sURL,true);
        		oHTTP.setRequestHeader("Method","POST "+sURL+" HTTP/1.1");
        		oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			oHTTP.send(sVars);
			XMLHTTP.Timer=(vTout)?setTimeout("XMLHTTP.timeout();",vTout):false;
		}
	}
};
