
var location_dialog=0;
var current_location=null;
var current_location_cookie="current_location";

window.onload = function() {

  	init();

  	var cookie=get_cookie(current_location_cookie);

  	if (cookie!=null)
	{
		current_location=get_cookie(current_location_cookie).split(",");		
		set_location(current_location[0],current_location[1]);
	}
	else
	{
		set_location('East Village','10009');
	}
	


}

addEventListener("orientationChange", function() {setTimeout(orient,0); setTimeout(scrollTo, 100, 0, 1);}, false);
addEventListener("orientationchange", function() {setTimeout(orient,0); setTimeout(scrollTo, 100, 0, 1);}, false);

function orient()
{

	document.body.setAttribute("class",(window.orientation==0 || window.orientation==180)?"o_v":"o_h");		
}
function init()
{
	orient();
	setTimeout(function(){window.scrollTo(0, 1);}, 200);	
	
}
function $(id)
{
	return document.getElementById(id);
}
setInterval(orient, 300);
setTimeout(function(){window.scrollTo(0, 1);}, 100);


function set_location(name,zip)
{
	set_cookie(current_location_cookie,name+","+zip);
	current_location=new Array();
	current_location[0]=name;
	current_location[1]=zip;
	if($('name')!=null)
	{
		$('name').innerHTML=name;
		$('zip').innerHTML=zip;	
	}
	if($('zip11215')!=null)
	{
		if(current_location[1]==11215)
		{
			$('zip11215').style.visibility="visible";	
			$('zip11215').style.display = 'block';		
		}
		else
		{
			$('zip10009').style.visibility="visible";	
			$('zip10009').style.display = 'block';	
		
		}	
	}	
}

function toggle_location_dialog()
{
	if(location_dialog==0)
	{
		window.scrollTo(0, 1);
		location_dialog=1;
		$('location_dialog').style.visibility="visible";	
		$('location_dialog').style.display = 'block';		
	}
	else if(location_dialog==1)
	{
		window.scrollTo(0, 1);
		location_dialog=0;
		$('location_dialog').style.visibility="hidden";	
		$('location_dialog').style.display = 'none';		
	}
	
}
function set_cookie (name, value, lifespan, access_path) {
var cookietext = name + "=" + escape(value) 
if (lifespan != null) { 
  var today=new Date() 
  var expiredate = new Date() 
  expiredate.setTime(today.getTime() + lifespan);
  cookietext += "; expires=" + expiredate.toGMTString()
}
if (access_path != null) { 
  cookietext += "; PATH="+access_path 
}
document.cookie = cookietext 
return null 
}





function get_cookie(Name) {
var search = Name + "=" 
var CookieString = document.cookie 
var result = null 
if (CookieString.length > 0) { 
    offset = CookieString.indexOf(search) 
    if (offset != -1) { 
        offset += search.length 
        end = CookieString.indexOf(";", offset) 
        if (end == -1) {
           end = CookieString.length }
        result = unescape(CookieString.substring(offset, end)) 
   } 
}
return result 
}


