window.addEvent('domready', function() {	
	popup.testCookie();
	popup.events();
	
	if(Browser.Engine.name == 'trident' && Browser.Engine.version == 4){
		$('shade').setStyles({height: popup.getPageSize()[1], width: popup.getPageSize()[0]})
	}
});

popup = {
	testCookie: function ()
	{
		
		if(Cookie.read('skippy') != 'true'){
			setTimeout("popup.show()", 500);
		}
	},
	show: function ()
	{
		$('popup').setStyles({display: 'block', opacity: 0});
		$('shade').setStyles({display: 'block', opacity: 0});
		
		$('popup').tween('opacity', 1);
		//$('popup').tween('top', [50, 100]);
		$('shade').tween('opacity', .9);
	},
	hide: function ()
	{
		var popFX = new Fx.Morph('popup', {duration: 500, wait: false, onComplete: function(){$("popup").style.display = "none";}});
		popFX.start({'opacity': 0});
		
		var shadeFX = new Fx.Morph('shade', {duration: 500, wait: false, onComplete: function(){$("shade").style.display = "none";}});
		shadeFX.start({'opacity': 0});
		
	},
	events: function ()
	{
		$('tosite').addEvents({
			'click': function(){
				popup.checkCheckbox();
				popup.hide();
				return false;
			}
		})
		$('learnmore').addEvents({
			'click': function(){
				popup.checkCheckbox();
				window.location = "/contact/index.php?q=greentax"
				return false;
			}
		})
	},
	checkCheckbox: function()
	{
		if($('skippy').checked){
			var skip = Cookie.write('skippy', 'true', {duration: 30});
		}
	},
	readCookie: function (name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') { 
				c = c.substring(1,c.length);
			}
			if (c.indexOf(nameEQ) == 0) {
				return c.substring(nameEQ.length,c.length);
			}
		}
		return null;
	},
	//
	// getPageSize()
	// Returns array with page width, height and window width, height
	// Core code from - quirksmode.org
	// Edit for Firefox by pHaez
	//
	getPageSize: function()
	{

		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;
		}


		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}

	
	
}


