/* Solo Shopify Theme v1.0 (jQuery 1.3.1 required). Copyright (c) Pixellent, LLC <http://www.pixellent.com>. */

// Clear Inputs
$j.cleared = function(field) {
	if ($j(field).length > 0 ) {
		$j(field).each(function() {
			var text = $j(this).val();
			$j(this).focus(function() { if ($j(this).val() == text) { $j(this).val(''); }; });
			$j(this).blur(function() { if ($j(this).val() == '') { $j(this).val(text); }; });
		});
	};
	
};

// Slider
$j.slider = function(container, slider, prev, next) {
	
	//alert(next);
	if ($j(container).length > 0 ) {
		$j("div#prev a").addClass("inactive");
				
		var width = parseInt($j(slider + " li").length) * 116; // While changing the width of li, should also change the value of '216' to li width + 16.
		if ($j(slider + " li").length <= 7) { $j(next).addClass("inactive"); };
		
		$j(prev).unbind("click");
		$j(prev).click(function() {
			if ($j(prev).hasClass("inactive") || $j(prev).hasClass("disabled")) {
				return false;
			} else {
				$j(prev).addClass("disabled");
				var position = parseInt($j(slider).css("margin-left"));
				var move = (position + 890) + "px";
				$j(slider).animate({ marginLeft: move }, 1000, "easeInOutQuint", function() {
					var next_click = parseInt($j(slider).css("margin-left")) + 890;
					if (next_click > 0) { $j(prev).addClass("inactive"); };
					$j(next).removeClass("inactive");
					$j(prev).removeClass("disabled");
				});
			};
			return false;
		});
		
		$j(next).unbind("click");
		$j(next).click(function() {
			if ($j(next).hasClass("inactive") || $j(next).hasClass("disabled")) {
				return false;
			} else {
				$j(next).addClass("disabled");
				var position = parseInt($j(slider).css("margin-left"));
				var move = (position - 890) + "px";
				$j(slider).animate({ marginLeft: move }, 1000, "easeInOutQuint", function() {
					var next_click = parseInt($j(slider).css("margin-left")) + -890;
					if ((next_click + width) <= 0) { $j(next).addClass("inactive"); };
					$j(prev).removeClass("inactive");
					$j(next).removeClass("disabled");
				});
			};
			return false;
		});
		
	};
	
};

// Initialize page elements after the DOM is loaded
$j(document).ready(function() {
	$j.cleared("input.field");
	$j.slider("div#slider", "div#slider ul", "div#prev a", "div#next a");
//alert(document.getElementById("test").value);

var slidecount = (document.getElementById("test").value) / 7;
var slideround = Math.round(slidecount);
var slidercount = 0;
if(slideround < slidecount)
{
slidercount = slideround;
}
else if ((slideround > slidecount) || (slideround == slidecount))
{
slidercount = slideround - 1;
}

slidercount = slidercount - 1;

var width = (parseInt($j("div#slider ul" + " li").length)) * 116;
if ($j("div#slider ul" + " li").length < 7) { $j("div#next a").addClass("inactive"); };
				var position = parseInt($j("div#slider ul").css("margin-left"));
				var move = ((slidercount * -890) - 890) + "px";
				$j("div#slider ul").animate({ marginLeft: move }, 1000, "easeInOutQuint", function() {
					var next_click = parseInt($j("div#slider ul").css("margin-left")) + -890;
				});	

if (slidercount < 0)
{
$j("div#prev a").addClass("inactive");
$j("div#prev a").addClass("disabled");
}
else
{
$j("div#prev a").removeClass("inactive");
$j("div#prev a").removeClass("disabled");
}
});
