$(document).ready(function()
{
	// Init pdBox
  $('.thickbox').pdBox({minWidth: 400});
  
  $('#oldWebThickbox').trigger('click');


  $('.brand-list :checkbox').bind('click', function(){
    if($(this).is('#prod1')){
      $(':checkbox:not(#prod1)').attr('checked', false);
      $(this).attr('checked', true);
    }
    else{
      var check = $('.brand-list input:not(#prod1):checked').size();
      if ( check > 0){$(':checkbox#prod1').attr('checked', false);}
      else{$(':checkbox#prod1').attr('checked', true);}
    }
  });
 

  $('.brand-list :checkbox').bind('click', function(){
    if($(this).is('#producerAll')){
      $(':checkbox:not(#producerAll)').attr('checked', false);
      $(this).attr('checked', true);
    }
    else{
      var check = $('.brand-list input:not(#producerAll):checked').size();
      if ( check > 0){$(':checkbox#producerAll').attr('checked', false);}
      else{$(':checkbox#producerAll').attr('checked', true);}
    }
  });

 $('.brand-list').each(function(){
    var elem = $(this);
    $('label a', this).bind('click', function(){
        $(':checkbox', elem).attr('checked', false);
        $(':checkbox', $(this).parents('.brand-item')).attr('checked', false);   
      });
  
  });

  //Vertical align
	$('.img-box, .product-list-weak .spc span').each(function(){
     var imgBoxH = $(this).height();
     $('img', this).each(function (){
       $(this).bind('load', function(){
        var imgH = $(this).height();
        $(this).css('margin-top', (imgBoxH - imgH) / 2 + 'px');
       }).attr('src', this.src);
     });
  });

  // Tabs
	$('.tabs-box').pdTabs();
	
	// GENERATE OFFER
	$('.generate-offer .generate').click(function(){
		var $this = $(this).parent();
		$this.html('');
		var prodID = $(this).attr('rel');
		$this.append('<div class="ico-dice"><input type="text" size="5" value="1" /><a href="ajax/order?prod='+prodID+'" class="btn-submit thickbox">Vygenerovat</a></div>')
		$('.thickbox').click(function(){
			var el = $(this).parent();
			var count = $('input', el).attr('value');
			var aHref = $(this).attr('href');
			$(this).attr('href', aHref+'&count='+count);
		}).pdBox({minWidth: 400});
		return false;
	});	
						
});

