$.alert = function(text, title){
	 $("#boxcontent").html(text);
	 $('#overlay').fadeIn('fast',function(){
         $('#box').animate({'top':'160px'},500);
     });
}

$(document).ready(function() { 
	/*place jQuery actions here*/ 
	var link = "/";
	
	
	$("table.termekek form").submit(function() {
		// Get the product ID and the quantity 
		var id = $(this).find('input[name=product_id]').val();
		var qty = $(this).find('input[name=db]').val();

      $.ajax({
        url: 'termekek/add_cart_item',
        type: 'POST',
        data: 'product_id='+id+'&quantity='+qty+'&ajax=1',
        success: function(data){
          if(data == 'true')
          {

            $('#tooltip_text').text('Termék bekerült a kosárba.');
            if($('#tooltip_text').html().length > 0) {
                setTimeout(function(){$.alert($('#tooltip_text').html());},500);
            }

            $.post(link + "termekek/show_cart_total", function(cart){

              $("#kosar").html(cart);
            });
          }else{
            alert("Termék nem létezik az adatbázisban!");
          }
        }
      });

     /*$.post(link + "termekek/add_cart_item", { product_id: id, quantity: qty, ajax: '1' },
  			function(data){
  			
  			if(data == 'true'){

          $('#tooltip_text').text('Termék bekerült a kosárba.');
          if($('#tooltip_text').html().length > 0) {
              setTimeout(function(){$.alert($('#tooltip_text').html());},500);
          }
    			
    			$.post(link + "termekek/show_cart_total", function(cart){
		
  					$("#kosar").html(cart);
          });
    		}else{
    			alert("Termék nem létezik az adatbázisban!");
    		}	
    		
 		 });*/

		return false;
	});
	
	$(".empty").live("click", function(){
    	$.get(link + "termekek/empty_cart", function(){
    		$.get(link + "termekek/show_cart", function(cart){
  				$("#cart_content").html(cart);
			});
		});
		
		return false;
    });

    $('#boxclose').click(function(){
        $('#box').animate({'top':'-500px'},500,function(){
            $('#overlay').fadeOut('fast');
        });
    });

	
	
	
});
