	/* 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() {

	$("#SchTable").tablesorter();
	$("#statstable").tablesorter();
     // simple accordion
	        jQuery('#list1a').accordion();
	        jQuery('#list1b').accordion({
	            autoheight: false
	        });

        

	        var timeout = 500;
	        var closetimer = 0;
	        var ddmenuitem = 0;

	        function jsddm_open() {
	            jsddm_canceltimer();
	            jsddm_close();
	            ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	        }

	        function jsddm_close()
	        { if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }

	        function jsddm_timer()
	        { closetimer = window.setTimeout(jsddm_close, timeout); }

	        function jsddm_canceltimer() {
	            if (closetimer) {
	                window.clearTimeout(closetimer);
	                closetimer = null;
	            } 
	        }

	        $(document).ready(function() {
	            $('#jsddm > li').bind('mouseover', jsddm_open)
	            $('#jsddm > li').bind('mouseout', jsddm_timer)
	        });

	        document.onclick = jsddm_close;

	        
	    // Track mousemouse co-ords for login box popup
	    $().mousemove(function(e) {
	        px = e.pageX;
	        py = e.pageY;
	    });

	    $("#ctl00_cph_Mainbody_ctl00_0_12_ctl00_eventCal tr:first td table tr td, #ctl00_cph_Mainbody_ctl00_0_12_ctl00_eventCal tr:first td ").css({ 'background-color': '#fff' });

	    $("#ctl00_cph_Mainbody_ctl00_4_eventCal ").css({ 'border': 'solid 1px #000' });

	    //$("#ctl00_cph_Mainbody_ctl00_4_eventCal th").css({ 'background-color': '#666', 'color': '#fff', 'height': '20px', 'font-size': '18px' });
	    
	    //$("#ctl00_cph_Mainbody_ctl00_0_12_ctl00_eventswidget td:first").css({ 'background-color': '#fff', 'height': '28px', 'font-size': '16px' });


	    
	    
	    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();

	    /*$("#Sponser_Horz").load('scripts/sections/Sponser/Horz.htm');
	    $("#Sponser_Vert").load('scripts/sections/Sponser/Vert.htm');*/

	});
	/* 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, 11) == "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>");
	    });

	}
