// 2010.07.23 KJD: Document created
var myCarousel = null;

var addthis_config = {
		   ui_click: false,
		   ui_header_color: "#00066",
		   ui_header_background: "#F9FAEB"
		}

function getDigits( thisString ){
	return thisString.replace(/[^0-9]/gi,'');
}

function mycarousel_initCallback(carousel) {
    
	myCarousel = carousel;
	
	jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('.gallery .toolbar .next a').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('.gallery .toolbar .previous a').bind('click', function() {
        carousel.prev();
        return false;
    });
};

function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {        return;    }

    // 2010.06.12 KJD: Get the last item ID
    var lastItem	= ($('li.ridegroup:last').find('div.ride:last').length )? $('li.ridegroup:last').find('div.ride:last').attr('rel'):'';
    
    $.ajax({
        url: thisfilename,
        data:
        {
        	page: 	'gallery',
        	action: 'getitems',
        	id: 	lastItem,
        	count:	$('.gallery .toolbar .perpage option:selected').text()
        },
        success:      function(thisResponse) {
        	carousel.add( $('.gallery .ridegroup').length, thisResponse );
        	
        	// 2010.06.11 KJD: Gallery tooltips
        	$(".gallery .ride a").tooltip({
        		bodyHandler: function(){
        			return $(this).parent().next().html();
        			},
        		delay: 0,
        		showURL: false,
        		track: true
        		});
        }

    });
};

function gotoUrl( thisURL ){
	location.href= thisURL;
}

function changeState( thisState ){
	gotoUrl( thisfilename + "?page=state&stateid=" + thisState );
}

