var california_widget_is_enabled = false;
var big_text = '%%City_Name%% Plumbers';
var small_text = '<b>Green</b><i>Plumbers</i> is bringing no-fee workshops near you, <a href="http://www.greenplumbersusa.com/spring-series" target="_blank" alt="Click to register">register now</a>!';

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function setCookie (name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}


function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
		arrayPageSize = new Array(w,h) 
		return arrayPageSize;
}
function getLeftPos()
{
	var page_size = getPageSize();
	return (page_size[0]-$("#splash1").width())/2;
	
}
$(document).ready(function(){
  if(california_widget_is_enabled==false)
  return this;
  
	var cooks = parseInt(getCookie("splash1_showed"));
  if(!cooks)
   cooks = 0;
  if(cooks<3)
	//if(true || cooks<3)
	{
		
	$.get("/california_widget/plumbers_california.php",function(data){

		if(data)
		{

			replaced_big_text = big_text.replace('%%City_Name%%',data);
			$("body").append('<div id="splash1"><div id="close_splash1"></div><div class="splash1_big"> '+replaced_big_text+'</div>		<div class="splash1_small"> '+small_text+'</div>		</div>');
			$("#splash1").animate({"left": getLeftPos()}, 1000 );
			$("#close_splash1").click(function(){
				$("#splash1").animate({"left": '100%'}, 1000 );
			});
		}
	});
	setCookie("splash1_showed",parseInt(cooks)+1);
	}
});
