// JavaScript Document

var hover_visitors = false;
var hover_residents = false;
var hover_planners = false;
var hover_media = false;
var hover_members = false;
var hover_button_hotel = false;
var hover_button_social = false;
var activeField;
var activeDiv;
var todayInt;
var usingIE = false;

$(document).ready(function() {
						   
	if (navigator.appName == "Microsoft Internet Explorer") {
		usingIE = true;
		$('#browser').show(0);
		}
	
	// Menu Item Hover Functions
	$('#menuItem_visitors').hover(
		function() {
			if (!hover_visitors) {
				closeMenu("closeAll");
				hover_visitors = true;
				$('#menuDiv_visitors').show();
				$('#menuItem_visitors').addClass("menuItemHover");
				$('#menuItem_visitors').css("color","#1f5eff");
			}
		},
		function() {
			hover_visitors = false;
			setTimeout("closeMenu('visitors')",1000);
		}
	);

	$('#menuItem_residents').hover(
		function() {
			closeMenu("closeAll");
			hover_residents = true;
			$('#menuDiv_residents').show();
			$('#menuItem_residents').addClass("menuItemHover");
			$('#menuItem_residents').css("color","#1f5eff");
		},
		function() {
			hover_residents = false;
			setTimeout("closeMenu('residents')",1000);
		}
	);
	
	$('#menuItem_planners').hover(
		function() {
			closeMenu("closeAll");
			hover_planners = true;
			$('#menuDiv_planners').show();
			$('#menuItem_planners').addClass("menuItemHover");
			$('#menuItem_planners').css("color","#1f5eff");
		},
		function() {
			hover_planners = false;
			setTimeout("closeMenu('planners')",1000);
		}
	);

	$('#menuItem_media').hover(
		function() {
			closeMenu("closeAll");
			hover_media = true;
			$('#menuDiv_media').show();
			$('#menuItem_media').addClass("menuItemHover");
			$('#menuItem_media').css("color","#1f5eff");
		},
		function() {
			hover_media = false;
			setTimeout("closeMenu('media')",1000);
		}
	);
	
	$('#menuItem_members').hover(
		function() {
			closeMenu("closeAll");
			hover_members = true;
			$('#menuDiv_members').show();
			$('#menuItem_members').addClass("menuItemHover");
			$('#menuItem_members').css("color","#1f5eff");
		},
		function() {
			hover_members = false;
			setTimeout("closeMenu('members')",1000);
		}
	);
	
	// Menu Div Hover Functions
	$('#menuDiv_visitors').hover (
		function() { hover_visitors = true; },
		function() {
			hover_visitors = false;
			setTimeout("closeMenu('visitors')",1000);
		}
	);
	
	$('#menuDiv_residents').hover (
		function() { hover_residents = true; },
		function() {
			hover_residents = false;
			setTimeout("closeMenu('residents')",1000);
		}
	);
	
	$('#menuDiv_planners').hover (
		function() { hover_planners = true; },
		function() {
			hover_planners = false;
			setTimeout("closeMenu('planners')",1000);
		}
	);
	
	$('#menuDiv_media').hover (
		function() { hover_media = true; },
		function() {
			hover_media = false;
			setTimeout("closeMenu('media')",1000);
		}
	);
	
	$('#menuDiv_members').hover (
		function() { hover_members = true; },
		function() {
			hover_members = false;
			setTimeout("closeMenu('members')",1000);
		}
	);
	
	var todayDate = new Date();
	todayInt = mktime(0,0,0,todayDate.getMonth() + 1,todayDate.getDate(),todayDate.getFullYear());
	FB.init("c554b2f0f887292af7944addf511898d");
});

