// Coupon display specific js - cc.coupons.js - beaver6813 - sam cleaver
$(function() {
$('.favouritecontainer a').live('click',function() {
									  var couponid = $(this).parent().siblings('.couponiddata').val();
									  var target = $(this);
									  $.ajax({
											   type: "GET",
											   url: "/setresponse.php",
											   data: "type=ToggleFavourite&ID="+couponid,
											   beforeSend: function() {
												  target.css('background','top left no-repeat url(/images/loading.gif)');
	   
											  },
											   success: function(msg){
												   if(msg=='TRUE')
											   {
													  target.css('background','top left no-repeat url(/images/star.png)');
													  target.attr('title','Click to remove from favorites');
											   }
												  else if(msg=='NOLOGIN')
												  	{
													target.css('background','top left no-repeat url(/images/star-empty.png)');	
													alert("You must login to pick favorites.");
													}
												  else if(msg=='REMOVED')
											   {
													  target.css('background','top left no-repeat url(/images/star-empty.png)');
													  target.attr('title','Click to add to favorites');
											   }
												  else
												  	{
													target.css('background','top left no-repeat url(/images/star-empty.png)');	
													  alert("An error occured. Please try again later.");
													}
											   }
											 });
											   });
$('.giftform').submit(function () {
	//First get zipcode and check if they entered a zipcode
	var zipcode = $(this).find("input[name=zipcode]").val();
	if(zipcode.length>0)
		{
		//Now lets do the smart thing and just use jquery ui's functions to ajaxify this
		$('#tabs').tabs('select',2);
		$('#tabs').tabs( 'url' , 2 , "/index.php?ajax=1&zipcode="+zipcode );
		$('#tabs').tabs( 'load' , 2 );
		setTimeout(function () { 
		$('#giftcertificates .inner').infinitescroll({
   
		  navSelector  : "#giftcertificates .moreresults a",            
						 // selector for the paged navigation (it will be hidden)
		  nextSelector : "#giftcertificates .moreresults a",   
						 // selector for the NEXT link (to page 2)
		  itemSelector : "#giftcertificates .innercontent",
		  donetext     : "",
		  loadingText  : "<em>Loading more results...</em>",
		  loadingImg   : "/images/loadingbanner.gif",
		  infid		   : 2
						 // selector for all items you'll retrieve
		}); 
		},2000);
		}
	return false;
	
});

});

