/**
 * website.js
 */

var website = {
	
	init: function() {
		
		headerpanels.init();
		fourscroller.init();
		
		$('.myform .row:odd').addClass('alt');
		
		$('.header-panel-foroneandall').css({
			cursor: 'pointer'
		}).click(function() {
			window.location = '/attractions.html';
		});

		$('.header-panel-advertisewithus').css({
			cursor: 'pointer'
		}).click(function() {
			window.location = '/advertise-with-us/what-we-can-do-for-you.html';
		});

		$('._blank').click(function(e) {
			e.preventDefault();
			window.open( $(this).attr('href') );
		});

		$("a[rel^='lightboxiframe']").fancybox({
			'width'				: '85%',
			'height'			: '85%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});

	}
	
};

var headerpanels = {
	
	 total_slides: 0
	,mainimage_width: 0
	,mainimage_height: 0
	,timer: null
	
	,init: function() {
		
		headerpanels.total_slides = $('.header-panels .header-panel').length;
		headerpanels.mainimage_width = $('.header-panels .header-panel:first').width();
		headerpanels.mainimage_height = $('.header-panels .header-panel:first').height();
		
		$('.header-panels .header-panels-inner').height( 2 * headerpanels.mainimage_height );
		
		var x=0;
		$('.header-panels .header-panel').each(function() {
			if(x == 0) {
				$(this).addClass('selected').css('top', '0px');
			}
			x++;
		});

		if( headerpanels.total_slides < 2 ) {
			return;
		}

		$('.header-panels').hover(function() {
			clearTimeout(headerpanels.timer);
		}, function() {
			clearTimeout(headerpanels.timer);
			headerpanels.ready_autoplay();
		});
		
		headerpanels.ready_autoplay();

	}
	
	,ready_autoplay: function() {
		
		headerpanels.timer = setTimeout(function() {

			$('.header-panels .header-panel.selected').animate({
				top: '-250px'
			}, 1000, 'easeOutQuad', function() {
				$(this).removeClass('selected');
				$('.header-panels').append( $(this) );
				//$(this).remove();
			});

			$('.header-panels .header-panel.selected').next().animate({
				top: 0
			}, 1000, 'easeOutQuad', function() {
				$(this).addClass('selected');
			});
			
			clearTimeout(headerpanels.timer);
			headerpanels.ready_autoplay();
			
		}, 7000);
		
	}
	
};


var fourscroller = {
	
	 total_slides: 0
	,mainimage_width: 0
	,mainimage_height: 0
	,timer: null
	
	,init: function() {
		
		fourscroller.total_slides = $('.fourscroller-inner').length;
		fourscroller.mainimage_width = $('.fourscroller').width();
		fourscroller.mainimage_height = $('.fourscroller').height();
		
		$('.fourscroller-inner .column').append('<span class="shine"></span>');
		
		var x=0;
		$('.fourscroller-inner').each(function() {
			if(x == 0) {
				$(this).addClass('selected').css('top', '0px');
			}
			x++;
		});
		
		fourscroller.ready_autoplay();

	}
	
	,ready_autoplay: function() {
		
		fourscroller.timer = setTimeout(function() {

			$('.fourscroller-inner.selected').animate({
				 top: '150px'
				,opacity:0
			}, 2000, 'easeOutQuad', function() {
				$(this).removeClass('selected');
				$('.fourscroller').append( $(this) );
			});

			$('.fourscroller-inner.selected').next().animate({
				 top: 0
				,opacity: 1
			}, 2000, 'easeOutQuad', function() {
				$(this).addClass('selected');
			});
			
			clearTimeout(fourscroller.timer);
			fourscroller.ready_autoplay();
			
		}, 5000);
		
	}
	
};

$(document).ready(website.init);
