/* variables for getting current mouse x,y coords */
var px = 0;
var py = 0;
var userid = 0;
var username = "";
var isadmin = false; //EIP-ADDED
// Var to track min and max state of floating window
var img1 = new Image;
img1.src = '/userfiles/images/north_america';
var img2 = new Image;
img2.src = '/userfiles/images/south_america';
var img3 = new Image;
img3.src = '/userfiles/images/europe';
var img4 = new Image;
img4.src = '/userfiles/images/africa';
var img5 = new Image;
img5.src = '/userfiles/images/asia';
var img5 = new Image;
img5.src = '/userfiles/images/australasia';
var img6 = new Image;
img6.src = '/userfiles/images/service_map.gif'


/*  THIS FUNCTION EXECUTES AFTER THE DOM IS READY, BUT BEFORE THE PAGE RENDERS...  */
$(document).ready(function() {

    // Track mousemouse co-ords for login box popup
    $().mousemove(function(e) {
        px = e.pageX;
        py = e.pageY;
    });
    $("#gotocountry").bind('select', function() {
        alert("test");
        window.location = "#" + $(this).val();
    });

    $("#corporatebox").hover(function() { $("#corporatebox").animate({ top: "-46px", height: "100px" }, 300); }, function() { });
    $("#corporatebox").hover(function() { }, function() { $("#corporatebox").animate({ top: "40px", height: "100px" }, 300); });


    $("#technologybox").hover(function() { $("#technologybox").animate({ top: "-46px", height: "100px" }, 300); }, function() { });
    $("#technologybox").hover(function() { }, function() { $("#technologybox").animate({ top: "40px", height: "100px" }, 300); });

    $("#manufacturingbox").hover(function() { $("#manufacturingbox").animate({ top: "-46px", height: "100px" }, 300); }, function() { });
    $("#manufacturingbox").hover(function() { }, function() { $("#manufacturingbox").animate({ top: "40px", height: "100px" }, 300); });

    $("#engineeringbox").hover(function() { $("#engineeringbox").animate({ top: "-46px", height: "100px" }, 300); }, function() { });
    $("#engineeringbox").hover(function() { }, function() { $("#engineeringbox").animate({ top: "40px", height: "100px" }, 300); });





    $('#input_text').keyup(function(e) {
        //alert(e.keyCode);
        if (e.keyCode == 13) {
            window.location = '?Content=Search+' + $('#input_text').val();
        }
    });
    $("#searchbtn").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, top: e.pageY - 167 });
        $("#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);
    }
}

function cmap(area) {
    var maparea = '/userfiles/images/' + area + '.jpg';
    $("#map").attr('src', maparea);
}

function cmap2(area) {
 $("#map").attr('src', '/userfiles/images/service_map.gif' );
}

/* 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>");
    });

}

/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2008 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
$(document).ready(function() {
    closetimer = 0;
    if ($("#nav")) {
        $("#nav b").mouseover(function() {
            clearTimeout(closetimer);
            if (this.className.indexOf("clicked") != -1) {
                $(this).parent().next().slideUp(1);
                $(this).removeClass("clicked");
            }
            else {
                $("#nav b").removeClass();
                $(this).addClass("clicked");
                $("#nav ul:visible").slideUp(1);
                $(this).parent().next().slideDown(1);
            }
            return false;
        });
        $("#nav").mouseover(function() {
            clearTimeout(closetimer);
        });
        $("#nav").mouseout(function() {
            closetimer = window.setTimeout(function() {
                $("#nav ul:visible").slideUp(1);
                $("#nav b").removeClass("clicked");
            }, 100);
        });
    }
});

$(document).ready(function() {




    closetimer = 0;
    var temp;
    if ($("#nav2")) {
        $("#nav2 b").mouseover(function() {
            clearTimeout(closetimer);
            var id = $(this).attr("id");
            temp = id;
            if (this.className.indexOf("clicked") != -1) {
                $("#" + id + "-c").show();
                $(this).removeClass("clicked");
            }
            else {
                for (i = 1; i < 9; i++) {
                    $("#w" + i + "-c").hide();
                }
                $("#nav2 b").removeClass();
                $(this).addClass("clicked");
                $("#" + id + "-c").show();
            }
            return false;
        });


    }

});