function closeMenu(menu) {
	if ((menu == "visitors" && !hover_visitors) || menu == "closeAll") {
		$('#menuDiv_visitors').hide();
		$('#menuItem_visitors').removeClass("menuItemHover");
		$('#menuItem_visitors').css("color","white");
		hover_visitors = false;
	}
	if ((menu == "residents" && !hover_residents) || menu == "closeAll") {
		$('#menuDiv_residents').hide();
		$('#menuItem_residents').removeClass("menuItemHover");
		$('#menuItem_residents').css("color","white");
		hover_residents = false;
	}
	if ((menu == "planners" && !hover_planners) || menu == "closeAll") {
		$('#menuDiv_planners').hide();
		$('#menuItem_planners').removeClass("menuItemHover");
		$('#menuItem_planners').css("color","white");
		hover_planners = false;
	}
	if ((menu == "media" && !hover_media) || menu == "closeAll") {
		$('#menuDiv_media').hide();
		$('#menuItem_media').removeClass("menuItemHover");
		$('#menuItem_media').css("color","white");
		hover_media = false;
	}
	if ((menu == "members" && !hover_members) || menu == "closeAll") {
		$('#menuDiv_members').hide();
		$('#menuItem_members').removeClass("menuItemHover");
		$('#menuItem_members').css("color","white");
		hover_members = false;
	}
}

function overlayControl(overlay) {
	$('#overlay_red').fadeOut(250);
	$('#overlay_blue').fadeOut(250);
	$('#overlay_yellow').fadeOut(250);
	$('#overlay_green').fadeOut(250);
	$('#overlay_' + overlay).fadeIn(250);
}

function showCal(field) {
	$('#calendar').show();
	if (activeField) activeField.style.backgroundColor = "white";
	field.style.backgroundColor = "#d33c33";
	activeField = field;
}

function hideCal(field, div) {
	$('#calendar').hide();
	document.getElementById(activeDiv).innerHTML = "";
	activeField.style.backgroundColor = "white";
}

function calClick(day) {
	var myDate = new Date(day * 1000);
	var text = "";
	if ((myDate.getMonth() + 1) < 10) text = "0";
	text += (myDate.getMonth() + 1) + "-";
	if (myDate.getDate() < 10) text += "0";
	text += myDate.getDate() + "-";
	text += myDate.getFullYear();
	activeField.value = text;
	hideCal();
	calClick2();
}

function processHotel() {
	$('#errorCheckin').hide();
	$('#errorCheckout').hide();
	$('#errorDates').hide();
	$('#hotelButton').html("<img src='/images/icons/ajax.gif' alt='Processing'><span class='ajaxMessage'>Processing...</span>");
	var error = false;
	var field = document.hotels.checkin.value;
	var checkinInt = mktime(0,0,0,field.substring(0,2),field.substring(3,5),field.substring(6));
	field = document.hotels.checkout.value;
	var checkoutInt = mktime(0,0,0,field.substring(0,2),field.substring(3,5),field.substring(6));
	if (checkinInt < todayInt) {
		error = true;
		$('#errorCheckin').show();
	}
	if (checkoutInt < todayInt) {
		error = true;
		$('#errorCheckout').show();
	}
	if (!error && checkoutInt < checkinInt) {
		error = true;
		$('#errorDates').show();
	}
	if (error) $('#hotelButton').html("<a class='button redButton' href='#' onclick='processHotel();return false;'>Look for rooms &raquo;</a>");
	else {
		var city = document.hotels.location.value;
		document.hotelSearchCriteriaForm.city.value = city;
		if (city == 'davenport' || city == 'bettendorf' || city == 'le claire') document.hotelSearchCriteriaForm.state.value="ia";
		else document.hotelSearchCriteriaForm.state.value="il";
		document.hotelSearchCriteriaForm.arrivalMonth.value = Number(document.hotels.checkin.value.substring(0,2));
		document.hotelSearchCriteriaForm.arrivalDay.value = Number(document.hotels.checkin.value.substring(3,5));
		document.hotelSearchCriteriaForm.departureMonth.value = Number(document.hotels.checkout.value.substring(0,2));
		document.hotelSearchCriteriaForm.departureDay.value = Number(document.hotels.checkout.value.substring(3,5));
		document.hotelSearchCriteriaForm.adults.value = document.hotels.adults.value;
		document.hotelSearchCriteriaForm.children.value = document.hotels.children.value;
		document.hotelSearchCriteriaForm.submit();
		var ajax = startAJAX();
		ajax.open("GET", "/include/ajax.php?hotel="+city, true);
		ajax.send(null);
	}
}

