/*#####################################
	FUNCTIONS BEGIN
#####################################*/

// Prepare Map Links
function prepareMapLinks(selector, paramsToAdd) {
	 $(selector).addClass('activateLightbox');
	 $(selector).each(function() {
	 	var link = $(this).attr('href');
 		$(this).attr({
 			href: (link + paramsToAdd)
 		});
 	});
}

// Slideshowpro controls

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
	    return document[movieName];
	}
}


function sspToggleDisplayMode(value, slideshow) {
	thisMovie(slideshow).sspToggleDisplayMode(value);
}
	
function sspLoadAlbum(slideshow, album, contentID) {
	thisMovie(slideshow).sspLoadAlbum(album, contentID);
}

// Lightbox
function albumTrigger(selector, slideshow) {
	$(selector).bind('click', function () {
		var contentID = $(this).attr('title');
		var album = $('#locationDescription').attr('title');
		sspLoadAlbum(slideshow, album, contentID);
		sspToggleDisplayMode("stop", slideshow);
	});
}

function lightboxCommentsLink() {
	$('#lightboxCommentsLink').bind('click', function () {
		var link = $(this).attr('href');
		$('#lightboxCommentsLink').hide();
		if ( $("#commentsOuterWrapInLightbox").length > 0 ) {	
			$("#commentsOuterWrapInLightbox").show();
			$('#returnToDescription').show();
			$('#locationDescription').hide();
		} else {
			$.ajax({
			    url: link,
			    cache: false,
			    success: function(html){
					$('#locationDescription').hide();
				    $("#locationDescriptionWrap").append(html);
				    $('#commentsWrap').jScrollPane({showArrows:false, scrollbarWidth: 23, dragMinHeight:20, dragMaxHeight:20});
				    $('#returnToDescription').bind('click', function () {
						$('#returnToDescription').hide();
						$('#commentsOuterWrapInLightbox').hide();
						$('#locationDescription').show();
						$('#lightboxCommentsLink').show();
				   		lightboxCommentsLink();	
						return false;
					});
				}
			});
		}
		return false;
	});
}

/*#####################################
	FUNCTIONS END
#####################################*/


