﻿$(document).ready(function () {
	$('#searchbox #q').focus(function () {
		if ($(this).val() == "Search") $(this).val('');
		else $(this).select();
	});
	$('#searchbox #q').blur(function () {
		if ($(this).val() == "") $(this).val('Search');
	});
	$('#searchform').submit(function () {
		if ($('#q').val() == "Search") {
			$('#q').focus();
			return false;
		}
	});
	$('.topmenuitem').mouseover(function (e) {
		var src = $(this).attr('src');
		$(this).attr('src', $(this).attr('oversrc'));
		$(this).attr('oversrc', src);
	});
	$('.topmenuitem').mouseout(function (e) {
		var src = $(this).attr('src');
		$(this).attr('src', $(this).attr('oversrc'));
		$(this).attr('oversrc', src);
	});
});

// preload
//if (document.images) { pic1 = new Image(149, 29); pic1.src = "images/nav/nav_02_over.jpg"; }


var productRotationId = 0;
var maxRotation = 0;

function setProductRotation(direction) {
	productRotationId += direction;
	findMaxRotation();
	
	if (productRotationId < 0) productRotationId = 0;

	if ((productRotationId * 3) >= maxRotation) productRotationId--;

	rotateProducts();
}

function rotateProducts() {
	findMaxRotation();
	var i = 0;

	$("#productrotationtable").find("tr").hide();


	var rotateId = 3 * productRotationId;


	if (rotateId < maxRotation) {
		$("#productrotation_" + rotateId).show();
		rotateId++;
	}

	if (rotateId < maxRotation) {
		$("#productrotation_" + rotateId).show();
		rotateId++;
	}

	if (rotateId < maxRotation) {
		$("#productrotation_" + rotateId).show();
		rotateId++;
	}

	if (rotateId <= 3)
		$("#prevProduct").html("&nbsp;");
	else
		$("#prevProduct").html("<img id=\"productrotateback\" src=\"/Content/images/arrow_lft_over.jpg\" onclick=\"setProductRotation(-1);\" onmouseover=\"rollover(this.id);\" onmouseout=\"rollover(this.id);\" style=\"cursor: pointer;\" /><a id=\"productrotateback2\" href=\"javascript:setProductRotation(-1)\">back</a>");

	if (rotateId < maxRotation)
		$("#nextProduct").html("<a id=\"productrotateforward2\" href=\"javascript:setProductRotation(1);\">next</a>&nbsp;<img id=\"productrotateforward\" src=\"/Content/images/arrow_rt_over.jpg\" onclick=\"setProductRotation(1)\" onmouseover=\"rollover(this.id);\" onmouseout=\"rollover(this.id);\" style=\"cursor: pointer;\" />");
	else
		$("#nextProduct").html("&nbsp;");
}

function findMaxRotation() {

	var i = 0;

	$("#productrotationtable").find("tr").each(function(){
		i++;
	});

	maxRotation = i;
}


function rotateArticles() {

}

function rollover(id) {
	var image = $("#" + id);
	if (image.attr("src").indexOf("_over") != -1) {
		image.attr("src", image.attr("src").replace("_over", "_off"));
	}
	else {
		image.attr("src", image.attr("src").replace("_off", "_over"));
	}
}

