var purchased=new Array();
var totalprice=0;

$(document).ready(function(){	
	$(".product img").draggable({
	
	containment: 'document',
	opacity: 0.6,
	revert: 'invalid',
	helper: 'clone',
	zIndex: 4000
	
	});

  if ($.cookie('params') != null)
  {    
    totalprice=parseInt($.cookie('total'));
  }  
  $('#count').html(totalprice);

  $(".product img").click(function(event) {
    addlist(event.target.id);
  });
					
  
  $(".removelink").click(function(event) {    
    $(this).parent().parent().remove();
    var y = $.cookie('params').split(',');
    var removeItem = $(this).parent().attr('id');
    y.splice( $.inArray(removeItem,y) ,1 );
    var s = "";    
    $.cookie('params', null);
    $.cookie('params', y, { expires: 7, path: '/', domain: ".littlepinkbook.co.za" });
    $('#formpostids').val(y);
    var total=$.cookie('total');
    total--;
    $.cookie('total', total, { expires: 7, path: '/', domain: ".littlepinkbook.co.za" });
    $('#count').html(total);    
  });

	$("div.content.drop-here").droppable({	
    drop:
    function(e, ui)
    {
    	var param = $(ui.draggable).attr('id');
    	
    	if($.browser.msie && $.browser.version=='6.0')
    	{
    		param = $(ui.draggable).attr('style').match(/src=\"([^\"]+)\"/);
    		param = param[1];
    	}    	
    	addlist(param);						
    }	
	});
  
});

function addlist(param)
{
  if ($.cookie('params') == null)
  {    
    $.cookie('params', param, { expires: 7, path: '/', domain: ".littlepinkbook.co.za" });
    $.cookie('total', 1, { expires: 7, path: '/', domain: ".littlepinkbook.co.za" });
    $('#count').html(1);
	
	$('#supplier_box_popup').fadeIn('700', function() {
		$('#supplier_box_popup').delay(4400).fadeOut('900')
	});
  }
  else
  {
    var paramsArray = $.cookie('params').split(',');
    var paramExists = false;
    $.each(paramsArray,function( intIndex, objValue )
    {
      if (param == objValue)
      {
        paramExists = true;  
      }
    });
    
    if (paramExists == false)
    {
      $.cookie('params', $.cookie('params') + ',' + param, { expires: 7, path: '/', domain: ".littlepinkbook.co.za" });
      totalprice=parseInt($.cookie('total', { expires: 7, path: '/', domain: ".littlepinkbook.co.za" }))+1;
      $.cookie('total', totalprice, { expires: 7, path: '/', domain: ".littlepinkbook.co.za" });
      $('#count').html(totalprice);
	  
	  $('#supplier_box_popup').fadeIn('700', function() {
		$('#supplier_box_popup').delay(4400).fadeOut('900')
		});
	  
    }  
  }
}