/*#####################################
	DOCUMENT READY BEGINS
#####################################*/
$(document).ready(function(){

	// Reservation Pop Up list in center bottom bucket
	// $('#reservationPopUp').hide();
	$('#bucket-2 .closeReservationPopUp').bind('click', function() {
		$('#bucket-2 .reservationPopUp').slideUp('slow');
		return false;
	});
	
	$('#reservationPagePopup .closeReservationPopUp').bind('click', function() {
		$('#reservationPagePopup .reservationPopUp').slideUp('slow');
		return false;
	});
	
	
	$('#bucket-2 .reservationPopUpWrap').bind('click', function() {
		if ($('#bucket-2 .reservationPopUp').is(':hidden')) {
			$('#bucket-2 .reservationPopUp').slideDown('slow');
			return false;
		}
	});
	
	$('#reservationPagePopup .reservationPopUpWrap').bind('click', function() {
		if ($('#reservationPagePopup .reservationPopUp').is(':hidden')) {
			$('#reservationPagePopup .reservationPopUp').slideUp('slow');
			return false;
		}
	});
	
	$('#reservationPagePopup #locationSelectorTrigger').bind('click', function() {
		if ($('#reservationPagePopup .reservationPopUp').is(':visible')) {
			$('#reservationPagePopup .reservationPopUp').slideUp('slow');
		} else {
			$('#reservationPagePopup .reservationPopUp').slideDown('slow');
		}
	});
	
	$('#locationSelector').hide();
	$('#locationSelectorWrap #locationSelectorTrigger').bind('click', function() {
		if ($('#locationSelector').is(':visible')) {
			$('#locationSelector').slideUp('slow');
		} else {
			$('#locationSelector').slideDown('slow');
		}
	});
	
	$('#closeLocationSelector').bind('click', function() {
			$('#locationSelector').slideUp('slow');
	});

	// Rotating ads right bottom bucket
	$('.bucketFade').innerfade({
		speed: 'slow',
		timeout: 5000,
		type: 'sequence',
		containerheight: '140px' 
	}); 
	
	// Dining Experience Video
	/*
	$('#videoWrap .clickOverlay').bind('click', function() {
		$('#videoWrap .overlay').toggle();
		$f(0).toggle();
		$('#startStopButton').toggleClass('playerStopped');
	});
	*/
	
	$('#videoWrap .clickOverlay').bind('click', function() {
		var playerState = $f(0).getState();
		if (playerState == 3) {
			$('#videoWrap .overlay').show();
			$f(0).stop();
			$('#startStopButton').addClass('playerStopped');
		} else {
			$('#videoWrap .overlay').hide();
			$f(0).play();
			$('#startStopButton').removeClass('playerStopped');
		}
	});
	
	muteStatus = 0;
	$('#videoWrap #mutePlayer').bind('click', function() {
		if (muteStatus == 0) {
			$f(0).mute();
			$('#videoWrap #mutePlayer').addClass('playerMuted');
			muteStatus = 1;	
		} else {
			$f(0).unmute();
			$('#videoWrap #mutePlayer').removeClass('playerMuted');
			muteStatus = 0;
		}
	});
	$('#videoWrap .overlay').show();

	// Location map
	$('#usButton').hide();

	$('#brazilButton').bind('click', function() {
		$("#map").animate({ 
		top: "-340px", left:"-130px"
		}, 500 );
		$('#usButton').show();
		return false;
	});

	$('#usButton').bind('click', function() {
		$("#map").animate({ 
		top: "0", left:"0"
		}, 500 );
		$('#brazilButton').show();
		return false;
	});

	
	// Initialize Slideshow for location
	if ($("#locationSlideShow").length > 0 ) {	
		initSlideShow();
	}

	if ($("#reservationList").length > 0 ) {	
		prepareMapLinks('.locationCity', '&nohead=1&print=1');
	}
	
	if ($("#brazilGroupBookings").length > 0 ) {	
		prepareMapLinks('.groupBookLocation', '&nohead=1&print=1');
	}
	
	if ($("#brazilUsaBookings").length > 0 ) {	
		prepareMapLinks('.groupBookLocation', '&nohead=1&print=1');
	}
	if ($("#map").length > 0 ) {	
		prepareMapLinks('.locationCity', '&nohead=1&print=1');
		$('.locationCity').hover(
			function () {
				var locationID = $(this).attr('id');
				$('#' + locationID + 'Image').show();
			}, 
			function () {
				var locationID = $(this).attr('id');
				$('#' + locationID + 'Image').hide();
			}
		);
	}
	
	
	
	// Activate Lightbox for Locations
	$('.activateLightbox').bind('click', function() {
		var ajaxContent = $(this).attr('href');
		$("#lightboxContent").empty();
		// sizeLightbox();
		$('#lightboxContentWrap').css('margin-top', '-265px').css('margin-left', '-350px');
		var $IE6 = typeof document.addEventListener !== 'function' && !window.XMLHttpRequest;
		if ($IE6) {
			$('#lightboxOverlay').css('top', $(document).scrollTop() + 'px');
		}
		$('#lightboxOverlay').fadeIn('slow');
		$('#lightboxContentWrap').fadeIn('slow');
	    $.ajax({
		    url: ajaxContent,
		    cache: false,
		    success: function(html){
		    	$("#lightboxContent").append(html);
			    if ( $("#locationSlideShow").length > 0 ) {	
					initSlideShow();
					 if ( $("#locationSlideShow").length > 0 ) {	
						albumTrigger('.thumbnailWindow', 'locationSlideShow');
					} 
				}
				
				lightboxCommentsLink();
				$('#locationDescriptionInnerWrap').jScrollPane({showArrows:false, scrollbarWidth: 23, dragMinHeight:20, dragMaxHeight:20});
				// WORKING ON THIS
				// Activate Lightbox for revervation ALREADY IN LIGHTBOX
				$('.reservationInsideLightbox').bind('click', function() {
					var link = $(this).attr('href');
					$("#lightboxContent").empty();
					$.ajax({
					    url: link,
					    cache: false,
					    success: function(html){
						    $("#lightboxContent").append(html);
						}
					});
					return false;
				});
			}
		});
		if ( $("#locationSlideShow").length > 0 ) {	
			albumTrigger('.thumbnailWindow', 'locationSlideShow');
		} 
		return false;
	});

	// Activate Lightbox for revervation
	$('.activateReservationLightbox').bind('click', function() {
		var ajaxContent = $(this).attr('href');
		$("#lightboxContent").empty();
		// sizeLightbox();
		$('#lightboxContentWrap').css('margin-top', '-265px').css('margin-left', '-350px');
		var $IE6 = typeof document.addEventListener !== 'function' && !window.XMLHttpRequest;
		if ($IE6) {
			$('#lightboxOverlay').css('top', $(document).scrollTop() + 'px');
		}
		$('#lightboxOverlay').fadeIn('slow');
		$('#lightboxContentWrap').fadeIn('slow');
	    $.ajax({
		    url: ajaxContent,
		    cache: false,
		    success: function(html){
		    	$("#lightboxContent").append(html);
			}
		});
		return false;
	});
	
	// Activate Lightbox for Video
	$('.activateVideoLightbox').bind('click', function() {
		$f(0).stop();
		$('#startStopButton').removeClass('playerStopped');
		$('#videoWrap .overlay').show();
		var ajaxContent = $(this).attr('href');
		$("#lightboxContent").empty();
		// sizeLightbox();
		$('#lightboxContentWrap').css('margin-top', '-265px').css('margin-left', '-350px');
		var $IE6 = typeof document.addEventListener !== 'function' && !window.XMLHttpRequest;
		if ($IE6) {
			$('#lightboxOverlay').css('top', $(document).scrollTop() + 'px');
		}
		$('#lightboxOverlay').fadeIn('slow');
		$('#lightboxContentWrap').fadeIn('slow');
	    $.ajax({
		    url: ajaxContent,
		    cache: false,
		    success: function(html){
		    	$("#lightboxContent").append(html);
		    	flowplayer("playerInLightbox", {src:'/fileadmin/test_images/flowplayer/flowplayer-3.1.0.swf', wmode: 'opaque'}, {
					clip:{
						autoPlay: false,
						autoBuffering: true,
						smoothing: false
					},
					plugins:{controls:null}
				});
		    	//Controls
			    $('#videoWrapInLightbox .clickOverlay').bind('click', function() {
					$('#videoWrapInLightbox .overlay').toggle();
					$f(1).toggle();
					$('videoWrapInLightbox #startStopButton').toggleClass('playerStopped');
				});
				$('#mutePlayerInLightbox').bind('click', function() {
					if (muteStatus == 0) {
						$f(1).mute();
						$('#mutePlayerInLightbox').addClass('playerMuted');
						muteStatus = 1;	
					} else {
						$f(1).unmute();
						$('#mutePlayerInLightbox').removeClass('playerMuted');
						muteStatus = 0;
					}
				});
			}
		});
		return false;
	});	
	
	// Hide lightbox
	$('#lightboxOverlay, .lightboxClose').click(function() {
		if ($("#videoWrapInLightbox").length > 0 ) {	
			$f(1).stop();
		}
		$('#lightboxContentWrap').fadeOut('5000', function () {
			$('#lightboxOverlay').hide();
		});
		return false;
	});

	$('#lightboxContentWrap').click(function(clickEvent) {
		clickEvent.stopPropagation();
	});
	
	// Fancy scroll on comments
	// $('#commentsWrapOnPage').jScrollPane({showArrows:false, scrollbarWidth: 23, dragMinHeight:20, dragMaxHeight:20});
	$('#awardsWrap').jScrollPane({showArrows:false, scrollbarWidth: 23, dragMinHeight:20, dragMaxHeight:20});
	// $('#commentsWrap').jScrollPane({showArrows:false, scrollbarWidth: 23, dragMinHeight:20, dragMaxHeight:20});
	
	$('.listCommentsForm #location').change (function() {
		$('.listCommentsForm').submit();
	});
		

});
/*#####################################
	DOCUMENT READY ENDS
#####################################*/
