$(document).ready(function(){

/* ---- 
All links on page open in new window if not internal
------*/
$('a').live('mouseup', function(){
		var fullUrl = $(this).attr('href');
		var splitUrl = fullUrl.split("/");
		
		if((splitUrl[2] != 'www.windtunnelmapsite.com') && (splitUrl[2] != 'windtunnelmapsite.com') && (splitUrl[2] != undefined)){
				$(this).attr("target","_blank");
				//If listview page
				pageUrl = window.location.href;
				thePage = pageUrl.split('/');
				theLength = thePage.length;
				if(thePage[theLength-1] == 'list_view.php?all=list'){
					window.open(fullUrl);
				}
		}	
	});

	
/*-----
Cookie script modified off of one found at 
http://scripts.franciscocharrua.com/javascript-cookies.php
-----*/

function setCookie(name, value){
  if(name != ''){document.cookie = name + '=' + value;}
}
function getCookie(name){
 //Without this, it will return the first value 
 //in document.cookie when name is the empty string.
 if(name == '')
   return('');
         
  name_index = document.cookie.indexOf(name + '=');
         
  if(name_index == -1)
  return('');
         
  cookie_value =  document.cookie.substr(name_index + name.length + 1, document.cookie.length);
         
 //All cookie name-value pairs end with a semi-colon, except the last one.
  end_of_cookie = cookie_value.indexOf(';');
  if(end_of_cookie != -1)
     cookie_value = cookie_value.substr(0, end_of_cookie);

  //Restores all the blank spaces.
  space = cookie_value.indexOf('+');
  while(space != -1)
   { 
    cookie_value = cookie_value.substr(0, space) + ' ' + 
    cookie_value.substr(space + 1, cookie_value.length);
							 
    space = cookie_value.indexOf('+');
   }

   return(cookie_value);
}   
function clearCookie(name){                  
  expires = new Date();
  expires.setYear(expires.getYear() - 1);

  document.cookie = name + '=null' + '; expires=' + expires; 		 
}


/*---------
  Popup contact form
---------*/		
$('#emailcontact').live("click",function(){
	$('#contactbox').load('contact_form.php').fadeIn('slow');
});


/*---------
 List view toggle
---------*/	
//Show more info
$('div.listView a.expand').click(function(){
	$(this).next('.listViewDesc').toggle('slow');
	return false;
});

//Toggle each category
$('.listToggle').click(function(){
	$(this).next('div').children().slideToggle('slow');
});



/*
New Category Info Popup

$('.clickInfo').click(function(){
			switch ($(this).attr("title")){
				case "1":
					loadPage = 'info_food.html';
				break;
				case "2":
					loadPage = 'info_career.html';
				break;
				case "3":
					loadPage = 'info_community_service.html';
				break;
				default:
					loadPage = 'info_default.html';
				break;
			}
	$('#contactbox').load(loadPage).fadeIn('slow');
});
*/

//Get the current event type so that only that page's tips are closed
currentEvent = getCookie('eventCookie');
//Get the current cookie value

curr_page = window.location.href;
page_param = curr_page.split("?");
params = '';
if(page_param[1]){
	params = page_param[1].split("&");
}
//When the eventType is set in the url, it redirects to the map page and sets info=show as a param
if(params != ''){
	if(params[0] == 'info=show'){
		if(currentEvent){
			//window pops up
					switch (currentEvent){
						case "1":
							loadPage = 'info_food.html';
						break;
						case "2":
							loadPage = 'info_career.html';
						break;
						case "3":
							loadPage = 'info_community_service.html';
						break;
						default:
							loadPage = 'info_default.html';
						break;
					}
			$('#contactbox').load(loadPage).fadeIn('slow');
		}
	}
}




$('#closePop').live("click",function(){
	$('#contactbox').hide();
});


});


