//Global Vars
var jQ = jQuery.noConflict();
var lastStartRow;
var FLfader = "";
var UAfader = "";

var frVar = "FALSE";

function toggleForgotPwd()
	{
		jQ("div#loginContent").toggle();
		jQ("div#forgotpasswordContent").toggle();
	}

function textFocus(e)
	{
		var target = e.target;
		if (jQ(target).val() == "Recherche dans les ventes à venir") {
			jQ(target).val("");
			frVar = "TRUE";
		}
		if(jQ(target).val() == "Search Upcoming Auctions" || jQ(target).val() == "Search Forthcoming Auctions" || jQ(target).val() == "Email Address")
			{
				jQ(target).val("");
			}
	}
 
function textBlur(e)
	{
	var target = e.target;
	var myField = target.id;
	if(myField == "searchBox" && jQ(target).val() == "")
		{
			if(document.domain.match("artfact") && frVar == "FALSE")
				{
					jQ("input#"+myField).val("Search Upcoming Auctions");
				}
			else if (document.domain.match("artfact") && frVar == "TRUE") {
				jQ("input#"+myField).val("Recherche dans les ventes à venir");
			}
			else
				{
					jQ("input#"+myField).val("Search Forthcoming Auctions");
				}
		}
	if(myField == "nwsltremail" && jQ(target).val() == "")
		{
			jQ("input#"+myField).val("Email Address");
		}
	}

// Artfact FR Page JS  ----------------------------------------------------//

//-------------------------------------------------------------------------//

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 startTimerSlow()
	{
		if(jQ("ul#FLUL li").length > 1)
			{
				FLfader = setTimeout(FLnextAuto, 13000);	
			}
	}
	
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 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);
			}else{
				$target = jQ(target);
			}
		
		var $target = jQ(target);
		if ('!$target.next.css("display","none")')
			{
				$target.next('div:visible').slideUp('normal');
			}
		$target
		.next('div:hidden').slideDown('slow')
		.siblings('div:visible').slideUp('normal');
	}

function openPanel()
	{
		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 ( jQ.browser.msie && jQ.browser.version == 8)
				{
					jQ("div#featuredlots").css("visibility","hidden");
				}
			}
		else
			{
				if ( jQ.browser.msie && jQ.browser.version == 8)
				{
					jQ("div#featuredlots").css("visibility","visible");
				}
				jQ($panel).animate({top: "60px"}, "fast").animate({top: "-321px"}, function(){
					jQ("div#loginWrapper").hide(0); 
				});
				jQ("ul#navigation a.loginOpen").removeClass("loginOpen").addClass("login");
			}
		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');
		});
	});
}

// The function below, is used to slide footer links out from "behind" the 'Subscribe'
// button in the footer
function footerSubscribeButton()
	{
		var time = 300;
		var hideDelay = 750;
		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');
		$target = jQ('div#footer span#footerButtons a#btnSubscriptions img,div#footer span#footerButtons a#btnPastAuctions,div#footer span#footerButtons a#btnAuctionAlerts,div#footer span#footerButtons a#btnFineArts,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;
		
		$target.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;
		});			
	}

jQ(function(){
	
	jQ("a.nowhere").attr("href", "javascript:void(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";
	});
	
	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, #newslettersignup input").focus(textFocus);
	jQ("input#searchBox, div#loginPanel input, #newslettersignup 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();
	footerSubscribeButton();

});