var FLfader = "";
var UAfader = "";
var jQ = jQuery.noConflict();
function toggleForgotPwd() {
    jQ("div#loginContent").toggle();
    jQ("div#forgotpasswordContent").toggle();
}

function textFocus(e) {
    var target = e.target;
    if (jQ(target).val() == "Search Here" || /*jQ(target).val() == "User Name" ||*/jQ(target).val() == "Email Address") {
        jQ(target).val("");
    }
}


function pwdFocus() {
    var $class = this.className;
    if ($class == "password") {
        //jQ("input#password").addClass("nobg");
    }
}

function textBlur(e) {
    var target = e.target;
    var myField = target.id;
    if (myField == "searchBox" && jQ(target).val() == "") {
        jQ("input#" + myField).val("Search Here");
    }
    else if (myField == "email" && jQ(target).val() == "") {
        jQ("input#" + myField).val("Email Address");
    }
    /*
    else if(myField == "password" || myField == "mbrUName")
    {
    if(!jQ(target).val() == "")
    {
    jQ(target).addClass("nobg");        
    }
    else
    {
    jQ(target).removeClass("nobg");
    }
    }
    */
}
function pwdBlur() {
    var $class = this.className;
    if ($class == "nobg") {
        //jQ("input#password").removeClass("nobg");
    }
}
function copyURL() {
    var $url = jQ("ul#FLUL li:visible a").attr('href');
    var $newURL = jQ("div#featuredlots div#FLnav a#FLinfo");
    $newURL.attr('href', $url);
}

function restartProgBar() {
    jQ("img#progbar").attr("src", "/wwwImages/FLprog.gif");
}

function FLnextAuto() {
    if (jQ("ul#FLUL li:visible").next().length) {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ(this).next().fadeIn();
            copyURL();
        });
        restartProgBar();
        startTimerSlow();
    }
    else {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ("ul#FLUL li:first").fadeIn();
            copyURL();
        });
        restartProgBar();
        startTimerSlow();
    }
}

function FLprevAuto() {
    if (jQ("ul#FLUL li:visible").prev().length) {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ(this).prev().fadeIn()
            copyURL();
        });
        restartProgBar();
        startTimerSlow();
    }
    else {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ("ul#FLUL li:last").fadeIn();
            copyURL();
        });
        restartProgBar();
        startTimerSlow();
    }
}

function FLnext() {
    if (jQ("ul#FLUL li:visible").next().length) {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ(this).next().fadeIn()
            copyURL();
        });
    }
    else {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ("ul#FLUL li:first").fadeIn();
            copyURL();
        });
    }
}

function FLprev() {
    if (jQ("ul#FLUL li:visible").prev().length) {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ(this).prev().fadeIn();
            copyURL();
        });
    }
    else {
        jQ("ul#FLUL li:visible").fadeOut(function() {
            jQ("ul#FLUL li:last").fadeIn();
            copyURL();
        });
    }
}

function FLright() {
    if (!jQ("ul#FLUL li").is(":animated")) {
        clearTimeout(FLfader);
        restartProgBar();
        FLnext();
    }
}

function FLleft() {
    if (!jQ("ul#FLUL li").is(":animated")) {
        clearTimeout(FLfader);
        restartProgBar();
        FLprev();
    }
}

function startTimerSlow() {
    if (jQ("ul#FLUL li").length > 1) {
        FLfader = setTimeout("FLnextAuto()", 13000);
    }
}

function UAnext() {
    if (jQ("div.UAitem:visible").next().length) {
        jQ("div.UAitem:visible").animate({
            top: "-100px",
            opacitcy: 0
        }, function() {
            jQ(this).hide().css("top", "0px");
        }).next().fadeIn();
        startTimerFast();
    }
    else {
        jQ("div.UAitem:last").animate({
            top: "-100px",
            opacitcy: 0
        }, function() {
            jQ(this).hide().css("top", "0px");
        });
        jQ("div.UAitem:first").fadeIn();
        startTimerFast();
    }
}

function UAprev() {
    if (jQ("div.UAitem:visible").prev().length) {
        jQ("div.UAitem:visible").animate({
            top: "100px",
            opacitcy: 0
        }, function() {
            jQ(this).hide().css("top", "0px");
        }).prev().fadeIn();
        startTimerFast();
    }
    else {
        jQ("div.UAitem:first").animate({
            top: "100px",
            opacitcy: 0
        }, function() {
            jQ(this).hide().css("top", "0px");
        });
        jQ("div.UAitem:last").fadeIn();
        startTimerFast();
    }
}

