$(document).ready(function() {
	$('#homePage1Wrapper').bind('mouseenter', HomePage1Enter);
	$('#homePage1Wrapper').bind('mouseleave', HomePage1Leave);
	$('#homePage2Wrapper').bind('mouseenter', HomePage2Enter);
	$('#homePage2Wrapper').bind('mouseleave', HomePage2Leave);
	$('#homePage3Wrapper').bind('mouseenter', HomePage3Enter);
	$('#homePage3Wrapper').bind('mouseleave', HomePage3Leave);
	$('.productImageMedium').loupe({
		width: 300, // width of magnifier
		height: 250, // height of magnifier
		loupe: 'loupe' // css class for magnifier
	});
	
	// $(function() {
		// $(".manufacturerSlider").jCarouselLite({
			// btnNext: ".manufacturerSliderNext",
			// btnPrev: ".manufacturerSliderPrev",
			// circular: true,
			// visible: 1
		// });
	// });
	
	$(function() {
		$(".manufacturerSlider").jcarousel({
			scroll: 1,
			wrap: 'circular',
			buttonNextHTML: '<div class="manufacturerSliderNext"></div>',
			buttonPrevHTML: '<div class="manufacturerSliderPrev"></div>'
		});
	});

	
	ScrollContent();
	$('.manufacturerSlider').bind('mouseenter', manufacturerSliderEnter);
	$('.manufacturerSlider').bind('mouseleave', manufacturerSliderLeave);
	$('#logo').bind('mouseenter', LogoEnter);
	$('#logo').bind('mouseleave', LogoLeave);
	$('.productAsk').bind('click', AskStylist);
	$('.productTell').bind('click', TellFriend);
	$('#askStylistFormClose').bind('click', function(){ $("#askStylistFormWrapper").hide(); });
	$('#tellFriendFormClose').bind('click', function(){ $("#tellFriendFormWrapper").hide(); });
	Shadowbox.init({
		handleOversize: "drag"
	});
});

function HomePage1Enter()
{
	$('#homePage1Over').show();
	$('#homePage1Out').hide();
}

function HomePage1Leave()
{
	$('#homePage1Out').show();
	$('#homePage1Over').hide();
}

function HomePage2Enter()
{
	$('#homePage2Over').show();
	$('#homePage2Out').hide();
}

function HomePage2Leave()
{
	$('#homePage2Out').show();
	$('#homePage2Over').hide();
}

function HomePage3Enter()
{
	$('#homePage3Over').show();
	$('#homePage3Out').hide();
}

function HomePage3Leave()
{
	$('#homePage3Out').show();
	$('#homePage3Over').hide();
}

function ProductThumbClick(id)
{
	$(".productImage").addClass("productImagehidden");
	$("#productImage"+id).removeClass("productImagehidden");
}

function manufacturerSliderEnter()
{
	$(".manufacturerSliderOverlay").show();
}

function manufacturerSliderLeave()
{
	$(".manufacturerSliderOverlay").hide();
}

function LogoEnter()
{
	$("#logo a img").attr("src", "../images/logoOver.jpg");
}

function LogoLeave()
{
	$("#logo a img").attr("src", "../images/logoOut.jpg");
}

function AskStylist()
{
	$("#tellFriendFormWrapper").hide();
	$("#askStylistFormWrapper").show();
	return false;
}

function TellFriend()
{
	$("#askStylistFormWrapper").hide();
	$("#tellFriendFormWrapper").show();
	return false;
}

function ScrollContent() 
{
	if( parseInt($("#content-item").height()) > 200 )
	{
		$("#content-slider").slider({
			orientation: "vertical",
			range: "min",
			min: 0,
			max: 100,
			value: 100,
			animate: true,
			change: handleSliderChange,
			slide: handleSliderSlide
		});
	}
}

function handleSliderChange(e, ui)
{
	var maxScroll = $("#content-scroll").attr("scrollHeight") - $(".manufacturerDescription").height() + 50;
	$("#content-scroll").animate({scrollTop: maxScroll - ui.value * (maxScroll / 100) }, 1000);
}
function handleSliderSlide(e, ui)
{
	var maxScroll = $("#content-scroll").attr("scrollHeight") - $(".manufacturerDescription").height() + 50;
	$("#content-scroll").attr({scrollTop: maxScroll - ui.value * (maxScroll / 100) });
}
