$(document).ready(function() {
	//
	// Auto-clearing form fields
	//
	$(".empty-on-click").focus
	(function(){
		var $this = $(this);
		if($this.hasClass('empty-on-click'))
		{
			$this.attr       ('orig_value', $this.val())
			     .val        ('')
			     .removeClass('empty-on-click')
		}
	})
	                         .blur
	(function(){
		var $this = $(this);
		if($this.val() == '')
		{
			$this.addClass('empty-on-click')
			     .val     ($this.attr('orig_value'));
		}
	});
	
	//
	// Gallery
	//
	$(".gallery a").prettyPhoto();
	$("a.prettyPhoto").prettyPhoto();
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	//
	// Header image rotation
	//
	var $header_lower  = $("#header-lower");
	var $header_higher = $("#header-higher");
	
	var time_main_image_hold = 5000; // Length of time to show each image
	var time_main_image_tras = 3000; // Length of time to take in the transition
	
	var default_tagline = 'Welcome!';
	var default_tagdesc = 'You have arrived at your complete source of leading edge martial arts information';
	var default_tagcta  = 'Book your amazing free 30-day trial now!';
	
	var state =
	[
		{
			image:   "index-1",
			tagline: default_tagline,
			tagdesc: default_tagdesc,
			tagcta:  default_tagcta
		},
		{
			image:   "index-2",
			tagline: "Kids Kung Fu",
			tagdesc: "Would you like your child to have more discipline, confidence and focus? Let us show you how Kung Fu can do this and so much more",
			tagcta:  "Book your free 30-day trial!"
		},
		{
			image:   "index-3",
			tagline: "Wing Chun Kung Fu",
			tagdesc: "We are a professional martial arts school with a fully structured curriculum",
			tagcta:  "Book your free classes now!<br />Free parking on site"
		},
		{
			image:   "index-4",
			tagline: "Never boring with our beginner to black belt training programs.",
			tagdesc: "<br />Great instructors teaching beginners friendly classes.<br />You\'ve got nothing to lose and everything to gain !",
			tagcta:  "Book your 30 day free trial period now !"
		},
		{
			image:   "index-5",
			tagline: "Serious Self-Defence Skills",
			tagdesc: "Learn skills &amp; techniques you need to survive a confrontation & key skills to stop trouble in its tracks!",
			tagcta:  "Book your amazing 30 days' free martial arts classes today!"
		},
		{
			image:   "index-6",
			tagline: "Learn Kung-fu!",
			tagdesc: "Learn self defence with a smile at Croydon\'s friendliest martial arts school!",
			tagcta:  "Please book your free 30 day trial now!"
		},
		{
			image:   "index-7",
			tagline: "Not just the ABC's of self-defence,",
			tagdesc: "but also the ABC's of life: Attitude, Behaviour and Character building for your child!<br />Let us show you what Kung Fu can do for your child, and so much more!",
			tagcta:  "Call to book your free 30 days trial now!"
		},
		{
			image:   "index-8",
			tagline: "Martial arts classes to meet every individual's needs.",
			tagdesc: "<br />We want to find out what YOU'RE looking for in martial arts!<br />Come and tell us on your 30 days' free trial!",
			tagcta:  "All you need to do is call us to book!"
		}
	];
	
	var main_image_total = state.length; // Total number of images to cycle through
	
	function rotate(i)
	{
		if(i >= main_image_total) i = 0;
		
		var new_state = state[i];
		var image   = 'url(/images/header/' + new_state.image + '.jpg)';
		var tagline = new_state.tagline;
		var tagdesc = new_state.tagdesc;
		var tagcta  = new_state.tagcta;
		
		var $header_lower_ii = $header_lower.children(":first-child").children(":first-child");
		
		$header_lower_ii.children(".tagline").html(tagline);
		$header_lower_ii.children(".tagdesc").html(tagdesc);
		$header_lower_ii.children(".tagcta").html(tagcta);
		$header_lower.css('background-image', image);
		
		$header_higher.delay(time_main_image_hold).fadeOut(time_main_image_tras, function() {
			var $this   = $(this);
			var $this_ii = $this.children(":first-child").children(":first-child");
			
			$this_ii.children(".tagline").html(tagline);
			$this_ii.children(".tagdesc").html(tagdesc);
			$this_ii.children(".tagcta").html(tagcta);
			$this.css('background-image', image)
			     .fadeIn(0);
			rotate(i + 1);
		});
	}
	
	rotate(1);
	
	//
	// Header image hover
	//
	var $header_highest = $("#header-highest");
	var $menu_items     = $("#header-navbar > ul > li > a, #header-navbar > ul > li > ul > li > a");
	
	$header_highest.hide();

	$menu_items.mouseover(function(){
		var new_state =
		{
			image:   "index-1",
			tagline: default_tagline,
			tagdesc: default_tagdesc,
			tagcta:  default_tagcta
		};
		
		switch($(this).attr('href'))
		{
			case '/about-us':
				new_state =
				{
					image:   "index-3",
					tagline: "About Us",
					tagdesc: "We are a professional martial arts school with a fully structured curriculum",
					tagcta:  "Book your free classes now! Free parking on site"
				};
				break;
			case '/about-kung-fu':
				new_state =
				{
					image:   "bruce-lee",
					tagline: "About Kung Fu",
					tagdesc: "We are a professional martial arts school with a fully structured curriculum",
					tagcta:  "Book your free classes now! Free parking on site"
				};
				break;
			case '/about-iwka':
				new_state =
				{
					image:   "index-3",
					tagline: "About the IWKA",
					tagdesc: "Our Kung Fu Big Brother!",
					tagcta:  "Learn of our connection to Wing Chun around the world!"
				};
				break;
			case '/press-releases':
				new_state =
				{
					image:   "index-3",
					tagline: "Press Releases",
					tagdesc: "Exciting News and Information",
					tagcta:  "Find out what's been happening at Kung Fu Schools!"
				};
				break;
			case '/about-us':
				new_state =
				{
					image:   "index-3",
					tagline: "About Us",
					tagdesc: "We are a professional martial arts school with a fully structured curriculum",
					tagcta:  "Book your free classes now! Free parking on site"
				};
				break;
			case '/links':
				new_state =
				{
					image:   "links",
					tagline: "Links",
					tagdesc: "We are a professional martial arts school with a fully structured curriculum",
					tagcta:  "Book your free classes now! Free parking on site"
				};
				break;
			case '/adult-classes':
				new_state =
				{
					image:   "adults",
					tagline: "Adults (13+)",
					tagdesc: "It’s never too late to start! Haven’t done a day’s training in your life? No problem! Our martial art is a great form of self-defence!",
					tagcta:  "Book your 30-day free trial now!"
				};
				break;
			case '/online-store':
				new_state =
				{
					image:   "store",
					tagline: "On-line Store",
					tagdesc: "It’s never too late to start! Haven’t done a day’s training in your life? No problem! Our martial art is a great form of self-defence!",
					tagcta:  "Book your 30-day free trial now!"
				};
				break;
			case '/adult-timetable':
				new_state =
				{
					image:   "timetable",
					tagline: "Adult Timetable",
					tagdesc: "It’s never too late to start! Haven’t done a day’s training in your life? No problem! Our martial art is a great form of self-defence!",
					tagcta:  "Book your 30-day free trial now!"
				};
				break;
			case '/kids-classes':
				new_state =
				{
					image:   "index-2",
					tagline: "Kids Kung Fu",
					tagdesc: "Would you like your child to have more discipline, confidence and focus? Let us show you how Kung Fu can do this and so much more",
					tagcta:  "Book your free 30-day trial!"
				};
				break;
			case '/little-dragons':
				new_state =
				{
					image:   "little-dragons",
					tagline: "Little Dragons (4 - 7 Yrs)",
					tagdesc: "Would you like your child to have more discipline, confidence and focus? Let us show you how Kung Fu can do this and so much more",
					tagcta:  "Book your free 30-day trial!"
				};
				break;
			case '/juniors':
				new_state =
				{
					image:   "juniors",
					tagline: "Juniors (7 - 12 Yrs)",
					tagdesc: "Would you like your child to have more discipline, confidence and focus? Let us show you how Kung Fu can do this and so much more",
					tagcta:  "Book your free 30-day trial!"
				};
				break;
			case '/news':
				new_state =
				{
					image:   "index-4",
					tagline: "News",
					tagdesc: "Great instructors teaching beginners friendly classes.<br />You\'ve got nothing to lose and everything to gain !",
					tagcta:  "Book your 30 day free trial period now !"
				};
				break;
			case '/diary':
				new_state =
				{
					image:   "diary",
					tagline: "Diary",
					tagdesc: "Great instructors teaching beginners friendly classes.<br />You\'ve got nothing to lose and everything to gain !",
					tagcta:  "Book your 30 day free trial period now !"
				};
				break;
			case '/testimonials':
				new_state =
				{
					image:   "testimonials",
					tagline: "Testimonials",
					tagdesc: "Would you like your child to have a fun activity ? More concentration and Focus ?",
					tagcta:  "Please Book your Free Classes Now !!!"
				};
				break;
			case '/gallery':
				new_state =
				{
					image:   "index-6",
					tagline: "Photo Gallery",
					tagdesc: "Learn self defence with a smile at Croydon\'s friendliest martial arts school!",
					tagcta:  "Please book your free 30 day trial now!"
				};
				break;
			case '/videos':
				new_state =
				{
					image:   "videos",
					tagline: "Video Gallery",
					tagdesc: "Learn self defence with a smile at Croydon\'s friendliest martial arts school!",
					tagcta:  "Please book your free 30 day trial now!"
				};
				break;
			case '/find-us':
				new_state =
				{
					image:   "find-us",
					tagline: "Find Us",
					tagdesc: default_tagdesc,
					tagcta:  default_tagcta
				};
				break;
			case '/contact-us':
				new_state =
				{
					image:   "contact-us",
					tagline: "Contact Us",
					tagdesc: "Let us Help You",
					tagcta:  "Please book your free 30 Days Trial Now !!!"
				};
				break;
		}
		
		var image   = 'url(/images/header/' + new_state.image + '.jpg)';
		var tagline = new_state.tagline;
		var tagdesc = new_state.tagdesc;
		var tagcta  = new_state.tagcta;
		
		var $header_highest_ii = $header_highest.children(":first-child").children(":first-child");
		
		$header_highest_ii.children(".tagline").html(tagline);
		$header_highest_ii.children(".tagdesc").html(tagdesc);
		$header_highest_ii.children(".tagcta").html(tagcta);
		$header_highest.css('background-image', image);
		
		$header_highest.show();
	});
	
	$menu_items.mouseout(function(){
		$header_highest.hide();
	});
});


