$(document).ready(function() {
	
	$('.pd_top').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow','swing');
	});
	
	$('#pd_bes').click(function(){
		$('html, body').animate({scrollTop: $('#pd_bes2')[0].offsetTop+150}, 'slow','swing');
	});
	
	$('#pd_akc').click(function(){
		$('html, body').animate({scrollTop: $('#pd_akc2')[0].offsetTop+150}, 'slow','swing');
	});

	$('#pd_kup').click(function(){
		$('html, body').animate({scrollTop: $('#pd_kup2')[0].offsetTop+150}, 'slow','swing');
	});

    if($('.compare')!=null)
        $('.compare').unbind();
	
	
if($('.compare')!=null)
    $('.compare').click(function(){
	    
	    $('html, body').animate({scrollTop:0}, 'slow','swing');
 
        $.ajax({
          type: "GET",
          url: "index.php?do=ajax&action=add_to_compare&product_id="+$(this).attr('rel'),
          success: function(msg){
             
             $('.compare_inner').remove();
             $('#compare_box').html(msg);
            

             if($('.compare_inner').hasClass('hidden')){
                 $('.compare_inner').removeClass('hidden')
             };


            
          }
        });
        return false;
    });
    
if($('.delete_from_compare')!=null)
    $('.delete_from_compare').click(function(){
        id=$(this).val();

        $.ajax({
          type: "GET",
          url: "index.php?do=ajax&action=delete_from_compare&product_id="+id,
          success: function(msg){
              $('.compare_inner').remove();
              $('#compare_box').html(msg);


              //$('#box_compare_'+id ).remove();
             //obj=$('#add_to_compare_clone').clone();
          }
        });
    });

if($('.compare_window')!=null)
    $('.compare_window').click(function() {
      var w2=window.open('/porownaj','porownaj');

    });

function reloadPorownaj(){
    
    var compare_window_guard=null;
    $.ajax({
          type: "GET",
          url: "index.php?do=ajax&action=check_compare_window_guard",
          success: function(msg){

            compare_window_guard=msg;

             if(compare_window_guard==1){
                 w = window.open('/porownaj','porownaj');
                 if (w && !w.closed) w.location.reload(true);
                 else w.close();
              }
          }
    });
};

 

});
