/* variables for getting current mouse x,y coords */
var px = 0;
var py = 0;
var userid = 0;
var username = "";
var evtSL; //Find_an_Agentdrop event helper
var evtSD; //Find_an_Agentdrop event helper
var intFadeIn = 500;
var intFadeOut = 50;
var tmpClickFun = false;
// Var to track min and max state of floating window

// ELEMENT LOCATION
jQuery.fn.elementlocation = function() {
    var curleft = 0;
    var curtop = 0;

    var obj = this;

    do {
        curleft += obj.attr('offsetLeft');
        curtop += obj.attr('offsetTop');

        obj = obj.offsetParent();
    } while (obj.attr('tagName') != 'BODY');

    
    return ({ x: curleft, y: curtop });
};

// END ELEMENT LOCATION

/* START Find_a_Listing LINK  */
function  doHomeDrop() {
    cancelFind_a_ListingDrop(); 
    cancelFind_an_OfficeDrop(); //ensure other dropdowns are closed
    cancelInfo_for_SellersDrop();
    cancelInfo_for_BuyersDrop();
    cancelOpen_HousesDrop();
    cancelSubdivisionsDrop();
    cancelReal_Estate_NewsDrop();
    cancelFind_an_AgentDrop();

    var location = $("#vmenu").elementlocation();
    var x = location.x;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            y = y - 2;
            x = x - 1;
        }
    }
    if ($("#HomeDrop").length > 0) {
        $("#HomeDrop").css({ 'left': x + 'px', 'top': y + 'px' })
        $("#HomeDrop").fadeIn(intFadeIn);
    } else {
    setupHomeDrop();
    }
}
function cancelHomeDrop() { $("#Homedrop").fadeOut(intFadeOut); };
function setupHomeDrop() {
    $("body").append("<div id='Homedrop' style='left:" + location.x + "px;top:" + (location.y + 0) + "px;'></div>");
    $("#Homedrop").load("scripts/menus/Home.html").hide();
    $("#Homedrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelHomeDrop()', 200); });
    $("#Home a").attr("href", "/");
}
/* END Find_a_Listing LINK  */

/* START Find_an_Agent LINK  */
function doFind_a_ListingDrop() {
    cancelFind_an_OfficeDrop(); //ensure other dropdowns are closed
    cancelInfo_for_SellersDrop();
    cancelInfo_for_BuyersDrop();
    cancelOpen_HousesDrop();
    cancelSubdivisionsDrop();
    cancelHomeDrop();
    cancelReal_Estate_NewsDrop();
    cancelFind_an_AgentDrop();

    var location = $("#vmenu").elementlocation();
    var x = location.x + 54;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            y = y - 2;
            x = x - 1;
        }
    }
    if ($("#Find_a_Listingdrop").length > 0) {
        $("#Find_a_Listingdrop").css({ 'left': x, 'top': y })
        $("#Find_a_Listingdrop").fadeIn(intFadeIn);
    } else {
        setupFind_a_ListingDrop();
    }
}
function cancelFind_a_ListingDrop() { $("#Find_a_Listingdrop").fadeOut(intFadeOut); };
function setupFind_a_ListingDrop() {
    $("body").append("<div id='Find_a_Listingdrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Find_a_Listingdrop").load("scripts/menus/Find_a_Listing.html").hide();
    $("#Find_a_Listingdrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelFind_a_ListingDrop()', 200); });
    $("#Find_a_Listing a").attr("href", "#");
}
/* END Find_a_Listing LINK  */

/* START Find_an_Agent LINK  */
function doFind_an_AgentDrop() {
    cancelFind_an_OfficeDrop(); //ensure other dropdowns are closed
    cancelInfo_for_SellersDrop();
    cancelInfo_for_BuyersDrop();
    cancelOpen_HousesDrop();
    cancelHomeDrop();
    cancelSubdivisionsDrop();
    cancelReal_Estate_NewsDrop();
    cancelFind_a_ListingDrop();
    var location = $("#Find_an_Agent").elementlocation();
    var x = location.x - 1;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            x = x - 1;
            y =  y - 1;
        }
    } 
    if ($("#Find_an_Agentdrop").length > 0) {
        $("#Find_an_Agentdrop").css({ 'left': x, 'top': y })
        $("#Find_an_Agentdrop").fadeIn(intFadeIn);
    } else {
        setupFind_an_AgentDrop();
    }
}
function cancelFind_an_AgentDrop() { $("#Find_an_Agentdrop").fadeOut(intFadeOut); };
function setupFind_an_AgentDrop() {
    $("body").append("<div id='Find_an_Agentdrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Find_an_Agentdrop").load("scripts/menus/Find_an_Agent.html").hide();
    $("#Find_an_Agentdrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelFind_an_AgentDrop()', 200); });
    $("#Find_an_Agent a").attr("href", "#");
}
/* END Find_an_Agent LINK  */

/* START Find_an_Office LINK  */
function doFind_an_OfficeDrop() {
    cancelFind_a_ListingDrop(); //ensure other dropdowns are closed
    cancelInfo_for_SellersDrop();
    cancelInfo_for_BuyersDrop();
    cancelHomeDrop();
    cancelOpen_HousesDrop();
    cancelSubdivisionsDrop();
    cancelReal_Estate_NewsDrop();
    cancelFind_an_AgentDrop();
    var location = $("#Find_an_Office").elementlocation();
    var x = location.x -1;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            y =  y - 1;
            x = x - 1;
        }
    } 
    if ($("#Find_an_Officedrop").length > 0) {
        $("#Find_an_Officedrop").css({ 'left': x, 'top': y })
        $("#Find_an_Officedrop").fadeIn(intFadeIn);
    } else {
        setupFind_an_OfficeDrop();
    }
}
function cancelFind_an_OfficeDrop() { $("#Find_an_Officedrop").fadeOut(intFadeOut); };
function setupFind_an_OfficeDrop() {
    $("body").append("<div id='Find_an_Officedrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Find_an_Officedrop").load("scripts/menus/Find_an_Office.html").hide();
    $("#Find_an_Officedrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelFind_an_OfficeDrop()', 200); });
    $("#Find_an_Office a").attr("href", "#");
}
/* END Find_an_Office LINK  */

/* START Open_Houses LINK  */
function doOpen_HousesDrop() {
    cancelFind_a_ListingDrop(); //ensure other dropdowns are closed
    cancelFind_an_OfficeDrop();
    cancelInfo_for_BuyersDrop();
    cancelHomeDrop();
    cancelSubdivisionsDrop();
    cancelReal_Estate_NewsDrop();
    cancelFind_an_AgentDrop();
    cancelInfo_for_SellersDrop();
    var location = $("#Open_Houses").elementlocation();
    var x = location.x - 1;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            y = y - 1;
            x = x - 1;
        }
    }
    if ($("#Open_Housesdrop").length > 0) {
        $("#Open_Housesdrop").css({ 'left': x, 'top': y })
        $("#Open_Housesdrop").fadeIn(intFadeIn);
    } else {
        setupOpen_HousesDrop();
    }
}
function cancelOpen_HousesDrop() { $("#Open_Housesdrop").fadeOut(intFadeOut); };
function setupOpen_HousesDrop() {
    $("body").append("<div id='Open_Housesdrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Open_Housesdrop").load("scripts/menus/Open_Houses.html").hide();
    $("#Open_Housesdrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelOpen_HousesDrop()', 200); });
    $("#Open_Houses a").attr("href", "#");
}
/* END Open_Houses LINK  */

/* START Subdivisions LINK  */
function doSubdivisionsDrop() {
    cancelFind_a_ListingDrop(); //ensure other dropdowns are closed
    cancelFind_an_OfficeDrop();
    cancelInfo_for_BuyersDrop();
    cancelHomeDrop();
    cancelOpen_HousesDrop();
    cancelReal_Estate_NewsDrop();
    cancelFind_an_AgentDrop();
    cancelInfo_for_SellersDrop();
    var location = $("#Subdivisions").elementlocation();
    var x = location.x - 1;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            y =  y - 1;
            x = x - 1;
        }
    } 
    if ($("#Subdivisionsdrop").length > 0) {
        $("#Subdivisionsdrop").css({ 'left': x, 'top': y})
        $("#Subdivisionsdrop").fadeIn(intFadeIn);
    } else {
        setupSubdivisionsDrop();
    }
}
function cancelSubdivisionsDrop() { $("#Subdivisionsdrop").fadeOut(intFadeOut); };
function setupSubdivisionsDrop() {
    $("body").append("<div id='Subdivisionsdrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Subdivisionsdrop").load("scripts/menus/Subdivision.html").hide();
    $("#Subdivisionsdrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelSubdivisionsDrop()', 200); });
    $("#Subdivisions a").attr("href", "#");
}
/* END Subdivisions LINK  */

/* START Info_for_Sellers LINK  */
function doInfo_for_SellersDrop() {
    cancelFind_a_ListingDrop(); //ensure other dropdowns are closed
    cancelFind_an_OfficeDrop();
    cancelInfo_for_BuyersDrop();
    cancelHomeDrop();
    cancelSubdivisionsDrop();
    cancelReal_Estate_NewsDrop();
    cancelFind_an_AgentDrop();
    cancelOpen_HousesDrop();
    var location = $("#Info_for_Sellers").elementlocation();
    var x = location.x - 1;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            y = y - 1;
            x = x - 1;
        }
    }
    if ($("#Info_for_Sellersdrop").length > 0) {
        $("#Info_for_Sellersdrop").css({ 'left': x, 'top': y })
        $("#Info_for_Sellersdrop").fadeIn(intFadeIn);
    } else {
        setupInfo_for_SellersDrop();
    }
}
function cancelInfo_for_SellersDrop() { $("#Info_for_Sellersdrop").fadeOut(intFadeOut); };
function setupInfo_for_SellersDrop() {
    $("body").append("<div id='Info_for_Sellersdrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Info_for_Sellersdrop").load("scripts/menus/Info_for_Sellers.html").hide();
    $("#Info_for_Sellersdrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelInfo_for_SellersDrop()', 200); });
    $("#Info_for_Sellers a").attr("href", "#");
}
/* END Info_for_Sellers LINK  */

/* START Info_for_Buyers LINK  */
function doInfo_for_BuyersDrop() {
    cancelFind_a_ListingDrop(); //ensure other dropdowns are closed
    cancelFind_an_OfficeDrop();
    cancelFind_an_AgentDrop();
    cancelHomeDrop();
    cancelOpen_HousesDrop();
    cancelSubdivisionsDrop();
    cancelReal_Estate_NewsDrop();
    cancelInfo_for_SellersDrop();
    var location = $("#Info_for_Buyers").elementlocation();
    var x = location.x - 1;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            x = x - 1;
            y =  y - 1;
        }
    } 
    if ($("#Info_for_Buyersdrop").length > 0) {
        $("#Info_for_Buyersdrop").css({ 'left': x, 'top': y })
        $("#Info_for_Buyersdrop").fadeIn(intFadeIn);
    } else {
        setupInfo_for_BuyersDrop();
    }
}
function cancelInfo_for_BuyersDrop() { $("#Info_for_Buyersdrop").fadeOut(intFadeOut); };
function setupInfo_for_BuyersDrop() {
    $("body").append("<div id='Info_for_Buyersdrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Info_for_Buyersdrop").load("scripts/menus/Info_for_Buyers.html").hide();
    $("#Info_for_Buyersdrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelInfo_for_BuyersDrop()', 200); });
    $("#Info_for_Buyers a").attr("href", "#");
}
/* END Info_for_Buyers LINK  */

/* START Real_Estate_News LINK  */
function doReal_Estate_NewsDrop() {
    cancelFind_a_ListingDrop(); //ensure other dropdowns are closed
    cancelFind_an_OfficeDrop();
    cancelFind_an_AgentDrop();
    cancelOpen_HousesDrop();
    cancelSubdivisionsDrop();
    cancelHomeDrop();
    cancelInfo_for_SellersDrop();
    cancelInfo_for_BuyersDrop();
    var location = $("#Real_Estate_News").elementlocation();
    var x = location.x - 1;
    var y = location.y + 39;
    if ($.browser.msie) {
        if ($.browser.version < 8) {
            y =  y - 1;
            x = x - 1;
        }
    } 
    if ($("#Real_Estate_Newsdrop").length > 0) {
        $("#Real_Estate_Newsdrop").css({ 'left': x, 'top': y })
        $("#Real_Estate_Newsdrop").fadeIn(intFadeIn);
    } else {
        setupReal_Estate_NewsDrop();
    }
}
function cancelReal_Estate_NewsDrop() { $("#Real_Estate_Newsdrop").fadeOut(intFadeOut); };
function setupReal_Estate_NewsDrop() {
    $("body").append("<div id='Real_Estate_Newsdrop' style='left:" + location.x + "px;top:" + (location.y + 20) + "px;'></div>");
    $("#Real_Estate_Newsdrop").load("scripts/menus/Real_Estate_News.html").hide();
    $("#Real_Estate_Newsdrop").hover(function(e) { clearTimeout(evtSL); },
                    function(e) { evtSD = setTimeout('cancelReal_Estate_NewsDrop()', 200); });
    $("#Real_Estate_News a").attr("href", "#");
}
/* END Real_Estate_News LINK  */

/*  THIS FUNCTION EXECUTES AFTER THE DOM IS READY, BUT BEFORE THE PAGE RENDERS...  */
$(document).ready(function() {
    setupHomeDrop();
    setupFind_a_ListingDrop();
    setupFind_an_AgentDrop();
    setupFind_an_OfficeDrop();
    setupOpen_HousesDrop();
    setupSubdivisionsDrop();
    setupInfo_for_SellersDrop();
    setupInfo_for_BuyersDrop();
    setupReal_Estate_NewsDrop();
    // Track mousemouse co-ords for login box popup
    $().mousemove(function(e) {
        px = e.pageX;
        py = e.pageY;
    });
    /* START Find_a_Listing LINK  */
    $("#Home a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doHomeDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Home").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelHomeDrop()', intFadeOut);
    });
    /* END Find_a_Listing LINK  */


    /* START Find_a_Listing LINK  */
    $("#Find_a_Listing a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doFind_a_ListingDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Find_a_Listing").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelFind_a_ListingDrop()', intFadeOut);
    });
    /* END Find_a_Listing LINK  */

    /* START Find_an_Agent LINK  */
    $("#Find_an_Agent a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doFind_an_AgentDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Find_an_Agent").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelFind_an_AgentDrop()', intFadeOut);
    });
    /* END Find_an_Agent LINK  */

    /* START Find_an_Office LINK  */
    $("#Find_an_Office a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doFind_an_OfficeDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Find_an_Office").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelFind_an_OfficeDrop()', intFadeOut);
    });
    /* END Find_an_Office LINK  */

    /* START Subdivisions LINK  */
    $("#Subdivisions a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doSubdivisionsDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Subdivisions").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelSubdivisionsDrop()', intFadeOut);
    });
    /* END Subdivisions LINK  */

    /* START Open_Houses LINK  */
    $("#Open_Houses a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doOpen_HousesDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Open_Houses").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelOpen_HousesDrop()', intFadeOut);
    });
    /* END Open_Houses LINK  */

    /* START Info_for_Sellers LINK  */
    $("#Info_for_Sellers a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doInfo_for_SellersDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Info_for_Sellers").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelInfo_for_SellersDrop()', intFadeOut);
    });
    /* END Info_for_Sellers LINK  */

    /* START Info_for_Buyers LINK  */
    $("#Info_for_Buyers a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doInfo_for_BuyersDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Info_for_Buyers").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelInfo_for_BuyersDrop()', intFadeOut);
    });
    /* END Info_for_Buyers LINK  */

    /* START Real_Estate_News LINK  */
    $("#Real_Estate_News a ").hover(function(e) {
        clearTimeout(evtSD);
        evtSD = setTimeout('doReal_Estate_NewsDrop()', intFadeOut);
    }, function(e) { clearTimeout(evtSD); });

    $("#Real_Estate_News").bind('mouseleave', function(e) {
        evtSL = setTimeout('cancelReal_Estate_NewsDrop()', intFadeOut);
    });
    /* END Real_Estate_News LINK  */


    $('#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");
        }
    });

    //load news module



    $("#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").keydown(function(event) {
            if (event.keyCode == 13) { doLogin(); }
        });
        $("#username").keydown(function(event) {
            if (event.keyCode == 13) { doLogin(); }
        });
    });

    //preload images
    $.getScript("js/sha256.js");

});
/* 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) == "Successfull") {
            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);
//    document.getElementById('ctl00_cph_Mainbody_ctl00_0_2_QuickSearch_Btn').onclick = tmpClickFun;
 }

/* 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'); }

$("ul.thumb li").hover(function() {
	$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
	$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
		.animate({
			marginTop: '-80px', /* The next 4 lines will vertically align this image */ 
			marginLeft: '-110px',
			top: '50%',
			left: '50%',
			width: '174px', /* Set new width */
			height: '115px', /* Set new height */
			padding: '0px'
		}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */

	} , function() {
	$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
	$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
		.animate({
			marginTop: '0', /* Set alignment back to default */
			marginLeft: '0',
			top: '0',
			left: '0',
			width: '86px', /* Set width back to default */
			height: '57px', /* Set height back to default */
			padding: '0px'
		}, 400);
});