function processSearch() {
	$('#searchButton').html("<img src='/images/icons/ajax.gif' alt='Processing'><span class='ajaxMessage'>Processing...</span>");
	if (document.searchForm.type[1].checked) window.location = "page.php?page_id=93#search=" + document.searchForm.q.value;
	else if (document.searchForm.type[2].checked) window.location = "search.php?members&search=" + document.searchForm.q.value;
	else document.searchForm.submit();
}

function startAJAX() {
	var ajaxRequest;
	try { ajaxRequest = new XMLHttpRequest(); }
	catch (e) {
		try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e){
				alert("Sorry, AJAX could be initialized. Please try again.");
				return false;
			}
		}
	}
	return ajaxRequest;
}

function openBox(content) {
	$('#box_content').html("<img src='/images/icons/ajax.gif'> <b>Loading...</b>");
	$('#box_back').fadeIn(250);
	$('#box_back').stop();
	$('#box_back').fadeTo(250,0.5);
	$('#box').slideDown(250);
	var ajax = startAJAX();
	ajax.open("GET", "../include/boxOpener.php?file="+content, true);
	ajax.send(null);
	ajax.onreadystatechange = function() { if (ajax.readyState == 4) $('#box_content').html(ajax.responseText); }
}

function closeBox() {
	$('#box').slideUp(250);
	$('#box_back').fadeOut(250);
}

function openAd(id) {
	$('#box_content').html("<img src='/images/icons/ajax.gif'> <b>Loading...</b>");
	$('#box_back').fadeIn(250);
	$('#box_back').stop();
	$('#box_back').fadeTo(250,0.5);
	$('#box').slideDown(250);
	var ajax = startAJAX();
	ajax.open("GET", "../include/boxOpener.php?ad="+id, true);
	ajax.send(null);
	ajax.onreadystatechange = function() { if (ajax.readyState == 4) $('#box_content').html(ajax.responseText); }
}

function addToList(toAdd) {
	var ajax = startAJAX();
	ajax.open("GET", "/pages/36/ajax.php?add="+toAdd, true);
	ajax.send(null);
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4) {
			var spanID = "span"+toAdd;
			$("#"+spanID).fadeOut(500, function() {
				document.getElementById(spanID).innerHTML = "<img src='/pages/36/icon_check.gif'><span class='iconMsg iconGreen'>Added to your list</span><a class='view_list' href='?page_id=35'>View my list &raquo;</a>";
				$("#"+spanID).addClass('simplicio_success');
				$("#"+spanID).fadeIn(500);
			});
		}
	}
}

