/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

        Project Vote Smart
        Utilities
        
        (c) Copyright 2008 Project Vote Smart
        
        Created 2008-11-09 by mike
        
        Last Modified:
        
        

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

/**
 * Cookie handling
 */
function createCookie(name,value,hours) {
	
	if (hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
	
}

function readCookie(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;
	
}

function eraseCookie(name) {
	
	createCookie(name,"",-1);
	
}


$(document).ready(function() {

        /**
         * Hide marked elements when mousover the menu
         * 
         * #nav_main is new css driven, .menu is for old js style menu
         */
        $("#nav_main ul li, .menu").mouseover(
                function () {
                        $(".hidefrommenu").css({
                                visibility: "hidden"
                        });
                }
        ).mouseout(
                function () {
                        $(".hidefrommenu").css({
                                visibility: "visible"
                        });
                }
        );
        
        /**
         * Fundraiser float box
         **/
         
        if ($('#fundraiserfloat').length > 0) {

                if (readCookie('pvsfundraiser') != '1') {
                	
                	// Display only once per week
                	
	                $('#fundraiserfloat').css( {
	                	display: "block"
	                });
	                
	                createCookie('pvsfundraiser', '1', '1'); // Set and expire cookie in 1 hour
	                
                }
        }
        
        if ($('#fundraisersplash').length > 0) {
        
                if (readCookie('pvsfundraiser') != '1') {
        
                        tb_show("Help Us If You Can", "#TB_inline?height=328&width=422&inlineId=fundraisersplash", "one");
                        
                        createCookie('pvsfundraiser', '1', '2'); // Set and expire cookie in 1 hour
                        
                }
                
        }
});
