
// jQuery Ready function
$(document).ready(function(){
  //alert("DOM is ready");

	// Preload Tab Hover and On images
	$.preloadCssImages();

	// Submit States form when changed
	$('#stateform_states').change(function() {
		window.location = "#gbl_state_" + this.value;
	});
	
	// Add 'Back to Top' links
	$('<div class="gbl_liststruct_foot"><a href="#gbl_top">Back to Top</a></div>').insertAfter('.gbl_state .gbl_liststruct_body');
	$('<a id="gbl_top" name="gbl_top"></a>').prependTo('body');
	
	// Replace email addreses with correct mailto links
	$('.gbl_email').mailto();
	
	
	// Load the Interstitial the first time anyone visits the site
	/*var viewedInter = readCookie('shotBongViewedInters'); // read in Interstitial cookie, otherwise create it and fwd to Interstitial page if it doesn't exist
	if ( !viewedInter ) {
		createCookie('shotBongViewedInters','True');
		window.location.href  = 'http://www.shotbong.com/interstitial.php';
	}*/
	


}); // End of jQuery Ready function





// Functions

jQuery.fn.mailto = function() {
	return this.each(function(){
		var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
		$(this).before('<a href="mailto:' + email + '" rel="nofollow" title="Email ' + email + '">' + email + '</a>').remove();
	});
};



// Start Cookie Functions
function createCookie(name,value,days) {
	var expires;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else{ 
		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);
}

function testCookie() {
  createCookie("testCookie","hi");
  var myCookie = readCookie("testCookie");
  if ((myCookie==null) || (myCookie=="")) { return false; } else { return true; }
}
// End Cookie Functions


