﻿var Util = {};
Util.CartItems = 0;
Util.addToCart = function (imagePath, title, quantity, totalPrice) {
	Util.CartItems++;

	$(".address").hide();

	var cartProductThumbs = $(".cartProductThumbs");
	var img = $("<img />").attr("src", imagePath).attr("title", title + " (x" + quantity + ")");
	cartProductThumbs.prepend(img);

	$("#cartTotal").html(totalPrice);

	$(".shoppingCart").show();
	if ($("#basketCopy").is(":hidden")) {
		var basketContent = $(".shoppingCart").html();
	}
	else {
		var basketContent = $(".shoppingCart").eq(0).html();
	}
	$("#basketCopy").addClass("shoppingCart").html(basketContent).show();
};

Util.InitCart = function (cartItemsCount) {
	Util.CartItems = cartItemsCount;
	Util.CartThumPosition = 0;

	if (Util.CartItems != 0) {
		$(".heading").hide();
		$(".address").hide();
		$(".shoppingCart").show();
		var basketContent = $(".shoppingCart").html();
		$("#basketCopy").addClass("shoppingCart").html(basketContent).show();
	}
	else {
		$(".heading").animate({ opacity: 1 }, 1000, function () { $(".heading").hide(); $(".address").show(); });
	}


	$(".leftArrow").live('click', function () {
		if (Util.CartThumPosition > 0) {
			Util.CartThumPosition--;
			$('.cartProductThumbs').animate({ marginLeft: '+=37' }, 500, function () { });
		}
	});

	$(".rightArrow").live('click', function () {
		if (Util.CartThumPosition < (Util.CartItems - 6)) {
			Util.CartThumPosition++;
			$('.cartProductThumbs').animate({ marginLeft: '-=37' }, 500, function () { });
		}
	});

};

Util.InitBanners = function () {
	
	var buttons = { previous: $('#lofslidecontent45 .lof-previous'),
		next: $('#lofslidecontent45 .lof-next')
	};

	$('#lofslidecontent45').lofJSidernews({ interval: 4000,
		direction: 'opacitys',
		easing: 'easeInOutExpo',
		duration: 1200,
		auto: true,
		isPreloaded : false,
		maxItemDisplay: 4,
		navPosition: 'horizontal', // horizontal
		navigatorHeight: 32,
		navigatorWidth: 80,
		mainWidth: 840,
		buttons: buttons
	});
};

Util.BindProducts = function () {
	$("img.productImage").click(function () {
		var href = $(this).siblings(".productTitle").find("a").attr("href");
		document.location = href;
	});
};

Util.SetBackground = function () {
	$("body").addClass('background');
}

Util.Index = function () {
	Util.InitBanners();
	Util.SetBackground();
}


var MainMenu = {};

MainMenu.SetToggle = function () {
	$("ul.menu li.parent a").removeAttr("href");

	$("ul.menu li.parent").click(function () {
		var parentId = $(this).attr('rel');
		$("ul.menu li.child[ref='" + parentId + "']").slideToggle();
	});
};

MainMenu.SetActiveMenu = function (permalink) {
	var activeMenu = $("ul.menu li[rel='" + permalink + "']");
	activeMenu.find("a").addClass('active');
	var isChild = activeMenu.hasClass('child');
	if (isChild) {
		var parentId = activeMenu.attr('ref');
		$("ul.menu li[ref='" + parentId + "']").show();
		$("ul.menu li[rel='" + parentId + "'] a").addClass('active');
	}
};
