/* 
 * Author: Krzemo Karpinski (krzemo.karpinski@gmail.com)
 * 
 */
Cufon.replace('header h2 span',{fontFamily: 'aauxprolight'});

$(document).ready(function(){
	$('#menuwrapper').css('height', $('#main').innerHeight());
	  var msie6 = $.browser == 'msie' && $.browser.version < 7;
	  if (!msie6) {
	    var top = $('#menu').offset().top - parseFloat($('#menu').css('margin-top').replace(/auto/, 0));
	    $(window).scroll(function (event) {
	      var y = $(this).scrollTop();

	      if (y >= top - 10) {
	        $('#menu').addClass('fixed');
	      } else {
	        $('#menu').removeClass('fixed');
	      }
	    });
	  }
	$('#menu a.mcategory').hover(function(){
		$(this).css('backgroundPosition', '-9999px center');
	}, function() {
		$(this).css('backgroundPosition', 'left center');		
	});
	$('header h2').hover(function() {
		$('header h1').addClass('animated');
	}, function() {
		$('header h1').removeClass('animated');
	});
	$('#psp a').click(function() {
		$('#psp a').removeClass('selected');
		$(this).addClass('selected');
		$('select#product_id option').eq($(this).index()).attr('selected', true);
		if($('input#product_cart_quantity').val() == '') $('input#product_cart_quantity').val('1');
		return false;
	});
	if($('select#product_id option:selected').index() > 0)
	{
		$('#psp a').eq($('select#product_id option:selected').index() - 1).addClass('selected');
	}
	$('input#product_cart_quantity').keyup(function(){
		var isInt = /^\d+$/.test($(this).val());
		if($(this).val() != '')
		{
			if(!isInt)
			{
				$(this).val(1);
				$('#flash_messages').html('').append('<p class="flash error int">Please enter valid number of pieces</p>');
			}
			else
			{
				$('#flash_messages p.int').remove();
				if($(this).val() > 5)
				{
					$(this).val(5);
					$('#flash_messages').html('').append('<p class="flash error max">We are sorry but you can order 5 pieces maximum</p>');				
				}
				else
				{
					$('#flash_messages p.max').remove();
				}
			}
		}
	});
	$('input#product_cart_quantity').change(function(){
		if($(this).val() == '')
		{
			$(this).val(1);
		}
	});
});