$("ul.thumb li a").click(function() {
		
		var mainImage = $(this).attr("href"); //Find Image Name
		$("#main_view img").attr({ src: mainImage });
		return false;		
	});

	function button2click() {
	    var txtname = document.getElementById('ctl00_cph_Mainbody_ctl00_0_4_TextBox1').value ;
	    var txtemail = "" + document.getElementById('ctl00_cph_Mainbody_ctl00_0_4_TextBox2').value;
	    var re = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
	    if ((txtname.length < 1 || txtemail.length <= 1) && !re.test(txtemail)) {
	        alert('Please enter your name and a valid e-mail address');
	    }
	    else {
	        window.open('Widgets/FTKPicker.aspx?ftkName='+txtname+'&ftkemail=' + txtemail, '', 'height=470, scrollbars=yes, width=700');
	        return false;
	    }
	}

	function lookdown(inputString) {
	    if (inputString.length == 0) {
	        // Hide the suggestion box.
	        $("#suggestions2").hide();
	    } else {
	        $.post("../rpc2.aspx", { queryString: "" + inputString + "" }, function(data) {
	            if (data.length > 0) {
	                $("#suggestions2").show();
	                $("#autoSuggestionsList2").html(data);
	            }
	        });
	    }

	} // lookup

	function lookup(inputString) {

	    if (inputString.length == 0) {
	        // Hide the suggestion box.
	        $("#suggestions").hide();
	    } else {
	        $.post("../rpc.aspx", { queryString: "" + inputString + "" }, function(data) {
	            if (data.length > 0) {
	                $("#suggestions").show();
	                $("#autoSuggestionsList").html(data);
	            }
	        });
	    }

	    return false;
	} // lookup
	$(document).ready(function() {
	    $("#ctl00_cph_Mainbody_ctl00_13_txtSearch").keydown(function(e) {
	        if ($(this).val() != "")
	            lookup($(this).val());
	        if (e.keyCode == 13) { return false; }
	    });
	});


function fill(thisValue) {
    $("#ctl00_cph_Mainbody_ctl00_13_txtSearch").val(thisValue);
    $("#ctl00_cph_Mainbody_ctl00_13_BtnAgentSearch").click();
    $("#suggestions").hide();

}
function filltown(thisValue) {
    $("#ctl00_TextBox1").val(thisValue);
    $("#ctl00_ImageButton2").click();
    $("#suggestions2").hide();
}
