var $j = jQuery.noConflict();


/** @id first function
* @classDescription the description
*/
$j(function(){	
	 
	
	
	var counter=1;
	if(jQuery('.ditto_item').size())
	{
    jQuery('.ditto_item').each(function(){
      if(counter>1 && counter%4==0)
      {
       jQuery(this).css('margin-right', '0');
      }
      
      counter++;
    });
  }
  
  
  jQuery.post('index.php?id=11', 'action=count', function(data){
      
      if(data.length > 0)
      {
        jQuery('.tc_cart_count').html(data.length);
        jQuery('.treasure_cart').css('opacity', '');
        jQuery('.treasure_cart').show();         
        
        jQuery('.thickbox').attr('href', 'index.php?id=11&TB_iframe=true&height=300&width=500');
        
          jQuery('.emptyTreasureChest').attr('href', 'javascript:void(0)');
          jQuery('.emptyTreasureChest').unbind('click');
          jQuery('.emptyTreasureChest').bind('click', function(){
              jQuery.post('index.php?id=11', 'action=empty', function(data){
                   window.location.href=window.location.href;
              });
        });
        
      }
            
       
      
  }, 'json');                                                     
  
   
   
   
                                   
   //jQuery('<a href="wishlist.html">View Wishlist</a>').insertAfter('.treasure_cart');
   
  
	
});


var wishurl ='';
function AddToWishlist(url,pid){
	wishurl = url;

	 jQuery.get(wishurl, 'op=add_to_wishlist&pid='+pid, function(data){
			   jQuery('#server_response').html(data);
	 });
	
	
}


function updateWishListQty(url, pid, qty){
		
   wishurl = url;
	 
	 jQuery.get(wishurl, 'op=update_wishlist_qty&pid='+pid+'&qty='+qty, function(data){
			   jQuery('#server_response').html(data);
	 }); 
}



function moveSelectedToCart(url_wl, url_cart){
		  
    
	  var inputs = document.getElementsByTagName("input");
	  var i=0;
	  
	  for (i = 0; i < inputs.length; i++) { 
	  	if (inputs[i].getAttribute('tag') == 'sitem') {
	  		var box = inputs[i];
			
				if(box.checked){
				 
  	      jQuery.post(url_cart, 'action=add&selector=id&item='+box.value, function(data){
  	           window.location.href=window.location.href;
  	      }); 
          	 
        }  
	     }
   	 }
      
      
      
}



function removeSelectedFromWishlist(url){
  wishlist = url;
	
  var inputs = document.getElementsByTagName("input");
  var i=0;
  
  for (i = 0; i < inputs.length; i++) {
  
  	if (inputs[i].getAttribute('tag') == 'sitem') {
  	
  		var box = inputs[i];
		
  		if(box.checked){ 
  		
  		  jQuery.get(wishlist, 'op=remove_wishlist&pid='+box.value, function(data){
      			 jQuery('#server_response').html(data);    
      	}); 
  		 
  		}
  	}
  }
}



function referToFriends(path){
  
	
  var inputs = document.getElementsByTagName("input");
  var i=0;
  
  for (i = 0; i < inputs.length; i++) {
  
  	if (inputs[i].getAttribute('tag') == 'sitem') {
  	
  		var box = inputs[i];
		
  		if(box.checked){ 
  		
  		   window.location.href=path+'?did='+box.value; 
  		 
  		}
  	}
  }
}


