/********************/
/*   Popup Config  */
/********************/
	
//Note: You must id your div that you want popped on the page "popPanel"
//eg: <div id="popPanel">
//this div must be located somewhere in the DOM of the page you want it to show on

//this sets the width of the popUp in pixels
var popWidth = "170px";

//set this to true if you want it to fade, or false if not
var doFade = true;
//set this to a value in seconds of how fast you want the fade to happen
var fadeDur = 0.5;

//set this to true if you want it to slide, or false if not
var doSlide = false;
//set this to a value in seconds of how fast you want the slide to happen
var slideDur = 0.5;

//set this to the delay in miliseconds you want before the div pops
//note: this is not 100% accurate just based on how a page loads and when it's
//officially "done" loading. Play with it to get it where you want per page
var popTime = 25;

/********************/
/*   Cookie Config  */
/********************/

//set this to the unique name of the cookie you want it to look at
//the cookie set "site wide", however you can use different cookies
//on differnt pages for different offers.
var cookieName = 'homePageOfferCount';

//number of days you want the cookie to stay on the users browser.
//each time they come to your site, the value gets reset, so they will
//only see the popup again if they do not come back to your site within
//the timeframe you set here
var expDays = 90;

//uncomment this line, load the page once, and then recomment it if you want to easily delete the cookie that gets set.
//this is just for testing, so make sure you comment it back out when you're done otherwise the page will
//pop the div every singe time it gets hit!
//DeleteCookie(cookieName); <-- this must be commented out when you go live <--

/***** End Config ****/

YAHOO.namespace("chesshouse.container");
YAHOO.chesshouse.container.init = function() {
    if (!checkCount()) {
    //if (1==1) {
        if (doFade == true && doSlide == true) {
            YAHOO.chesshouse.container.popPanel = new YAHOO.widget.Panel("popPanel", { 
            fixedcenter : true,
            width:popWidth, 
            visible:false, 
            constraintoviewport:true, 
            modal:true, 
            close:true, 
            effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:fadeDur}, 
            {effect:YAHOO.widget.ContainerEffect.SLIDE,duration:slideDur}] 
            } );
        }else if (doFade == true && doSlide == false) {
            YAHOO.chesshouse.container.popPanel = new YAHOO.widget.Panel("popPanel", { 
            fixedcenter : true,
            width:popWidth, 
            visible:false, 
            constraintoviewport:true, 
            modal:true, 
            close:true, 
            effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}] 
            } );
        }else if (doFade == false && doSlide == true) {
            YAHOO.chesshouse.container.popPanel = new YAHOO.widget.Panel("popPanel", { 
            fixedcenter : true,
            width:popWidth, 
            visible:false, 
            constraintoviewport:true, 
            modal:true, 
            close:true, 
            effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}] 
            } );
        }else{
            YAHOO.chesshouse.container.popPanel = new YAHOO.widget.Panel("popPanel", { 
            fixedcenter : true,
            width:popWidth, 
            visible:false, 
            constraintoviewport:true, 
            modal:true, 
            close:true
            } );
        }
        YAHOO.chesshouse.container.popPanel.render();
        window.setTimeout(function() { 
            YAHOO.chesshouse.container.popPanel.show();
        },popTime); 
    }else{
        YAHOO.chesshouse.container.popPanel = new YAHOO.widget.Panel("popPanel", { 
        visible:false																																			
        });
    }
}

YAHOO.util.Event.addListener(window, "load", YAHOO.chesshouse.container.init);

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
	var count = GetCookie(cookieName);
	if(count == null) {
		SetCookie(cookieName,'1');
		return 1;
	}else {
		var newcount = parseInt(count) + 1;
		DeleteCookie(cookieName);
		SetCookie(cookieName,newcount,exp);
		return count;
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	
	return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
	var count = GetCookie(cookieName);
	if (count == null) {
		count=1;
		SetCookie(cookieName, count, exp, '/');
		return false;
	}	else {
		count++;
		SetCookie(cookieName, count, exp, '/');
		return true;
	}
}
