var searchTimer = null;
var searchHasFocus = false;
var popDelay = "";
var ajax = function () {
        this.curID = "";
        this.oLayer = "";
        this.bv = "";
        this.mousex = 0;
        this.mousey = 0;
        this.browserCheck();
        this.iRequests = 0;
        this.oCache = []
    };
ajax.prototype.browserCheck = function () {
    this.bv = document.layers ? "ns" : document.getElementById && !document.all ? "ns6" : "ie"
};
ajax.prototype.requestPost = function (url, parameters) {
    $.ajax({
        type: "POST",
        url: url,
        data: parameters,
        cache: false,
        async: false,
        success: function (serverResponseData) {
            var obj = oAjax;
            var response = serverResponseData;
            obj.iRequests++;
            if (response != "") {
                obj.cacheAdd(obj.curID, response);
                obj.layerWrite(response)
            }
        },
        error: function () {}
    })
};
ajax.prototype.messageGet = function (ID) {
    if (this.curID == ID) return;
    if (this.oLayer == "") {
        this.oLayer = document.getElementById("ajax-dragLayer")
    }
    this.oLayer.style.display = "none"
	this.curID = ID;
    var cachedIndex = this.cacheLookUp(this.curID);
    if (cachedIndex > -1) {
        this.cacheGet(cachedIndex)
    } else {
        var postStr = "id=" + this.encode(this.curID);
        this.requestPost("/includes/ajax_get_summary.asp", postStr)
    }
};
ajax.prototype.layerShow = function () {
    this.oLayer.style.display = "block"
};
ajax.prototype.layerHide = function () {
	oAjax.oLayer.style.display = "none"
    oAjax.curID = ""
};
ajax.prototype.layerWrite = function (sText) {
    var oResponseArray = sText.split("-DELIMITER-");
    if (oResponseArray.length == 0) return;
    var sTitle = oResponseArray[0];
    var sSummary = oResponseArray[1];
    sTitle = this.decode(sTitle);
    sSummary = this.decode(sSummary);
    $("div[id=ajax-summary]").html(sTitle);
    $("div[id=ajax-summary]").html(sSummary);
    if (this.curID != "") this.layerShow()
};
ajax.prototype.cacheLookUp = function (ID) {
    var index = -1;
    for (var i = 0; i < this.oCache.length; i++) {
        if (this.oCache[i][0] == ID) {
            index = i;
            break
        }
    }
    return index
};
ajax.prototype.cacheAdd = function (ID, sText) {
    var index = this.cacheLookUp(ID);
    if (index == -1) {
        this.oCache[this.oCache.length] = [ID, sText]
    }
};
ajax.prototype.cacheGet = function (index) {
    this.layerWrite(this.oCache[index][1])
};
ajax.prototype.encode = function (uri) {
    if (escape) {
        return escape(uri)
    }
    if (encodeURIComponent) {
        return encodeURIComponent(uri)
    }
    return uri
};
ajax.prototype.decode = function (uri) {
    uri = uri.replace(/\+/g, ' ');
    if (unescape) {
        return unescape(uri)
    };
    if (decodeURIComponent) {
        return decodeURIComponent(uri)
    };
    return uri
};
oAjax = new ajax();
var bHeight = 0;
var pixTop = 0;
var bIELTE6 = false;
$(function () {
    $("a").mousemove(function (e) {
        if (oAjax.oLayer != '') {
            if (this.onmouseover != undefined) {
                followMouse(e)
            }
        }
    });
    if ($.browser.msie && parseInt($.browser.version) <= 6) {
        bIELTE6 = true
    }
});
function followMouse(e) {
    bHeight = parseInt($("div[class=dragbody]").height()) - 100;
    oAjax.oLayer.style.top = 0;
    oAjax.oLayer.style.left = 0;
    if (oAjax.bv == "ie") {
        oAjax.mousey = e.pageY - (bHeight + 38);
        oAjax.mousex = e.pageX + 55
    } else {
        oAjax.mousey = e.pageY - bHeight;
        oAjax.mousex = e.pageX + 50
    }
    if (oAjax.curID != "") {	
		if($("#ajax-dragLayer").is(":hidden")){
			$("#ajax-dragLayer").css({"visibility":"hidden"});
			$("#ajax-dragLayer").css({"display":"block"});
		}
        if (oAjax.mousex > (.65 * parseInt($(document).width()))) {
            if (bIELTE6 == false) {
               $("img[class=dragarrow]").attr("src", "/images/nd-poparrow-right.png")
            } else {
                $("img[class=dragarrow]").attr("src", "/images/nd-poparrow-right.gif");
            }
            $("img[class=dragarrow]").css({
                "marginLeft": parseInt($("div[id=ajax-dragLayer]").width()) + 56 + iDragArrow - parseInt($("img[class=dragarrow]").width())
            });
            oAjax.oLayer.style.left = oAjax.mousex - (parseInt($("div[id=ajax-dragLayer]").width()) + 56 + parseInt($("img[class=dragarrow]").width())) + "px";
            oAjax.oLayer.style.top = oAjax.mousey + "px"
        } else {
            if (bIELTE6 == false) {
               $("img[class=dragarrow]").attr("src", "/images/nd-poparrow-left.png");
            } else {
                $("img[class=dragarrow]").attr("src", "/images/nd-poparrow-left.gif")
            }
            $("img[class=dragarrow]").css({
                "marginLeft": iDragArrow
            });
            oAjax.oLayer.style.left = oAjax.mousex + "px";
            oAjax.oLayer.style.top = oAjax.mousey + "px"
        }
		$("#ajax-dragLayer").css({"visibility":"visible"});
    }
};

$(function () {
    $(".shareThis, .atdragbody").hover(function () {
        if ($("div[class=shareThisDD]").is(":hidden")) $("div[class=shareThisDD]").show();
        if (popDelay != "") clearTimeout(popDelay)
    }, function () {
        popDelay = setTimeout(function () {
            $("div[class=shareThisDD]").hide()
        }, 800)
    });
    $("div p.menu_head").click(function () {
        $(this).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("medium")
    });
    $("input.searchBox, input.searchButton").bind({
        mouseenter: function () {
            if (searchTimer != null) clearTimeout(searchTimer);
            $("input.searchButton").show().fadeTo(200, 1.0)
        },
        mouseout: function () {
            if (!$("input.searchButton").is(":hidden") && searchHasFocus == false) {
                searchTimer = setTimeout(function () {
                    $("input.searchButton").fadeTo(200, 0).hide(100)
                }, 300)
            }
        },
        click: function () {
            if (searchTimer != null) clearTimeout(searchTimer);
            if ($("input.searchButton").is(":hidden")) {
                window.setTimeout(function () {
                    $("input.searchButton").show().fadeTo(200, 1.0)
                }, 100)
            };
            searchHasFocus = true
        },
        blur: function () {
            $("input.searchButton").fadeTo(200, 0).hide(100);
            searchHasFocus = false
        }
    });
	$("#menu>li").mouseenter(function(){
		$(this).find("div.ddl").slideDown(200)
	}).mouseleave(function(){
		$(this).find("div.ddl").hide()
	});
});
function showBigSubNav() {
    document.getElementById("big-subnav").style.display = "inline"
};

function hideBigSubNav() {
    document.getElementById("big-subnav").style.display = "none"
}
