/*
* Namespace for LR Golf
*/
var LR = window.LR ||
{};

LR.Golf = {};
LR.Golf.Navigation = (function() {

	function init() {

		// main navigation items
		$('#mainnavigation > li').mouseover(function() {
			$(this).siblings('li').removeClass('active');
			$(this).addClass('active');
		});

		// enable a page click to turn off menus (mouseout fails to work because of positioning)
		$('html').click(function() {
			$('#mainnavigation > li').removeClass('active');
		});

		// "make a reservation" menu
		$('#resoptions').hover(function() {
			$(this).addClass('active');
		}, function() {
			$(this).removeClass('active');
		});

		//Sifr header		
		$(".h1_sifr").sifr({
			path: "/common/templates/resort/resort_1/flash/",
			font: "itc_advent_gothic_book",
			fontSize: "30"
		});

		//Panel images
		$(".panel_image_container").each(function() {
			var slideshowEngine = new imageslideshowEngine();
			slideshowEngine.images = $(this).children("img").get();
			slideshowEngine.init(5000, "fast");
		});
		
		//Keep session alive
		try {
			setInterval("PageMethods.Heartbeat();", 300000);
		} catch (e) { }
	}

	return {
		init: init
	};

})();


LR.Golf.MainImages = (function() {
	var slideshowEngine;
	var config = {
		fadeInterval: 5000,
		fadeSpeed: 500
	};

	function createSlideshow() {
		if ($('body').hasClass('gallery') == false) {
			// create slideshow and set up image array
			slideshowEngine = new imageslideshowEngine();
			slideshowEngine.images = $('#images img').get();

			// set up control click event handlers
			$('#thumbs img').css({
				cursor: 'pointer'
			});
			$('#thumbs img').each(function(i) {
				$(this).click(function(e) {
					slideshowEngine.jumpToPair(i, false);
					var altText = $(this).attr("alt");
//					$(".image_caption").fadeOut("fast", function() {
//						$(".image_caption").html(altText).removeClass("sifr");
//						$(".image_caption").sifr({
//							path: "/common/templates/resort/resort_1/flash/",
//							font: "nobel_book_light",
//							fontSize: "30"
//						});
//						$(".image_caption").fadeIn("fast");
//					});
					e.preventDefault();
				});
			});			
			// start the engine
			slideshowEngine.init(config.fadeInterval, config.fadeSpeed, mainImageSwitched);
		}
	}

	function mainImageSwitched(i) {
		try {
			if ($("#images img").size() > 0) {
				var altText = $("#images img").eq(i.to).attr("alt");
//				$(".image_caption").fadeOut("fast", function() {
//					$(".image_caption").html(altText).removeClass("sifr");					
//					$(".image_caption").sifr({
//						path: "/common/templates/resort/resort_1/flash/",
//						font: "nobel_book_light",
//						fontSize: "30"
//					});
//					$(".image_caption").fadeIn("fast");
//				});
			}
		} catch (e) { alert(e); }
	}

	function selectImage(i) {
		slideshowEngine.jumpToPair(i, true);
	}

	return {
		createSlideshow: createSlideshow,
		selectImage: selectImage
	};

} ());


/* Gallery */
LR.Golf.Gallery = (function() {
	var slideshowEngine;
	var config = {
		fadeInterval: 6000,
		fadeSpeed: 1000
	};

	function create() {
		if ($('body').hasClass('gallery')) {
			// create slideshow and set up image array
			slideshowEngine = new imageslideshowEngine();
			slideshowEngine.images = $('#images img').get();

			// set up control click event handlers
			$('#imagestrip img').css({
				cursor: 'pointer'
			});
			$('#imagestrip img').each(function(i) {
				$(this).click(function(event) {
					selectImage(i);
					event.preventDefault();
				});
			});

			//setup move left event handler
			$("#gallerygroup #moveright").click(function(event) {

				var imageCount = $("#imagestrip").children().size();
				var containerWidth = (imageCount * 75);
				containerWidth = containerWidth - (containerWidth * 2);

				var vleft = $("#imagestrip").css("left");
				var vwidth = $("#imagestrip").css("width");

				vleft = parseInt(vleft.substring(0, vleft.length - 2)) - 300;
				if (vleft >= containerWidth) {
					$("#imagestrip").animate({
						left: vleft
					}, 500);
				}
				event.preventDefault();
			});

			//setup move right event handler
			$("#gallerygroup #moveleft").click(function(event) {
				var vleft = $("#imagestrip").css("left");
				vleft = parseInt(vleft.substring(0, vleft.length - 2)) + 300;
				if (vleft <= 0) {
					$("#imagestrip").animate({
						left: vleft
					}, 500);
				}
				event.preventDefault();
			});

			$('#pause').click(function(event) {
				pause();
				event.preventDefault();
			});
			$('#play').click(function(event) {
				unpause();
				event.preventDefault();
			});

			// start the engine
			slideshowEngine.init(config.fadeInterval, config.fadeSpeed, imageSwitched);
		}
	}

	function selectImage(i) {
		slideshowEngine.jumpToPair(i, true);
		imageSwitched({
			to: i
		});
	}

	function imageSwitched(indexes) {
		// activate the indexed thumbnail, deactivate others        
		$('#imagestrip img').eq(indexes.to).addClass('active').siblings().removeClass('active');
	}

	function pause() {
		if (slideshowEngine) {
			slideshowEngine.pauseEngine();
		}
	}
	function unpause() {
		if (slideshowEngine) {
			slideshowEngine.unpauseEngine();
		}
	}

	return {
		create: create,
		selectImage: selectImage,
		imageSwitched: imageSwitched,
		pause: pause,
		unpause: unpause
	};

} ());

function fnShowHole(x) {
    $('#fullmap').hide();
    $('#hole1').hide();
    $('#hole2').hide();
    $('#hole3').hide();
    $('#hole4').hide();
    $('#hole5').hide();
    $('#hole6').hide();
    $('#hole7').hide();
    $('#hole8').hide();
    $('#hole9').hide();
    $('#smallmap').show();
    $(x).show();
}


$(document).ready(LR.Golf.Navigation.init);
$(document).ready(LR.Golf.MainImages.createSlideshow);
$(document).ready(LR.Golf.Gallery.create);