﻿//set animation hover function
$(document).ready(function() {
    $("#ctl00_SearchBar1_DLTypes img[src$='_noani.gif']").mouseover(function(event) {
        this.src = this.src.replace("_noani.gif", "_ani.gif");
    }).mouseout(function(event) {
        this.src = this.src.replace("_ani.gif", "_noani.gif");
    });
});
$(document).ready(function() {
    $("#ctl00_DLTypes2 img[src$='_noani.gif']").mouseover(function(event) {
        this.src = this.src.replace("_noani.gif", "_ani.gif");
    }).mouseout(function(event) {
        this.src = this.src.replace("_ani.gif", "_noani.gif");
    });
});
$(document).ready(function() {
    $("#CommentListView > div.comment:gt(3)").hide("fast");
    if ($("#CommentListView > div.comment").length > 4)
        $("#CommentA").show("fast");
});

function ShowAdds() {
    $("div.addl").css({ 'height': '160px', 'background-image': 'url(/images/banners/size/160x160.jpg)', 'display':'none' });
    $("div.addl").show("normal");
    $("div.addm").css({ 'height': '60px', 'width': '468px', 'background-image': 'url(/images/banners/size/468x60.jpg)', 'margin-top':'10px', 'display': 'none' });
    $("div.addm").show("normal");
    $("div.addr").css({ 'height': '350px','width':'160px', 'background-image': 'url(/images/banners/size/160x350.jpg)', 'display': 'none' });
    $("div.addr").show("normal");
}

function TipAFriend()
{
    var url = escape(location.href);
    var title = document.title.replace(/"/g, "\"");
    open("tipafriend.aspx?url=" + url + "&title=" + title,"tipafriend","height=550,width=550,location=0,menubar=0,toolbar=0,status=1"); 
}

var _displayElement = null;
var _recipeUrl = "";
var _quickViewTimer = null;
function ShowQuickView(lnk, t) {
    if (_quickViewTimer != null)
        clearTimeout(_quickViewTimer);
    if (_displayElement == null)
        _displayElement = $get("QuickView");
    var j = Sys.UI.DomElement.getLocation(lnk);
    _displayElement.style.left = (j.x + 25) + "px";
    _displayElement.style.top = (j.y - 150) + "px";
    _displayElement.innerHTML = "";
    _recipeUrl = lnk.parentNode.href.replace("frontpage.aspx?", "itempopup.aspx?cmd=0&").replace("plan=", "p=") + "&t=" + t;
    _quickViewTimer = setTimeout("GetRecipe()", 200);
}

function GetRecipe()
{
    var wRequest =  new Sys.Net.WebRequest();
    wRequest.set_url(_recipeUrl);
    wRequest.set_httpVerb("GET");
    //wRequest.set_userContext("user's context");
    wRequest.add_completed(OnWebRequestCompleted);
    wRequest.invoke();
}

function HideQuickView()
{
    if (_quickViewTimer != null)
        clearTimeout(_quickViewTimer);
    if (_displayElement != null)
    {
        _displayElement.style.display = "none";
        _displayElement.innerHTML = "";
    }
}

function ClearQuickView()
{
    if (_quickViewTimer != null)
        clearTimeout(_quickViewTimer);
    if (_displayElement != null)
        _displayElement.innerHTML = "";
    _displayElement = null;
}

function OnWebRequestCompleted(executor, eventArgs) 
{
    if(executor.get_responseAvailable()) 
    {
        DisplayWebRequestBody(executor);
    }
}

function DisplayWebRequestBody(executor)
{
    var responseData = executor.get_responseData() + "";
    responseData = responseData.substr(responseData.indexOf('<div id="ItemViewer1_ItemPanel" class="midtprint">'));
    responseData = responseData.substring(0, responseData.lastIndexOf("</div>"));
    _displayElement.innerHTML = responseData;
    _displayElement.style.display = "block";
    ReplaceDisplayElement();
    //pageTracker._trackPageview('/quickview');
}

function ReplaceDisplayElement()
{
    var htmlElm = document.getElementsByTagName("HTML")[0];
    var bottom = htmlElm.scrollTop + htmlElm.clientHeight;
    var b = Sys.UI.DomElement.getBounds(_displayElement);
    if (b.height < 300) {
        _displayElement.style.top = b.y + 100 + "px";
        b = Sys.UI.DomElement.getBounds(_displayElement);
    }
    if ((b.y + b.height) > bottom)
        _displayElement.style.top = ((b.height > htmlElm.clientHeight) ? htmlElm.scrollTop : (bottom - b.height)) + "px";
}