var $followBannerVisible = true;
var $followSelection;
var $firstRun = true;
var $followArray = ["follow", "contact", "disclaimer", "legal"];
var $arrowPosArray = [140, 293, 474, 692, 838];
var $bottomArrowPosArray = [220, 468, 715];


$(document).ready(function(){
	initUpperBanner();
	initImageFade();
	
	//setup follow banner
	$(".followDiv").hover(function() {
		$(this).find("#bounceImage").animate({
			top: -8
		}, 200);
	}, function() {
		$(this).find("#bounceImage").animate({
			top: 0
		}, 200);
	});
	showFollow();
	$(".horizontalFollowBanner").hide();
	$("#upArrow").hide();
	
	$("#galleryImage").bind("contextmenu", function(e) {
		return false;
	});
	$('#galleryImage').bind('dragstart', function(event) { event.preventDefault(); });
});

function initUpperBanner() {
	var $arrowBool = (parseInt($("#downArrow").attr("title")) != -1) ? true : false;
	if($arrowBool)
		$("#downArrow").css("left", $arrowPosArray[$("#downArrow").attr("title")]);
	else
		$("#downArrow").hide();
	$("li.forNavigation").hover(function() {
		$(this).css("background-color", "#999999");
		if(!$arrowBool)
			$("#downArrow").show();
		$("#downArrow").css("border-top", "20px solid #999999");
		var $dArrowTo = $arrowPosArray[$(this).attr("id")];
		$("#downArrow").css("left", $dArrowTo);
	}, function() {
		$(this).css("background-color", "#656565");
		$("#downArrow").css("border-top", "20px solid #656565");
		if ($arrowBool) {
			var $dArrowTo = $arrowPosArray[$("#downArrow").attr("title")];
			$("#downArrow").css("left", $dArrowTo);
		} else {
			$("#downArrow").hide();
		}
	})
	
	$("li.forBottomNavigation").hover(function() {
		$(this).css("background-color", "#999999");
		$("#upArrow").css("border-bottom", "20px solid #999999");
		var $uArrowTo = $bottomArrowPosArray[$(this).attr("id")];
		$("#upArrow").css("left", $uArrowTo);
		$("#upArrow").show();
	}, function() {
		$(this).css("background-color", "#656565");
		$("#upArrow").css("border-bottom", "20px solid #656565");
		var $uArrowTo = $bottomArrowPosArray[$("#upArrow").attr("title")];
		$("#upArrow").css("left", $uArrowTo);
		if(!$followBannerVisible)
			$("#upArrow").hide();
	})
	
	$(".rightColumn").hover(function() {
		$("#hoverImage").animate({
			top: -8
		}, 200)
	}, function() {
		$("#hoverImage").animate({
			top: 0
		}, 200)
	});
	
	$(".forBottomNavigation").click(function() {
		$firstTime = false;
		$("#upArrow").attr("title", $(this).attr("id"));
		showFollow($(this).attr("title"));
	});
}

function initImageFade() {
	$("div.navigation").hover(function() {
		$(this).fadeTo(300,.7);
	}, function() {
		$(this).fadeTo(200,1);
	});
}

function showFollow(_id){
	if ($followSelection == _id || $followBannerVisible == false)
		$followBannerVisible = !$followBannerVisible;
	$followSelection = _id;

	jQuery.each($followArray, function() {
		$("." + this + "Container").hide();
	});
	
	if ($followBannerVisible) {
		jQuery.each($followArray, function() {
			if(this == _id)
				$("." + this + "Container").show();
		});
		$("#upArrow").show();
		$("#followBanner").append('<span class="fold" id="foldTopLeft"></span><span class="fold" id="foldTopRight"></span>')
		$(".horizontalFollowBanner").slideDown();
		if (!$firstRun) {
			$("html, body").animate({
				scrollTop: $(document).height()
			}, 1000);
		}
	} else {
		$firstRun = false;
		$("#upArrow").hide();
		$(".horizontalFollowBanner").slideUp();
		$("#upArrow").attr("title", 1);
	}
}

