// JavaScript Document

function init_page( page )
{
	$(document).ready(function() {
		
		if( page == "enquiries" )
		{
			$('#frm_dateofevent').datepicker({dateFormat: 'DD, MM d, yy', firstDay: 1});

			$('#frm_message').keydown( function (e) {
												  
				var field = document.getElementById('frm_message');
				if( field.value.length > 1500 )
				{
					field.value = field.value.substring( 0, 1500 );
				}
				else
				{
					document.getElementById('frm_message_charsleft').innerHTML = 1500 - field.value.length;
				}											  
			});
		
			$('#frm_firstname,#frm_lastname,#frm_suburb').blur( function () {
				if( this.value.length > 50 || this.value.length < 1 )
				{
					this.className = "fail";	
				}
				else
				{
					this.className = "pass";	
				}
			});
			
			$('#frm_mobilephone').blur( function() {
				if( this.value.length > 20 || this.value.length < 1 )
				{
					this.className = "fail";	
				}
				else
				{
					this.className = "pass";
				}
			});

			$('#frm_message').keyup( function (e) {
												  
				var field = document.getElementById('frm_message');
				if( field.value.length > 1500 )
				{
					field.value = field.value.substring( 0, 1500 );
				}
				else
				{
					document.getElementById('frm_message_charsleft').innerHTML = 1500 - field.value.length;
				}
												  
			});

	$('#frm_firstname,#frm_lastname,#frm_mobilephone,#frm_homephone,#frm_emailaddress,#frm_venuename,#frm_address1,#frm_address2,#frm_suburb,#frm_postcode,#frm_typeofevent,#frm_dateofevent,#frm_message,#frm_timestart_hour,#frm_timestart_min,#frm_timestart_ampm,#frm_timeend_hour,#frm_timeend_min,#frm_timeend_ampm,#frm_hearaboutus').mouseover( function() {
	
		$( this ).addClass('hover');
	
	});

$('#frm_firstname,#frm_lastname,#frm_mobilephone,#frm_homephone,#frm_emailaddress,#frm_venuename,#frm_address1,#frm_address2,#frm_suburb,#frm_postcode,#frm_typeofevent,#frm_dateofevent,#frm_message,#frm_timestart_hour,#frm_timestart_min,#frm_timestart_ampm,#frm_timeend_hour,#frm_timeend_min,#frm_timeend_ampm,#frm_hearaboutus').mouseout( function() {
	
	$( this ).removeClass('hover');
	
	});
		
		}
		
		if( page == "landing" )
		{
			setTimeout( "fadeout('weddings')", 2000 );
			setTimeout( "fadeout('parties')", 2300 );
			setTimeout( "fadeout('corporate')", 2600 );
			setTimeout( "fadeout('enquiries')", 2900 );
			setTimeout( "fadeout('masters','landing')", 2000 );
			
			$("#img_weddings").hover(
			  function () {
				$( this ).fadeTo(500, 1);
			  }, 
			  function () {
				$( this ).fadeTo(500, 0);
			  }
			);
		
			$("#img_parties").hover(
			  function () {
				$( this ).fadeTo(500, 1);
			  }, 
			  function () {
				$( this ).fadeTo(500, 0);
			  }
			);
			
			$("#img_corporate").hover(
			  function () {
				$( this ).fadeTo(500, 1);
			  }, 
			  function () {
				$( this ).fadeTo(500, 0);
			  }
			);
			
			$("#img_enquiries").hover(
			  function () {
				$( this ).fadeTo(500, 1);
			  }, 
			  function () {
				$( this ).fadeTo(500, 0);
			  }
			);
			
			// Navbar Hover Elements
			$("#nav_weddings").hover(
			  function () {
				$( "#img_weddings" ).fadeTo(500, 1);
			  }, 
			  function () {
				$( "#img_weddings" ).fadeTo(500, 0);
			  }
			);	
		
			$("#nav_parties").hover(
			  function () {
				$( "#img_parties" ).fadeTo(500, 1);
			  }, 
			  function () {
				$( "#img_parties" ).fadeTo(500, 0);
			  }
			);	
			
			$("#nav_corporate").hover(
			  function () {
				$( "#img_corporate" ).fadeTo(500, 1);
			  }, 
			  function () {
				$( "#img_corporate" ).fadeTo(500, 0);
			  }
			);	
			
			$("#nav_enquiries").hover(
			  function () {
				$( "#img_enquiries" ).fadeTo(500, 1);
			  }, 
			  function () {
				$( "#img_enquiries" ).fadeTo(500, 0);
			  }
			);

			// Masters Title Hover Effect
			$("#img_masters").hover(
			  function () {
				$( this ).fadeTo(500, 1);
			  }, 
			  function () {
				$( this ).fadeTo(500, 0);
			  }
			);	
			
			$("#nav_home").hover(
			  function () {
				$( "#img_masters" ).fadeTo(500, 1);
			  }, 
			  function () {
				$( "#img_masters" ).fadeTo(500, 0);
			  }
			);	

		}
		else
		{
//			$( "#img_masters" ).css( "visibility", "hidden" );
			
			// Masters Title Hover Effect
			$("#img_masters").hover(
			  function () {

//				$( "#img_masters" ).css( "visibility", "visible" );
				$( this ).fadeTo(500, 1);
			  }, 
			  function () {
				//$( "#img_masters" ).css( "visibility", "hidden" );
				$( this ).fadeTo(500, 0);
			  }
			);	
			
			$("#nav_home").hover(
			  function () {
				$( "#img_masters" ).fadeTo(500, 1);
			  }, 
			  function () {
				$( "#img_masters" ).fadeTo(500, 0);
			  }
			);	
		}
		
	}); 
}

function fadeout( element, page )
{
	if( element == "masters" )
	{
		if( page == "landing" )
		{
			$( "#img_" + element ).fadeTo( 2000, 0 );
		}
		else
		{
			$( "#img_" + element ).fadeTo( 100, 0 );
		}
	}
	else
	{
		$( "#img_" + element ).fadeTo( 500, 0 );
	}
}
