var MYIDX = 0;

/**
 * 
 * Builds the carousel for must haves
 * 
 **/
var PhotoGallery = {
	
	init:function(pagesize){
		jQuery(document).ready(function() {
		    jQuery('#mycarousel').jcarousel({
		      scroll:1, 
		      /*wrap:"circular",*/
			  wrap: 'last',
		      auto:5,
			  size:pagesize,
		      initCallback: PhotoGallery.mycarousel_initCallback,
			  itemFirstInCallback:  PhotoGallery.mycarousel_itemFirstInCallback,
			  itemFirstOutCallback: PhotoGallery.mycarousel_itemFirstOutCallback
			  // This tells jCarousel NOT to autobuild prev/next buttons
        	  ,buttonNextHTML: null
        	  ,buttonPrevHTML: null
		    });
		});
	},
	
	mycarousel_itemFirstInCallback:function(carousel, item, idx, state){
		//add the selected class to the element
		$('#my-control-'+idx).addClass('selected');
	},
	
	mycarousel_itemFirstOutCallback:function(carousel, item, idx, state){
		//remove the selected class from the element
		$('#my-control-'+idx).removeClass('selected');
	},
	
	mycarousel_initCallback:function(carousel){
		//bind a click event to all a tags with class external
		jQuery('ul.pagination a.external').bind('click', function() {
			attributeID = jQuery(this).attr('pgid');
	        carousel.scroll(jQuery.jcarousel.intval(attributeID));
	        return false;
	    });

		
		jQuery('#mycarousel-next').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    jQuery('#mycarousel-prev').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	},
	
	toggleHover:function(obj){
		$(obj).hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
	}
	
};

/**
 * 
 * Builds the carousel for auctions by location 
 * 
 **/
var AuctionGallery = {
	
	init:function(pagesize){
		jQuery(document).ready(function() {
		    jQuery('#mycarousel-auction').jcarousel({
		      scroll:1, 
		      /*wrap:"circular",*/
			  wrap: 'last',
		      auto:5,
			  size:pagesize,
		      initCallback: AuctionGallery.mycarousel_initCallback,
			  itemFirstInCallback:  AuctionGallery.mycarousel_itemFirstInCallback,
			  itemFirstOutCallback: AuctionGallery.mycarousel_itemFirstOutCallback
			  // This tells jCarousel NOT to autobuild prev/next buttons
        	  ,buttonNextHTML: null
        	  ,buttonPrevHTML: null
		    });
		});
	},
	
	mycarousel_itemFirstInCallback:function(carousel, item, idx, state){
		//add the selected class to the element
		$('#my-control-'+idx).addClass('selected');
	},
	
	mycarousel_itemFirstOutCallback:function(carousel, item, idx, state){
		//remove the selected class from the element
		$('#my-control-'+idx).removeClass('selected');
	},
	
	mycarousel_initCallback:function(carousel){
		//bind a click event to all a tags with class external
		jQuery('ul.pagination a.external').bind('click', function() {
			attributeID = jQuery(this).attr('pgid');
	        carousel.scroll(jQuery.jcarousel.intval(attributeID));
	        return false;
	    });

		
		jQuery('#mycarousel-next').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    jQuery('#mycarousel-prev').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	},
	
	toggleHover:function(obj){
		$(obj).hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
	}
	
};


/**
 * 
 * Builds the carousel for browse items 
 * 
 **/
var BrowseGallery = {
	
	init:function(pagesize){
		jQuery(document).ready(function() {
		    jQuery('#mycarousel-browse').jcarousel({
		      // Uncomment the following option if you want items
		      // which are outside the visible range to be removed
		      // from the DOM.
		      // Useful for carousels with MANY items.
		
		      // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
		      itemLoadCallback: mycarousel_itemLoadCallback

			  /*scroll:2, 
		      wrap:"circular",
			  wrap: 'last',
		      auto:5,
			  size:pagesize,
		      initCallback: AuctionGallery.mycarousel_initCallback,
			  itemFirstInCallback:  AuctionGallery.mycarousel_itemFirstInCallback,
			  itemFirstOutCallback: AuctionGallery.mycarousel_itemFirstOutCallback
			  // This tells jCarousel NOT to autobuild prev/next buttons
        	  ,buttonNextHTML: null
        	  ,buttonPrevHTML: null*/
		    });
		});
	},
	
	mycarousel_itemLoadCallback:function(carousel, state){
		// Check if the requested items already exist
		if (carousel.has(carousel.first, carousel.last)) {
	        return;
	    }
		
		var ajax = $.ajax({
			type: "GET",
			url: "/includes/ajax/ajx_gateway.cfm?comp=ajx_account&method=getDonationRecord",
			dataType: 'json',
			data: {
				donationid: id
			},
			success: function(r, status){
				//console.log(r);
				location.href = '/accountDonationHistoryPrint.cfm?d='+id;
			}
		});

	},
	
	mycarousel_itemFirstInCallback:function(carousel, item, idx, state){
		//add the selected class to the element
		$('#my-control-'+idx).addClass('selected');
	},
	
	mycarousel_itemFirstOutCallback:function(carousel, item, idx, state){
		//remove the selected class from the element
		$('#my-control-'+idx).removeClass('selected');
	},
	
	mycarousel_initCallback:function(carousel){
		//bind a click event to all a tags with class external
		jQuery('ul.pagination a.external').bind('click', function() {
			attributeID = jQuery(this).attr('pgid');
	        carousel.scroll(jQuery.jcarousel.intval(attributeID));
	        return false;
	    });

		
		jQuery('#mycarousel-next').bind('click', function() {
	        carousel.next();
	        return false;
	    });

	    jQuery('#mycarousel-prev').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	},
	
	toggleHover:function(obj){
		$(obj).hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
	}
	
};

