function showChatBox(){
	$('#chatBox').animate({top:$(window).scrollTop() }, "slow");
	$('#chatBox').fadeTo("slow", 1);
}

var COOKIE_NAME = 'buck_closePopup';


// check cookie
function checkCookie() {		
	if ($.cookie(COOKIE_NAME) != null){
		// user has elected to close popup box; hide for 2hrs
	}else{
		// show chatbox
		setTimeout ("showChatBox()", 60000);//2 mins
		//setTimeout ("showChatBox()", 10000); //10 secs
	}
};


// set cookie by num of days
function setCookie() {
	var date = new Date();
	date.setTime(date.getTime() + (1 * 2 * 60 * 60 * 1000));	// (now) + DAYS, HRS, MINS, SECS, MSECS
	$.cookie(COOKIE_NAME, date, { expires: date });
	//alert('Cookie saved \n Expires: '+date);
};


function closeChatBox(){
	setCookie();
	$('#chatBox').animate({ opacity:0 }, "slow");
}	


var GblTop;
 
function GetVertOffset (srchStr){
    GblTop = $(srchStr).offset().top - parseFloat($(srchStr).css('marginTop').replace(/auto/, 0));
}


$(document).ready(function(){
	
	$("#chatBox").css("opacity","0");
	
	checkCookie();
	
	GetVertOffset ('#chatBox');
	
	$(window).scroll(function(){
		$('#chatBox').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 500});
		
		/*
        var y = $(window).scrollTop();
		if (y >= GblTop){
            $('#chatBox').addClass('fixed');
        }
        else{
            $('#chatBox').removeClass('fixed');
        }
		*/
	});
	
	
	$('#chatClose').click(function(){
		closeChatBox();
	});
	
});



