(function(){

var api = {

	init: function()
	{
		if ($.browser.msie) {
			try {
				document.execCommand("BackgroundImageCache", false, true);
			} catch(err){};
			if (typeof(DD_belatedPNG) != 'undefined')
			{
				DD_belatedPNG.fix('#top, #siteTop .info, #siteInfo .add a, #siteInfo .zoom, #siteInfo .directions h4, #trail .view a, #town .content, #sites .marker, #roadTrip h4 span, .twitterbutton, .png');
			}
		}

		if ($('#gallery').length)
		{
			$('#gallery .slider').jCarouselLite({
				circular: true,
				visible: 10,
				scroll: 1,
				btnNext: '#gallery p.next a',
				btnPrev: '#gallery p.prev a'
			});
			$('#gallery .slider a').click(function(){
				$('#gallery .main').find('img').attr('src', $(this).attr('href')).end();
				$('#gallery .main').find('h3').html($(this).attr('title')).end();
				$('#gallery .main .descrip').html($(this).attr('caption')).end();
				var html = "";
				if ($(this).attr('town')) {
					html = html + '<a href="' + $(this).attr('townpath') + '">' + $(this).attr('town') + '</a><br/>';
				}
				if ($(this).attr('dest')) {
					html = html + '<a href="' + $(this).attr('destpath') + '">' + $(this).attr('dest') + '</a><br/>';
				}
				$('#gallery .main .info').html(html);
				return false;
			});
			//$('#gallery .slider a.img:nth(0)').trigger('click');
		}

		if ($('#sites').length)
		{
			$('#sites .map').scrollFollow({ offset: 10 });
		}

		if ($('#gallery2').length)
		{
			$('a.prev').click(function(){slide(-1); return false;});
			$('a.next').click(function(){slide(1); return false;});
		
			function slide(dir) {
				var curSlide = $('#gallery2 div').index($('#gallery2 .show'));
				$('#gallery2 div').removeClass('show');
				var curSlide = curSlide + dir;
				var slides = $('#gallery2 div');
				if(curSlide >= slides.length) {
					curSlide = 0;
				} else if(curSlide < 0) {
					curSlide = slides.length-1;
				}
				$(slides[curSlide]).addClass('show');
			}
		}
	}
	
};


$(document).ready(api.init);

})();