
function Dimensions()
{
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	return new Array(frameWidth,frameHeight);
}
// Object.prototype.setOpacity = function(value){//opacity is from 1 - 10
//  this.style.opacity = value/10;
//  this.style.filter = 'alpha(opacity=' + value*10 + ')';
// }jquery doesn not support - http://dev.jquery.com/ticket/4695


var layer;
var opacity = 10;
var timer;
function FadeOut(){
    if(layer!=undefined){
        if(opacity==10){
    		clearInterval(timer);
    		timer = setInterval(FadeOut, 40);
    	}else if(opacity==0){
    		layer.style.top="-1000px";
    		clearInterval(timer);
    	}
    	opacity--;
    	layer.style.opacity = opacity/10;
    	layer.style.filter = 'alpha(opacity=' + opacity*10 + ')';
    }
}

function AddNew(){
	layer = document.createElement("div");
	var img = document.createElement("img");
	var upto = Math.floor(Math.random()*26);
	img.src = "images/pops/New_"+upto+".gif";
	dims = Dimensions();
	lHeight = 545;
	lWidth = 790;
	layer.style.position = "absolute";
	layer.style.zIndex = 500;
	layer.style.top =  Math.floor(Math.random()*lHeight)+((dims[1]-lHeight)/2)+"px";
	layer.style.left =  Math.floor(Math.random()*lWidth)+((dims[0]-lWidth)/2)+"px";
	layer.appendChild(img);
	layer = document.body.appendChild(layer);
	timer = setInterval(FadeOut, 1000);
	//layer.setOpacity(5);
}



function OneInSome(){
	num = Math.floor(Math.random()*9);
	if(num==1||(typeof alwaysNew)!='undefined'){
		AddNew();
	}else{
		//AddNew();
	}
	
}


var ztrack = 2;
function AddSubscribe(press){
	dims = Dimensions();
	lHeight = 545;
	lWidth = 790;
	if(press==true){
	    box = document.getElementById("press");
	    
	}else{
	    box = document.getElementById("subscribe");
    	var upto = Math.ceil(Math.random()*8);
    	box.style.backgroundImage = "url(images/subscribes/Subscribe_"+upto+".gif)";
	}
	box.style.top =  Math.floor(Math.random()*(lHeight-100))+((dims[1]-lHeight)/2)+"px";
	box.style.left =  Math.floor(Math.random()*(lWidth-400))+((dims[0]-lWidth)/2)+200+"px";
	ztrack++;
	box.style.zIndex =  ztrack;
	//layer.setOpacity(5);
}



function closeSubscribe(){
	subscribe = document.getElementById("subscribe");
	subscribe.style.left = "-1000em";
}

function closePress(){
	press = document.getElementById("press");
	press.style.left = "-1000em";
}
function sendEmail(){
	email = document.forms[0].email.value;
	if(email!=""){
		sendRequest("save_email.php?email="+email, handleRequest);
	}
}

function sendPassword(){
	password = document.forms[1].password.value;
	if(password!=""){
	    alert(password);
		sendRequest("check_press.php?password="+password, handlePress);
	}
}

function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
    // req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}
function handleRequest(req){
	inputBox = document.getElementById("subscribeForm");
	document.getElementById("subscribe").removeChild(inputBox);
	document.getElementById("subscribe_text").firstChild.nodeValue = "Thank you!"

}

function handlePress(req){
    alert(req);
}

//sendRequest('send_email.php?email=kip@friendchip.com',handleRequest);
function Start(){
	if((typeof showSubscribe)!='undefined'){
		AddSubscribe();
	}
	
	OneInSome();
}

window.onload = Start;