function startTimerFast() {
    if (jQ("div.UAitem").length > 1) {
        UAfader = setTimeout("UAnext()", 5000);
    }
}

function UAup() {
    if (!jQ("div.UAitem").is(":animated")) {
        clearTimeout(UAfader);
        UAnext();
    }
}

function UAdown() {
    if (!jQ("div.UAitem").is(":animated")) {
        clearTimeout(UAfader);
        UAprev();
    }
}

function accordion(e) {
    var target = e.target;
    if (target.tagName == "SPAN" || target.tagName == "IMG") {
        target = jQ(target).parent().get(0);
    }
    jQ(target).next('div:hidden').slideDown('slow').siblings('div:visible').slideUp('normal');
}

function openPanel(top) {

    jQ("div#forgotpasswordContent").hide();
    jQ("div#loginContent").show();
    
    
    var $panel = jQ("div#loginWrapper div#loginPanel");
    if (jQ($panel).css("top") != "0px") {
        jQ("div#loginWrapper").show(0);
        jQ($panel).animate({ top: "60px" }).animate({ top: "0px" }, "fast");
        jQ("ul#navigation a.login").removeClass("login").addClass("loginOpen");

        if (top.toString() != "") {
            document.getElementById('loginWrapper').style.top = top;
        }
    }
    else {
        jQ($panel).animate({ top: "60px" }, "fast").animate({ top: "-321px" }, function() {
            jQ("div#loginWrapper").hide(0);
        });
        jQ("ul#navigation a.loginOpen").removeClass("loginOpen").addClass("login");
    }

    //var $pnl = jQ("#loginWrapper");
    //jQ($pnl).css({ 'top': top });


    jQ('div#searchFilterMenu').hide();


}

function closeIt(e) {
    var target = e.target;
    jQ(target).parent().parent().parent().hide();
}

function closeFilter() {
    jQ("div.filterWrap").hide();
}

function bubble() {
    var distance = 10;
    var time = 500;
    var beingShown = false;
    var shown = false;
    content = "";
    content += "<div class='infoBubble clearfix'>";
    content += "<div class='bubbleTop left2'></div>";
    content += "<div class='bubbleBody left2'>";
    content += "<p>This auction will begin shortly. Please check back and refresh your browser to join the live bidding.</p>";
    content += "</div>";
    content += "<div class='bubbleBottom left2'></div>";
    content += "</div>";
    var $button = jQ('img.apStartingSoon');
    $button.before(content);
    var $bubble = jQ('div.infoBubble');
    $bubble.hide();
    $button.mouseover(function() {
        if (beingShown || shown) {
            return;
        } else {
            beingShown = true;
            $bubble.css({
                top: -100,
                display: 'block'
            })
			.animate({
			    top: '-=' + distance + 'px',
			    opacity: 1
			}, time, 'swing', function() {
			    beingShown = false;
			    shown = true;
			});
        }
    }).mouseout(function() {
        $bubble.animate({
            top: '-=' + distance + 'px',
            opacity: 0
        }, time, 'swing', function() {
            shown = false;
            $bubble.css('display', 'none');
        });
    });
}