function fbs_click() {
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function mktime() {
	// http://kevin.vanzonneveld.net
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: baris ozdil
	// +      input by: gabriel paderni
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: FGFEmperor
	// +      input by: Yannoo
	// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +      input by: jakes
	// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfixed by: Marc Palau
	// +   improved by: Brett Zamir (http://brettz9.blogspot.com)

	var no=0, i = 0, ma=0, mb=0, d = new Date(), dn = new Date(), argv = arguments, argc = argv.length;

	var dateManip = {
		0: function(tt){ return d.setHours(tt); },
		1: function(tt){ return d.setMinutes(tt); },
		2: function(tt){ var set = d.setSeconds(tt); mb = d.getDate() - dn.getDate(); return set;},
		3: function(tt){ var set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - dn.getFullYear(); return set;},
		4: function(tt){ return d.setDate(tt+mb);},
		5: function(tt){
			if (tt >= 0 && tt <= 69) tt += 2000;
			else if (tt >= 70 && tt <= 100) tt += 1900;
			return d.setFullYear(tt+ma);
		}
		// 7th argument (for DST) is deprecated
	};

	for( i = 0; i < argc; i++ ){
		no = parseInt(argv[i]*1);
		if (isNaN(no)) return false;
        else {
			// arg is number, let's manipulate date object
			if(!dateManip[i](no)){
				// failed
				return false;
			}
		}
	}
	for (i = argc; i < 6; i++) {
		switch(i) {
			case 0:
				no = dn.getHours();
				break;
			case 1:
				no = dn.getMinutes();
				break;
			case 2:
				no = dn.getSeconds();
				break;
			case 3:
				no = dn.getMonth()+1;
				break;
			case 4:
				no = dn.getDate();
				break;
			case 5:
				no = dn.getFullYear();
				break;
		}
		dateManip[i](no);
	}
	
	return Math.floor(d.getTime()/1000);
}

function htmlspecialchars_decode(string, quote_style) {
	// Convert special HTML entities back to characters  
	// 
	// version: 906.401
	// discuss at: http://phpjs.org/functions/htmlspecialchars_decode
	// +   original by: Mirek Slugen
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfixed by: Mateusz "loonquawl" Zalega
	// +      input by: ReverseSyntax
	// +      input by: Slawomir Kaniecki
	// +      input by: Scott Cariss
	// +      input by: Francois
	// +   bugfixed by: Onno Marsman
	// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +    bugfixed by: Brett Zamir (http://brett-zamir.me)
	// -    depends on: get_html_translation_table
	// *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
	// *     returns 1: '<p>this -> &quot;</p>'
	var histogram = {}, symbol = '', tmp_str = '', entity = '';
	tmp_str = string.toString();
	
	if (false === (histogram = this.get_html_translation_table('HTML_SPECIALCHARS', quote_style))) return false;

	for (symbol in histogram) {
		entity = histogram[symbol];
		tmp_str = tmp_str.split(entity).join(symbol);
	}
	tmp_str = tmp_str.split('&#039;').join("'");

	return tmp_str;
}


function get_html_translation_table(table, quote_style) {
	// Returns the internal translation table used by htmlspecialchars and htmlentities  
	// 
	// version: 906.401
	// discuss at: http://phpjs.org/functions/get_html_translation_table
	// +   original by: Philip Peterson
	// +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfixed by: noname
	// +   bugfixed by: Alex
	// +   bugfixed by: Marco
	// +   bugfixed by: madipta
	// +   improved by: KELAN
	// +   improved by: Brett Zamir (http://brett-zamir.me)
	// +    bugfixed by: Brett Zamir (http://brett-zamir.me)
	// %          note: It has been decided that we're not going to add global
	// %          note: dependencies to php.js. Meaning the constants are not
	// %          note: real constants, but strings instead. integers are also supported if someone
	// %          note: chooses to create the constants themselves.
	// *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
	// *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}

	var entities = {}, histogram = {}, decimal = 0, symbol = '';
	var constMappingTable = {}, constMappingQuoteStyle = {};
	var useTable = {}, useQuoteStyle = {};

	// Translate arguments
	constMappingTable[0]      = 'HTML_SPECIALCHARS';
	constMappingTable[1]      = 'HTML_ENTITIES';
	constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
	constMappingQuoteStyle[2] = 'ENT_COMPAT';
	constMappingQuoteStyle[3] = 'ENT_QUOTES';

	useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
	useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';

	if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
		throw new Error("Table: "+useTable+' not supported');
		// return false;
	}

	if (useTable === 'HTML_ENTITIES') {
		entities['160'] = '&nbsp;';
		entities['161'] = '&iexcl;';
		entities['162'] = '&cent;';
		entities['163'] = '&pound;';
		entities['164'] = '&curren;';
		entities['165'] = '&yen;';
		entities['166'] = '&brvbar;';
		entities['167'] = '&sect;';
		entities['168'] = '&uml;';
		entities['169'] = '&copy;';
		entities['170'] = '&ordf;';
		entities['171'] = '&laquo;';
		entities['172'] = '&not;';
		entities['173'] = '&shy;';
		entities['174'] = '&reg;';
		entities['175'] = '&macr;';
		entities['176'] = '&deg;';
		entities['177'] = '&plusmn;';
		entities['178'] = '&sup2;';
		entities['179'] = '&sup3;';
		entities['180'] = '&acute;';
		entities['181'] = '&micro;';
		entities['182'] = '&para;';
		entities['183'] = '&middot;';
		entities['184'] = '&cedil;';
		entities['185'] = '&sup1;';
		entities['186'] = '&ordm;';
		entities['187'] = '&raquo;';
		entities['188'] = '&frac14;';
		entities['189'] = '&frac12;';
		entities['190'] = '&frac34;';
		entities['191'] = '&iquest;';
		entities['192'] = '&Agrave;';
		entities['193'] = '&Aacute;';
		entities['194'] = '&Acirc;';
		entities['195'] = '&Atilde;';
		entities['196'] = '&Auml;';
		entities['197'] = '&Aring;';
		entities['198'] = '&AElig;';
		entities['199'] = '&Ccedil;';
		entities['200'] = '&Egrave;';
		entities['201'] = '&Eacute;';
		entities['202'] = '&Ecirc;';
		entities['203'] = '&Euml;';
		entities['204'] = '&Igrave;';
		entities['205'] = '&Iacute;';
		entities['206'] = '&Icirc;';
		entities['207'] = '&Iuml;';
		entities['208'] = '&ETH;';
		entities['209'] = '&Ntilde;';
		entities['210'] = '&Ograve;';
		entities['211'] = '&Oacute;';
		entities['212'] = '&Ocirc;';
		entities['213'] = '&Otilde;';
		entities['214'] = '&Ouml;';
		entities['215'] = '&times;';
		entities['216'] = '&Oslash;';
		entities['217'] = '&Ugrave;';
		entities['218'] = '&Uacute;';
		entities['219'] = '&Ucirc;';
		entities['220'] = '&Uuml;';
		entities['221'] = '&Yacute;';
		entities['222'] = '&THORN;';
		entities['223'] = '&szlig;';
		entities['224'] = '&agrave;';
		entities['225'] = '&aacute;';
		entities['226'] = '&acirc;';
		entities['227'] = '&atilde;';
		entities['228'] = '&auml;';
		entities['229'] = '&aring;';
		entities['230'] = '&aelig;';
		entities['231'] = '&ccedil;';
		entities['232'] = '&egrave;';
		entities['233'] = '&eacute;';
		entities['234'] = '&ecirc;';
		entities['235'] = '&euml;';
		entities['236'] = '&igrave;';
		entities['237'] = '&iacute;';
		entities['238'] = '&icirc;';
		entities['239'] = '&iuml;';
		entities['240'] = '&eth;';
		entities['241'] = '&ntilde;';
		entities['242'] = '&ograve;';
		entities['243'] = '&oacute;';
		entities['244'] = '&ocirc;';
		entities['245'] = '&otilde;';
		entities['246'] = '&ouml;';
		entities['247'] = '&divide;';
		entities['248'] = '&oslash;';
		entities['249'] = '&ugrave;';
		entities['250'] = '&uacute;';
		entities['251'] = '&ucirc;';
		entities['252'] = '&uuml;';
		entities['253'] = '&yacute;';
		entities['254'] = '&thorn;';
		entities['255'] = '&yuml;';
	}

	if (useQuoteStyle !== 'ENT_NOQUOTES') entities['34'] = '&quot;';
	if (useQuoteStyle === 'ENT_QUOTES') entities['39'] = '&#39;';
	entities['60'] = '&lt;';
	entities['62'] = '&gt;';

	// ascii decimals for better compatibility
	entities['38'] = '&amp;';

	// ascii decimals to real symbols
	for (decimal in entities) {
		symbol = String.fromCharCode(decimal);
		histogram[symbol] = entities[decimal];
	}
    
	return histogram;
}