// functions for shoppingbank.com - sept 2009

// expanding menu category 

$(function() {
	$("#marketPlaceCategoriesTab").click(function() {
		$('#marketplaceCategories').slideDown('slow');
		addAutoHide("#marketplaceCategories"); 
	});

	$("#marketplaceCategories #marketplaceCategoriesClose").click(function() {
		$('#marketplaceCategories').slideUp('slow');
	});
});

$(function() {
	$("#marketPlaceBrandsTab").click(function() {
		$('#marketplaceBrands').slideDown('slow');
		addAutoHide("#marketplaceBrands"); 
	});

	$("#marketplaceBrands #marketplaceBrandsClose").click(function() {
		$('#marketplaceBrands').slideUp('slow');
	});
});

$(function() {
	$("#marketPlaceStoresTab").click(function() {
		$('#marketplaceStores').slideDown('slow');
		addAutoHide("#marketplaceStores"); 
	});

	$("#marketplaceStores #marketplaceStoresClose").click(function() {
		$('#marketplaceStores').slideUp('slow');
	});
});

$(function() {
	$("#marketPlacePartnersTab").click(function() {
		$('#marketplacePartners').slideDown('slow');
		addAutoHide("#marketplacePartners"); 
	});

	$("#marketplacePartners #marketplacePartnersClose").click(function() {
		$('#marketplacePartners').slideUp('slow');
	});
});

$(function() {
	$("#showmoreinfoTab").click(function() {
		$('#showmoreinfoDiv').slideDown('slow');
		addAutoHide("#showmoreinfoDiv"); 
	});

	$("#showmoreinfoDiv #showmoreinfoClose").click(function() {
		$('#showmoreinfoDiv').slideUp('slow');
	});
});

function addAutoHide(element) {
	var t;
	
	$(element).hover(function() {
		clearTimeout(t)
	}, function() {
		t = setTimeout(function() {$(element).slideUp()}, 2000);
	});
}


// horizontal scroller

$(function() {
	//$("div.horizontalScroll").smoothDivScroll({scrollingSpeed: 5, mouseDownSpeedBooster: 3, visibleHotSpots: "always", autoScroll:"onstart", autoScrollDirection:"endlessloop"});
	$(".horizontalScroll.autoScroll").smoothDivScroll({scrollingSpeed: 5, mouseDownSpeedBooster: 3, visibleHotSpots: "always", autoScroll: "always", autoScrollDirection: "backandforth", pauseAutoScroll: "mouseover", countOnlyClass: ".entry"});
	$(".horizontalScroll.manualScroll").smoothDivScroll({scrollingSpeed: 5, mouseDownSpeedBooster: 3, visibleHotSpots: "always", countOnlyClass: ".entry", rows: 2});
});


// from footer.js - microsite functions

$(document).ready(function() {
	$('#micrositeFader').fadeTo(10, 0.0);
	$(".microsite").fadeIn(1500);

	// On any appropriate link, check for microsite
	$(".micrositeCheck").click(function() {
		var location = this.href;
		if (location.indexOf("/microsite/") > 0) {
			showMicrositeFrame(location);
			return false;
		}
		
		window.location = location;
		return false;
	});
});

function micrositeCheck(location) {
	if (location.indexOf("/microsite/") > 0) {
		showMicrositeFrame(location);

		return false;
	}
	window.location = location;
	return false;
}
		
function showMicrositeFrame(location) {
	var mc = $("#micrositeControl");
	var offset = mc.offset();

	$("#micrositeFrame").css("left", (offset.left + 5) + "px");
	
	mc.addClass("popup")
		.find("iframe:first")
			.queue(function() {
				this.src = location;
				$(this).dequeue();
			})
			.end()
		.find('#micrositeFader')
			.fadeTo("fast", 0.5)
	;
}

function hideMicrositeFrame() {
	$("#micrositeControl")
		.find('#micrositeFader')
			.fadeTo("fast", 0.0, function() {
				$('#micrositeControl')
					.removeClass("popup")
					.find("iframe:first")
						.queue(function() {
							this.src = "about:blank";
							$(this).dequeue();
						})
				;
			})
	;
}


// hover tooltip popup effect on productcells

$(function() 
{
	$(".entry").hover(
		function() {
			var txt = $(".hiddenDetails", this).attr("innerHTML");
					
			if (txt) {
				var offset = $(this).offset();
				var detailSection = $("#detailSection"); 
				detailSection.attr("innerHTML", txt);
				$("#detailSection").css("left", (offset.left + 80) + "px");
				$("#detailSection").css("top", (offset.top + 120) + "px");
				$("#detailSection").css("z-index", (10));
				$("#detailSection").show();
			}
		},
		function(evt) {
			// Check whether the mouse is still over the tooltip
			if ($("#detailSection").length > 0) {
				var detailSection = $("#detailSection"); 
				var offset = detailSection.offset();
				if ((evt.pageX >= offset.left) 
					&& (evt.pageX < (offset.left + detailSection.width()))
					&& (evt.pageY >= offset.top) 
					&& (evt.pageY < (offset.top + detailSection.height()))) {
					return false; // It is
				} else {
					detailSection.hide();
				}
			}
		});

	$("#detailSection").hover(
		function() {}, 
		function() {
			$(this).hide();
		});
	
});