jQ(function() {

    jQ("a.nowhere").attr("href", "javascript:void(0);");

    if (!(jQ.browser.msie && jQ.browser.version < 7)) {
        jQ('#navigation li')
				.removeClass('highlight').find('a.hot')
				.append('<span class="hover" />').each(function() {
				    var $span = jQ('> span.hover', this).css('opacity', 0);
				    jQ(this).hover(function() {
				        $span.stop().fadeTo(350, 1);
				    }, function() {
				        $span.stop().fadeTo(350, 0);
				    });
				});
    }

    if (jQ("ul#FLUL li").length > 1) {
        jQ("div#featuredlots").hover(function() {
            jQ("div#FLnav").stop().animate({ "top": "0" }, 250);
            clearTimeout(FLfader);
            jQ("img#progbar").hide();
        }, function() {
            jQ("div#FLnav").stop().animate({ "top": "-42px" }, 250);
            startTimerSlow();
            jQ("img#progbar").show();
            restartProgBar();
        });
    }

    if (jQ("div.UAitem").length > 1) {
        jQ("div#UAcontainer").hover(function() {
            clearTimeout(UAfader);
        }, function() {
            startTimerFast();
        });
    }
    else {
        jQ("div#UAnav").hide(); //hide UAnav if less than 2 items
    }

    jQ('div#filters div.filters a').click(function() {
        var filterContainers = jQ('div.filterWrap');
        if (jQ(filterContainers.filter(this.hash)).is(":hidden")) {
            filterContainers.hide().filter(this.hash).show();
            return false;
        }
    });

    jQ('img#btnSearchFilter').click(function() {
        window.location = "/catalog/advancedSearch.cfm?srchScope=p"
    });

    jQ(function() {
        var time = 1000;
        var hideDelay = 1000;
        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;
        var btnWidth = 110;
        var $btn = jQ('div#footer span#footerButtons a#btnSubscriptions img');
        var $pa = jQ('div#footer span#footerButtons a#btnPastAuctions');
        var $aa = jQ('div#footer span#footerButtons a#btnAuctionAlerts');
        var $fa = jQ('div#footer span#footerButtons a#btnFineArts');
        var $ft = jQ('div#footer span#footerButtons a#btnFreeTrial');
        var paWidth = $pa.width();
        var aaWidth = $aa.width();
        var faWidth = $fa.width();
        var offSet = 25;
        btnWidth += offSet;
        paWidth += offSet;
        aaWidth += offSet;
        faWidth += offSet;
        var $paEnd = btnWidth;
        var $aaEnd = paWidth + $paEnd;
        var $faEnd = aaWidth + $aaEnd;
        var $ftEnd = faWidth + $faEnd;

        jQ([$btn.get(0), $aa.get(0), $pa.get(0), $fa.get(0), $ft.get(0)]).hover(function() {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                return;
            } else {
                beingShown = true;
                $pa.animate({
                    left: '+=' + $paEnd + 'px',
                    opacity: 1
                }, time);
                $aa.animate({
                    left: '+=' + $aaEnd + 'px',
                    opacity: 1
                }, time);
                $fa.animate({
                    left: '+=' + $faEnd + 'px',
                    opacity: 1
                }, time);
                $ft.animate({
                    left: '+=' + $ftEnd + 'px',
                    opacity: 1
                }, time);
                shown = true;
            };
        }, function() {

            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function() {
                hideDelayTimer = null;
                shown = false;
                $pa.animate({
                    left: "0px",
                    opacity: 0
                }, time);
                $aa.animate({
                    left: "0px",
                    opacity: 0
                }, time);
                $fa.animate({
                    left: "0px",
                    opacity: 0
                }, time);
                $ft.animate({
                    left: "0px",
                    opacity: 0
                });
            }, hideDelay);
            beingShown = false;
        });
    });

    if (jQ("div#results div.resultsRight div.auctionButton img").hasClass("apStartingSoon")) {
        bubble();
    }

    jQ("ul#FLUL li:first").fadeIn(startTimerSlow);
    jQ("img#progbar").show().attr("src", "/wwwImages/FLprog.gif").css("opacity", "0.5");
    jQ("div.UAitem:first").fadeIn(startTimerFast);
    jQ("a#FLnext").click(FLright);
    jQ("a#FLprev").click(FLleft);
    jQ("a#UAup").click(UAup);
    jQ("a#UAdown").click(UAdown);
    jQ("input#searchBox, div#loginPanel input").focus(textFocus);
    jQ("div#loginPanel input#password").focus(pwdFocus);
    jQ("div#loginPanel input#password").blur(pwdBlur);
    jQ("input#searchBox, div#loginPanel input").blur(textBlur);
    jQ("a#forgotpassword, a#cancelForgotPwd").click(toggleForgotPwd);
    jQ("div#navContainer li#panel_button, div#loginWrapper div#loginPanel div.panel_button").click(openPanel);
    jQ('div.filterWrap > div').filter('.accordion').hide();
    jQ('div.filterWrap').click(accordion);
    jQ('div.filterWrap > h3 span.close').click(closeIt);
    jQ("div#filters, div#navContainer").click(closeFilter);
    if (jQ("ul#navigation li#panel_button a").hasClass("firstload")) {
        jQ("div#navContainer ul#navigation li#panel_button").trigger("click");
    }
    copyURL();
});



