//document ready function
var popid;
$(document).ready(function() {

	// Handle content rotation in the bottom left ad area
	$("#rotate1").css("display", "none");
	$("#forwardback").css("visibility", "visible");
	var currentRotateImage = Math.floor(Math.random() * 6) + 1;
	$("#rotate" + currentRotateImage).css("display", "block");

	$("#rotatelast").click(function() {
		$("#rotate" + currentRotateImage).css("display", "none");
		currentRotateImage--;
		if (currentRotateImage == 0) {
			currentRotateImage = 6;
		}
		$("#rotate" + currentRotateImage).css("display", "block");
		$(".onofflight:last").after($(".onofflight:first"));
	});

	$("#rotatenext").click(function() {
		$("#rotate" + currentRotateImage).css("display", "none");
		currentRotateImage++;
		if (currentRotateImage == 7) {
			currentRotateImage = 1;
		}
		$("#rotate" + currentRotateImage).css("display", "block");
		$(".onofflight:first").before($(".onofflight:last"));
	});

	//product rollover on default page

	$("#lineuplink").hover(
		function() {
			$(this).css("background-image", $(this).css("background-image").replace("_off", "_on"));
			if (($.browser.msie) && (parseInt(jQuery.browser.version) < 7)) {
				$(this).css('filter', $(this).css('filter').replace(/_off/, "_on"));
			}
		},
		function() {
			$(this).css("background-image", $(this).css("background-image").replace("_on", "_off"));
			if (($.browser.msie) && (parseInt(jQuery.browser.version) < 7)) {
				$(this).css('filter', $(this).css('filter').replace(/_on/, "_off"));
			}
		}
	);

	//popup info for lineup page
	$(".prodpop").append("<span>[ x ]</span>");
	$(".prodpop span").click(function() {
		$(this).parent().css("display", "none");
		$('#' + popid.substr(0, (popid.length - 4))).mouseout();
	});

	$(".prodlink").click(function() {
		popid = $(this).attr("id") + "_pop";
		$(".prodpop").css("display", "none");
		$("#" + popid).css("display", "block");
		return (false);
	});
	
	//lineup page hover effect
	var t;
	$(".prodlink").hover(
		function() {
			clearTimeout(t);
			$(this).children("img:not(#sgImage)").attr("src", $(this).children("img").attr("src").replace("_off", "_on"));
			if (($.browser.msie) && (parseInt(jQuery.browser.version) < 7)) {
				$(this).children("img:not(#sgImage)").css('filter', $(this).children("img").css('filter').replace(/_off/, "_on"));
			}
			$(this).click();
		},
		function() {
			$(this).children("img:not(#sgImage)").attr("src", $(this).children("img").attr("src").replace("_on", "_off"));
			if (($.browser.msie) && (parseInt(jQuery.browser.version) < 7)) {
				$(this).children("img:not(#sgImage)").css('filter', $(this).children("img").css('filter').replace(/_on/, "_off"));
			}
			$(this).delay(1000, function() {
				$("#" + popid).hide();
			});
			
			// hack //
			$('#' + popid).hover(
			function() {

				clearTimeout(t);
				$('#' + popid.substr(0, (popid.length - 4))).mouseover();

			},
			function() {
				clearTimeout(t);
				$("#" + popid).delay(1000, function() {
					$('#' + popid.substr(0, (popid.length - 4))).mouseout();
				});
			}
			);

		}
	);

	$.fn.delay = function(time, func) {
		t = setTimeout(func, time);
		return t;
	}

	//determine which person's info to view on testimonial page
	//alert($(".userinfo").length);
	if (location.search.search("user") != -1) {
		var userName = location.search.replace("?user=", "");
		if ($("#" + userName + ".userinfo").length == 1) {
			$(".userinfo").removeClass("youcantseeme").addClass("youcantseeme");
			$("#" + userName).removeClass("youcantseeme");
		}
	}

	//IE6 png fix
	if (($.browser.msie) && (parseInt(jQuery.browser.version) < 7)) {
		$("img[src$=.png], #lineuplink").css("behavior", "url(js/iepngfix.htc)");
		$(".prodpop").wrapInner($("<div></div>"));
	}
	//IE6 png rollover fix
});
