/**
 * harlyn.js
 */

var harlyn = {
	
	// initialise
	init: function() {

		harlyn.init_sifr();
		harlyn.init_subnavigation();
		harlyn.init_signup_panel();
		harlyn.init_footer_getintouch();
		
		if( $(".gallery").attr('class') ) {
			$(".gallery").yoxview({dataFolder:"/assets/js/yoxview/data/", lang:"en"});
		}
		
		if( $.datepicker ) {
			$('#morning-date, #afternoon-date').datepicker({
				changeMonth: true,
				changeYear: true,
				minDate: 0,
				dateFormat: 'dd/mm/yy'
			});
		}
		
		if( $('#homepage-movie').attr('id') ) {
			setTimeout(function() {
				harlyn.init_movie_homepage();
			}, 3000);
		}

		if( $('#coasteering-movie').attr('id') ) {
			setTimeout(function() {
				harlyn.init_movie_coasteering();
			}, 3000);
		}

	}
	
	// initialise subnavigation behaviour
	,init_subnavigation: function() {
		
		$('ul.subnavigation a').click(function() {
			
			/*
			if( $(this).parent().find('ul').length ) {
				$(this).blur();
				$(this).parent().find('ul:first').slideToggle('normal');
				return false;
			}
			*/
			
			if( $(this).attr('href') == '#' ) {
				return false;
			}
			
		});
		
	}
	
	// initialise cufon font replacement
	,init_sifr: function() {
		Cufon.replace('.replace');
	}
	
	// initialise ajax signup panel
	,init_signup_panel: function() {
		
		$('#signup_emailaddress').focus(function() {
			
			if( $(this).val() == 'Your email address' ) {
				$(this).val('');
			}
			
		}).blur(function() {
			
			if( $(this).val() == '' ) {
				$(this).val('Your email address');
			}
			
		});
		
		/*
		$('.signup-panel-form').submit(function() {
			var emailaddress = $(this).find("input[name='emailaddress']").val();
			var thisEl = $(this);
			
			if(emailaddress) {
				
				harlyn.show_overlay( thisEl );
				
				$.ajax({
					 url: '/ajax/signup.php'
					,data: 'a=submit&emailaddress=' + emailaddress
					,type: 'POST'
					,success: function(data) {
						harlyn.hide_overlay( thisEl );
						thisEl.html( data );
					}
				});
				
			}
			return false;
		});
		*/
		
	}

	// initialise footer get in touch ajax functionality
	,init_footer_getintouch: function() {

		$('#footer-contact-form').submit(function() {
			var thisEl = $(this).parent();
			var formdata = $(this).serialize();

			harlyn.show_overlay( $(thisEl) );
			
			$.ajax({
				 url: '/ajax/getintouchfooter.php'
				,data: formdata
				,type: 'POST'
				,success: function(data) {
					harlyn.hide_overlay( thisEl );
					thisEl.html( data );
				}
			});
			
			return false;
		});
		
	}

	// show an overlay
	,show_overlay: function( el ) {
		
		el.append('<div class="overlay"></div>');
		el.find('.overlay').css('opacity', 0).show().fadeTo('fast', 0.8);
		
	}

	// hide an overlay
	,hide_overlay: function( el ) {
		
		el.find('.overlay').fadeOut('fast', function() {
		});
		
	}
	
	,init_movie_homepage: function() {
		
		var img_width = $('#homepage-movie img').width();
		var img_height = $('#homepage-movie img').height();
		
		$('#homepage-movie').css({
			 width: img_width + 'px'
			,height: img_height + 'px'
		});
		
		$('#homepage-movie img').fadeOut('normal', function() {
			
			$('.header-image .book-online-now').animate({
				bottom: '50px'
			}, 'normal');
			
			$('#homepage-movie').animate({
				height: '592px'
			}, 'normal', function() {
				flashvars = { 'skinName' : 'assets/swf/flvplayer/Corona_Skin_3'
							 ,'streamName' : '/assets/media/HSS-Generic-web-890'
							 ,'autoPlay' : true
							 ,'autoRewind' : false};
				params    = { 'wmode' : 'transparent' };
				
				swfobject.embedSWF(
					"/assets/swf/flvplayer/FLVPlayer_Progressive.swf"
					,"homepage-movie"
					,"890"
					,"592"
					,"9.0.0"
					,"/assets/js/expressInstall.swf"
					,flashvars
					,params
				);

			});
			
		});
		
	}

	,init_movie_coasteering: function() {
		
		var img_width = $('#coasteering-movie img').width();
		var img_height = $('#coasteering-movie img').height();
		
		$('#coasteering-movie').css({
			 width: img_width + 'px'
			,height: img_height + 'px'
		});
		
		$('#coasteering-movie img').fadeOut('normal', function() {
			
			$('#coasteering-movie').animate({
				height: '372px'
			}, 'normal', function() {
				flashvars = { 'skinName' : 'assets/swf/flvplayer/Corona_Skin_3'
							 ,'streamName' : '/assets/media/HSS-Coasteering-HD-web-665'
							 ,'autoPlay' : true
							 ,'autoRewind' : false};
				params    = { 'wmode' : 'transparent' };
				
				swfobject.embedSWF(
					"/assets/swf/flvplayer/FLVPlayer_Progressive.swf"
					,"coasteering-movie"
					,"665"
					,"372"
					,"9.0.0"
					,"/assets/js/expressInstall.swf"
					,flashvars
					,params
				);

			});
			
		});
		
	}

};

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