var disclaimer;
var imageDir = "/wp-content/themes/saatchila/images/"

if(typeof $ != "function"){
	alert("You need to include jquery when using disclaimer.js.");
}

function openDisclaimer()
{
	if(disclaimer == null){
		disclaimer = new Disclaimer();
	}
}

var WindowProperties = {
pageSize:getPageSize
};
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	var obj = {width:pageWidth,height:pageHeight,scrollX:xScroll,scrollY:yScroll,windowWidth:windowWidth,windowHeight:windowHeight};
	//arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return obj;
}


Disclaimer = function (url){
	this.div;
	this.bg;
	this.show(url);
}

/*Disclaimer.prototype.show = function(url){
	$("body").append("<div id=\"disclaimer\" style=\"position: absolute; top: 200px; left: 50%; width: 500px; margin-left: -250px; z-index: 1000001;\"><div class=\"disclaimer-box-content\"><div class=\"disclaimer-overlay-close\" id=\"close-button\"><a class=\"squarex\" href=\"javascript:void(0);\"/></div><div class=\"clear\"/>Feel free to check out the examples of our work contained in our Web site. It's here for you to enjoy. But it needs to stay here. Seriously. Downloading or reproducing this material in any form is a violation of the copyright. Thanks for your understanding.<br /><br /><input name=\"accept\" type=\"button\" value=\"Accept\" id=\"accept-button\"/><input name=\"decline\" type=\"button\" value=\"Decline\" id=\"decline-button\" /><br /><br />For complete terms and conditions, please click here.</div></div>");
	this.createBackground();
	$(window).resize(this.resize);
	this.div = $("#disclaimer");
	$("#close-button").bind("click",{scope: this},this.close);
	$("#accept-button").bind("click",{scope: this},this.accept);
	$("#decline-button").bind("click",{scope: this},this.decline);
}*/


/*Disclaimer.prototype.show = function(){
	str = "<div id=\"disclaimer\" style=\"position: absolute; top: 200px; left: 50%; width: 500px; margin-left: -250px; z-index: 1000001;\">";
	str += "<div class=\"disclaimer-box-content\">";
	str += "<div class=\"disclaimer-body\">";
	str += "<div>Feel free to check out the examples of our work contained in our Web site. It&lsquo;s here for you to enjoy. But it needs to stay here. Seriously. Downloading or reproducing this material in any form is a violation of the copyright. Thanks for your understanding.</div>";
	str += "<div class=\"disclaimer-buttons\">";
	str += "<div class=\"disclaimer-accept\">";
	str += "<input id=\"accept-button\" name=\"accept\" type=\"image\" value=\"Accept\" src=\""+ imageDir + "disclaimer-accept.gif\" hspace=\"0\" vspace=\"0\" border=\"0\" />";
	str += "</div>";
	str += "<div class=\"disclaimer-reject\">";
	str += "<input id=\"decline-button\" name=\"decline\" type=\"image\" value=\"Accept\" src=\"" + imageDir + "disclaimer-reject.gif\" align=\"right\" hspace=\"0\" vspace=\"0\" border=\"0\" />";
	str += "</div>";
	str += "</div>";
	str += "<div class=\"disclaimer-conditions\">For complete terms and conditions, please <a href=\"/sslav2/terms-conditions/\" target=\"_blank\">click here</a>.</div>";
	str += "</div></div></div>";
	$("body").append(str);
	this.createBackground();
	$(window).resize(this.resize);
	this.div = $("#disclaimer");
	$("#close-button").bind("click",{scope: this},this.close);
	$("#accept-button").bind("click",{scope: this},this.accept);
	$("#decline-button").bind("click",{scope: this},this.decline);
}*/

Disclaimer.prototype.show = function(){
	str = "<div id=\"disclaimer\" style=\"position: absolute; top: 200px; left: 50%; width: 500px; margin-left: -250px; z-index: 1000001;\">";
	str += "<div class=\"disclaimer-box-content\">";
	str += "<div class=\"disclaimer-body\">";
	str += "<div>Feel free to check out the examples of our work contained in our Web site. It&lsquo;s here for you to enjoy. But it needs to stay here. Seriously. Downloading or reproducing this material in any form is a violation of the copyright. Thanks for your understanding.</div>";
	str += "<div class=\"disclaimer-buttons\">";
	str += "<div class=\"disclaimer-accept\">";
	str += "<input id=\"accept-button\" name=\"accept\" type=\"image\" value=\"Accept\" src=\""+ imageDir + "disclaimer-accept.gif\" hspace=\"0\" vspace=\"0\" border=\"0\" />";
	str += "</div>";
	str += "<div class=\"disclaimer-reject\">";
	str += "<input id=\"decline-button\" name=\"decline\" type=\"image\" value=\"Accept\" src=\"" + imageDir + "disclaimer-reject.gif\" align=\"right\" hspace=\"0\" vspace=\"0\" border=\"0\" />";
	str += "</div>";
	str += "</div>";
	str += "</div></div></div>";
	$("body").append(str);
	this.createBackground();
	$(window).resize(this.resize);
	this.div = $("#disclaimer");
	$("#close-button").bind("click",{scope: this},this.close);
	$("#accept-button").bind("click",{scope: this},this.accept);
	$("#decline-button").bind("click",{scope: this},this.decline);
}

Disclaimer.prototype.accept = function(e){
	e.data.scope.setCookie("sscopywarning", '1', 30);
	e.data.scope.removeDisclaimer();
}

Disclaimer.prototype.decline = function(e){
	window.location = document.referrer;
}


Disclaimer.prototype.resize = function(){
	var w,h;
	var page = WindowProperties.pageSize();
	w = page.width;
	h = page.height;
	if(page.windowHeight < h){
		w -= 18;
	}
	var o = $("#modal-overlay"); 
	o.width(w);
	o.height(h);
}

Disclaimer.prototype.createBackground = function(){
	var w,h;
	var page = WindowProperties.pageSize();
	w = page.width;
	h = page.height + 400;
	if(page.windowHeight < h){
		w -= 18;
	}
	$("body").append("<div style=\"z-index: 1000000; width: " + w + "px; height: " + h + "px;\" class=\"modal\" id=\"modal-overlay\" ></div>");
	this.bg = $("#modal-overlay");
}

Disclaimer.prototype.close = function(e){
	e.data.scope.removeDisclaimer();
}

Disclaimer.prototype.removeDisclaimer = function(){
	this.div.remove();
	this.bg.remove();
	disclaimer = null;
}

Disclaimer.prototype.setCookie = function($name,$value,$expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+$expiredays);
	document.cookie=$name + "=" + $value + ";expires=" + exdate.toGMTString() + ";path=/";
}