	/* variables for getting current mouse x,y coords */
	var px=0;
	var py=0;
	var userid = 0;
	var username = "";
	// Var to track min and max state of floating window


	/*  THIS FUNCTION EXECUTES AFTER THE DOM IS READY, BUT BEFORE THE PAGE RENDERS...  */
	$(document).ready(function() {
	
		$(".homboxclass0 img").remove();


	    // Track mousemouse co-ords for login box popup
	    $().mousemove(function(e) {
	        px = e.pageX;
	        py = e.pageY;
	    });

	    $("#Residents").hover(function(e) { $(this).attr("src", "App_Themes/default/img/residents_over.png"); },
	        function(e) { $(this).attr("src", "App_Themes/default/img/residents.png"); });
	    $("#Business").hover(function(e) { $(this).attr("src", "App_Themes/default/img/business_over.png"); },
	        function(e) { $(this).attr("src", "App_Themes/default/img/business.png"); });
	    $("#Visitors").hover(function(e) { $(this).attr("src", "App_Themes/default/img/visitors_over.png"); },
	        function(e) { $(this).attr("src", "App_Themes/default/img/visitors.png"); });
	    $("#My_City").hover(function(e) { $(this).attr("src", "App_Themes/default/img/government_over.png"); },
	        function(e) { $(this).attr("src", "App_Themes/default/img/government.png"); });


	    $('#input_text').keyup(function(e) {
	        //alert(e.keyCode);
	        if (e.keyCode == 13) {
	            window.location = '?Content=Search+' + $('#input_text').val();
	        }
	    });
	    $("#search_nav_button").bind('click', function() { window.location = '?Content=Search+' + $('#input_text').val(); });
	    $("#input_text").bind('focus', function() {
	        if ($('#input_text').val() == 'Search...') {
	            $('#input_text').val("");
	            $('#input_text').css({ 'color': '#000000' });
	        }
	    });
	    $("#input_text").bind('blur', function() {
	        if ($('#input_text').val() == '') {
	            $('#input_text').css({ 'color': '#666666' });
	            $('#input_text').val("Search...");
	        }
	    });

	    $("#ctl00_cph_Mainbody_ctl00_0_4_eventCal tr td").each(function(i) {

	        if ($(this).attr("style") == "color: rgb(239, 239, 239); width: 14%; white-space: nowrap;") {
	            $(this).removeAttr("style");
	            $(this).attr("class", "otherday");

	        } else if ($(this).attr("style") == "WIDTH: 14%; COLOR: #efefef; WHITE-SPACE: nowrap") {
	            $(this).removeAttr("style");
	            $(this).attr("class", "otherday");

	        } else {
	            $(this).removeAttr("style");
	        }
	    });


	    $("#ctl00_cph_Mainbody_ctl00_0_4_eventCal tr:even td").css({ 'background-color': '#f2f2f2', 'padding': '2px;' });
	    $("#ctl00_cph_Mainbody_ctl00_0_4_eventCal tr:first td").css({ 'background-color': '#fff', 'padding': '2px;' });
	    $(".otherday a").css({ 'color': '#ccc' });

	    $(".calevent").each(function() {
	        $(this).hover(function() {
	            $("#calinfo").html("<div>Loading... <img src='images/busy.gif' alt='Please Wait' /></div>");
	            $("#calinfo").css({ 'top': py - 5, 'left': px + 15 });
	            $("#calinfo").show();
	            $(this).find("a").attr("title", "");
	            $("#calinfo").load('scripts/widgets/calendar/getinfo.aspx' + $(this).find("a").attr("href"), function() { });
	        }, function() {
	        $("#calinfo").hide();
	        });
	    });
	    // $("#ctl00_cph_Mainbody_ctl00_0_4_eventCal tr td a").css({ 'color': '#4d4d4d' });
	    // $("#ctl00_cph_Mainbody_ctl00_0_4_eventCal tr td .calevent a").css({ 'color': '#23336c' });

	    // $("#ctl00_cph_Mainbody_ctl00_0_4_eventCal tr:first").css({ 'border-bottom': '#fff' });
	    /*  put link like cursor behavor on all elements with class 'hover' */
	    setHover(".hover");

	    /* Setup the login box popup click function*/
	    $("#loginlink").click(function(e) {
	        $('#voice-login').css({ left: e.pageX - 255, top: e.pageY - 210 });
	        $("#username").val('');
	        $("#password").val('');
	        $("#voice-login").fadeIn(1500);
	        $("#username").focus();
	        $("#password").keyup(function(event) {
	            if (event.keyCode == 13) { doLogin(); }
	        });
	        $("#username").keyup(function(event) {
	            if (event.keyCode == 13) { doLogin(); }
	        });
	    });

	    if (userid == 0) doGarbage();

	});
	/* Search box */
	
	
	/*   put link like cursor behavor on all elements with class passed as argument  */
	function setHover(div) {
		$(div).hover(function (){$(div).css({cursor:"pointer"});}, 
      	function (){ $(div).css({cursor:"default"});});
	}
	 
	/* login script */
	function doLogin() {

	    $.post('scripts/processlogin.aspx', {
	        u: $("#username").val(),
	        p: hex_sha256(hex_sha256($("#password").val()))
	    }, function(msg) {
	        $("#loginmsg").html("Login: " + msg);
	        if (Left(msg,10) == "Successful") {
	            hideLogin();
	            setTimeout('rload()', 1000);
	        }
	    });
	}

	function Left(str, n) {
	    if (n <= 0)
	        return "";
	    else if (n > String(str).length)
	        return str;
	    else
	        return String(str).substring(0, n);
	}

	function Right(str, n) {
	    if (n <= 0)
	        return "";
	    else if (n > String(str).length)
	        return str;
	    else {
	        var iLen = String(str).length;
	        return String(str).substring(iLen, iLen - n);
	    }
	}

	/* hides login form  */
	function hideLogin(){ $("#voice-login").fadeOut(1000);	}
	
	/* logs user out of the cms  */
	function doLogout(){
		$.post('scripts/logout.aspx',{},function(msg){window.location.reload(true);});
	}
	
	/* reloads current page  */
	function rload(){window.location.reload(true);};
	
	function encodeRE(s) { return s.replace(/[.*+?^${}()|[\]\/\\]/g, '\\$0'); }
	
	function doMetaUpdate(urltxt){
		$.wordStats.computeTopWords(count, $('.mainbody'));
		
		for (var i=0; i <= 20; i++ )
		{
			words=words+$.wordStats.topWords[i];
		}
		 $.wordStats.clear(); //release memory
			$.post('scripts/meta.asp',{
				metakey: words,
				content: $(".mainbody").html(),
				url: urltxt
			});//,function(data){alert(data);}	
	}


	function doGarbage() {
	    /* Find all friendly UL's */
	    $('ul.SearchableSelect').each(function() {
	        /* Hide list element */
	        $(this).css("display", "none");

	        /* Create new ID for the select, use existent Id of UL but add the _Select prefix */
	        var ElementId = $(this).attr("id") + "_Select";

	        /* Create new Select-element */
	        $(this).after("<select id='" + ElementId + "' class='SearchableSelect'></select>");

	        /* Loop-through list and add children to select */
	        var first = true;
	        $(this).find("li").each(function() {
	            if (first) {
	                $(this).html("Please Select Street...");
	                first = false;
	            }
	            /* Setup values */
	            var Value =  $(this).find("span").attr("title") ;
	            var SelectedElement = ($(this).hasClass("SelectedItem") ? ' selected' : '');

	            /* Add child to select */
	            $("#" + ElementId).append("<option value='" + Value + "'" + SelectedElement + ">" + $(this).html() + "</option>");
	        });
	    });

	    /* Hook selects */
	    $("select.SearchableSelect").change(function() {
	    if (this.value.length > 0) $("#garbagedayis").html("<h2>Your Garbage Pickup Day Is: "+this.value+"</h2>");
	    });

	}