function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
	}
	});
	group.height(tallest);
}

function marginTop(group2) {
	all_height = 0;
	group2.each(function() {
		this_height = $(this).height();
		all_height = all_height + this_height;
	});
}

$(document).ready(function ()
{
	$('#payment_bar .left').click(function(){
		var position = $("#payment_bar .cont ul").position();
		if(position.left<0)
			$("#payment_bar .cont ul").animate({left: "+=100px"}, 400);
		else
			$("#payment_bar .cont ul").animate({left: "-=1400px"}, 800);
		
	});
	$('#payment_bar .right').click(function(){
		var position = $("#payment_bar .cont ul").position();
		if(position.left>-1400)
			$("#payment_bar .cont ul").animate({left: "-=100px"}, 400);
		else
			$("#payment_bar .cont ul").animate({left: "+=1400px"}, 800);
		
	});
	
	/*equalHeight($(".u_kol"));	*/
	that_height = $("#main2").height();
	marginTop($(".u_hai"));
	
	temp = $(".ten").height();
	margin_top = that_height - all_height - temp;
	if (margin_top > 0){
		margin_top = margin_top + 81;
		$(".ten").css("margin-top",margin_top+"px")
	}
	
	$('#select_producer').sSelect({ddMaxHeight: '200px'});	
	$('#select_producer').change(function ()
	{
		location.href = $(this).val();
		
		return false;
	});
	
	$('.radio').change(function(){  
		if($(this).is(":checked"))
		{ 
			$(".selected:not(:checked)").removeClass("selected"); 
			$(this).next("label").addClass("selected");
		}
		
		//return false;
	});	
	
	
	$('#product_desc .image a, #product_desc .smallimages a').fancybox();
	
	$('input[rel=clearDefault][type=text]').focus(clearIfDefaultValue = function ()
	{
		input = $(this);
		
		if(input.val()==input.attr('defaultValue'))
		{
			input.val('');
		}
	});
	
	$('input[rel=clearDefault][type=text]').blur(function ()
	{
		input = $(this);
		
		if(input.val()=='')
		{
			input.val(input.attr('defaultValue'));
		}
	});
	
	$('input[rel=clearDefault][type=text]').parents('form').submit(function ()
	{
		$('input[rel=clearDefault][type=text]', this).each(clearIfDefaultValue);
	});
	
	
	
	
	$('input.dynamicLabel').focus(function ()
	{
		input = $(this);
		
		input.prev('label').hide();
	});
	
	$('input.dynamicLabel').blur(hideDynamicLabelsIfNoEmpty = function ()
	{
		input = $(this);
		
		if(input.val()=='')
		{
			input.prev('label').show();
		}
	});
	
	$('input.dynamicLabel').each(function ()
	{
		input = $(this);
		
		if(input.val()!='')
		{
			input.prev('label').hide();
		}
	});
	
	
	$('#panel_menu ul li ul').hide();
	$('#panel_menu ul li.active ul').show();
	
	$('#panel_menu ul li > a').click(function ()
	{
		a = $(this);
		
		if(a.parent().find('ul').length==0 || a.parent().find('ul:visible').length)
		{
			return;
		}
		
		$('#panel_menu ul li').removeClass('active');
		$('#panel_menu ul li ul').slideUp();
		a.parent().addClass('active');
		a.parent().find('ul').slideDown();
		
		return false;
	});
	
	
	$('.filters .tabs a').click(function ()
	{
		var link = $(this);
		
		$('.filters .tabs a').removeClass('active');
		
		link.addClass('active');
		
		$('.filters div.man, .filters div.woman').hide();
		$('.filters div.' + link.attr('href').replace('#', '')).show();
		
		return false;
	});
	
	
	
	$('.gratises[rel!=]').each(function ()
	{
		var div = $(this);
		
		if(!div.attr('rel'))
		{
			return;
		}
		
		var params = div.attr('rel').split(',');
		
		var from = params[0];
		var to = params[1];
		var limit = params[2];
		
		$.get( 
			ApplicationHelper.url('gratis/get_gratises_in_current_currency_list/' + from + '/' + to + '/' + limit ) ,
			function(data)
			{
				div.removeAttr('rel');
				div.html(data);
	      	}
      	);
	});

	
	$('#gratis, .gratises').delegate('.gratisItems form a.submit', 'click', function ()
	{
		$(this).parents('form').submit();
		
		return false;
	});
	
	
	/*$('#gratis.gratis_cart .gratises').hide();
	$('#gratis.gratis_cart .gratises:first').show();
	
	
	$('#gratis.gratis_cart h2').click(function ()
	{
		
		$('#gratis.gratis_cart .gratises').slideUp();
		$(this).next('.gratises').slideDown();
	});
	*/
	//$('.opinions ul li').not(':first').hide();
	
	
	
});
