$(document).ready(function() {
	
	// SITE MESSAGE FADE
	$('#site_msg').delay(7000).animate({'top' : '-=42px'}, 'slow');
	
	//test for facility pics anitmation
//	$('.facility_pics').hover(function() {
//		$(this).find('img').animate({'width' : '+=5px', 'height' : '+=5px'},200);									
//	},function() {
//		$(this).find('img').animate({'width' : '-=5px', 'height' : '-=5px'},200);
//	});
	
	
	// ======== GET THE MIDDLE ADVERT TO WORK ========= //
	//$('.advert_middle a, advert_middle2 a').removeAttr('href');
	$('.advert_middle, advert_middle2').css({'cursor' : 'pointer'});
	$('.advert_middle, advert_middle2').click(function() {
		$(this).css({'marginBottom' : '0px'});											   
		$('#advertMiddle_detail_container').show();												   
	});
	
	$('#advertMiddle_detail_close').click(function() {
		$(this).parent().parent().fadeOut(0);
		$('.advert_middle, advert_middle2').css({'marginBottom' : '17px'});	
	});
	
	
	// ============= TESTIMONIALS PAGE =============== //
	$('.testimonial_link a').removeAttr('href');
	
	//set first testimonial as the displayed one
	$('.testimonial_link:first').addClass('Subhover');
	$('.testimonial_detail_image').html('<img src="files/testimonial/' + $('.testimonial_link:first').find('img').attr('lang') + '" width="80" height="82" title="' + $('.testimonial_link:first').find('img').attr('title') + '" />');
	$('.testimonial_detail_header').html($('.testimonial_link:first').find('img').attr('title'));
	$('.testimonial_detail_txt').html($('.testimonial_link:first').find('img').attr('alt'));
	
	//create the select function
	$('.testimonial_link').click(function() {
		if($('.testimonial_link').hasClass('Subhover')) {
			$('.testimonial_link').removeClass('Subhover');	
		}
		$(this).addClass('Subhover');
		$('.testimonial_detail_image').html('<img src="files/testimonial/' + $(this).find('img').attr('lang') + '" width="80" height="82" title="' + $(this).find('img').attr('title') + '" />');
		$('.testimonial_detail_header').html($(this).find('img').attr('title'));
		$('.testimonial_detail_txt').html($(this).find('img').attr('alt'));
		$('#testimonail_detail_wrapper').slideto({highlight : false});
		
	});
	
	// ============== LEFT INPUT AREAS ================//
	// --------- BOOK A VISIT
	//make drop dewn work
	$('#book_tour').click(function() {
		$('.book_a_visit').toggle();							 
	});
	// adjust css on click
	$('.left_input #book_name, .left_input #book_email, .left_input #book_phone').css({'color' : '#6c7072'});
	$('.left_input #book_name').val('Enter Your Name Here');
	$('.left_input #book_email').val('Enter Your Email Here');
	$('.left_input #book_phone').val('Enter A Contact Number Here');
	
	//remove css on click
	$('.left_input #book_name').click(function() {
		if($(this).val() == 'Enter Your Name Here') {
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	$('.left_input #book_email').click(function() {
		if($(this).val() == 'Enter Your Email Here') {
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	$('.left_input #book_phone').click(function() {
		if($(this).val() == 'Enter A Contact Number Here') {
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	
	$('#book_btn').click(function() {
		var b_name = $('.left_input #book_name').val();								
		var b_email = $('.left_input #book_email').val();
		var b_phone = $('.left_input #book_phone').val();
		
		$('.book_a_visit').fadeOut(500);
		$('.book_a_visit_success').load('load_tour.php?b_name=' + b_name + '&b_email=' + b_email + '&b_phone=' + b_phone);
		$('.book_a_visit_success').fadeIn(600);
		$('.book_a_visit_success').delay(6000).fadeOut(600);
		$('.book_a_visit').delay(7000).fadeIn(500);
	});
	
	// --------- NEWSLETTER SIGN UP
	//make drop dewn work
	$('#news_signup').click(function() {
		$('.newsletter_sign_up').toggle();							 
	});
	// adjust css on click
	$('.left_input #news_signup, .left_input #news_signup_name').css({'color' : '#6c7072'});
	$('.left_input #news_signup').val('Enter Your Email Here');
	$('.left_input #news_signup_name').val('Enter Your Name Here');
	
	//remove css on click
	$('.left_input #news_signup').click(function() {
		if($(this).val() == 'Enter Your Email Here') {
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	$('.left_input #news_signup_name').click(function() {
		if($(this).val() == 'Enter Your Name Here') {
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	
	$('#news_signup_btn').click(function() {
		var n_email = $('.left_input #news_signup').val();								
		var n_name = $('.left_input #news_signup_name').val();
		
		$('.newsletter_sign_up').fadeOut(500);
		$('.newsletter_sign_up_success').load('load_newsletter.php?email=' + n_email + '&name=' + n_name);
		$('.newsletter_sign_up_success').fadeIn(600);
		$('.newsletter_sign_up_success').delay(6000).fadeOut(600);
		$('.newsletter_sign_up').delay(7000).fadeIn(500);
	});
	
	// ============== Media Page ===================
	// make tabs change class
	$('.m_tabs').click(function() {
		
		if($('.m_tabs').hasClass('Subhover')) {
			$('.m_tabs').removeClass('Subhover');	
		}
		$(this).addClass('Subhover');
	});
	
	// make image folder change class on hover
	$('.m_gallery_container').hover(function() {
		$(this).children().addClass('Subhover');											   
	} ,function() {
		$(this).children().removeClass('Subhover');
	});
	
	// load images from the selected category
	$('.m_gallery_container').click(function() {
											 
		var mode = $(this).find('img').attr('alt');	
		var cat = $(this).find('img').attr('lang');	
		
		$('.media_container').load('load_images.php?mode=' + mode + '&cat=' + cat);
	});
	
	// load the images again
	$('#images, #images1').click(function() {						
		$('.media_container').load('load_images.php');
	});
	
	
	// load selected video
	$('.m_video_container').click(function() {
											 
		//var mode = $(this).find('img').attr('alt');	
		var video_id = $(this).find('img').attr('alt');	
		var title = $(this).find('img').attr('title');
		
		$('.media_title').html(title);
		$('.video_container_box').html('<iframe width="840" height="457" style="border:solid 2px #5D5D5D;" src="http://www.youtube.com/embed/' + video_id + '?rel=0&amp;hd=1" frameborder="0" allowfullscreen></iframe>');
		$('.video_player_box').fadeIn(0);
		$('.video_player_box').slideto({highlight: false});
	});
	
	// load the videos
	$('#videos').click(function() {						
		$('.media_container').load('load_videos.php');
	});
	
	$('#video_blogs').click(function() {						
		$('.media_container').load('load_blogs.php');
	});
	
	// make video folder change class on hover
	$('.m_video_container').hover(function() {
		$(this).children().addClass('Subhover');											   
	} ,function() {
		$(this).children().removeClass('Subhover');
	});
	
	// load selected video
	$('.m_video_container').click(function() {
											 
		//var mode = $(this).find('img').attr('alt');	
		var video_id = $(this).find('img').attr('alt');	
		var title = $(this).find('img').attr('title');
		
		$('.media_title').html(title);
		$('.video_container_box').html('<iframe width="840" height="457" style="border:solid 2px #5D5D5D;" src="http://www.youtube.com/embed/' + video_id + '?rel=0&amp;hd=1" frameborder="0" allowfullscreen></iframe>');
		$('.video_player_box').fadeIn(0);
		$('.video_player_box').slideto({highlight: false});
	});
	
	// load the downloads
	$('#downloads').click(function() {						
		$('.media_container').load('load_downloads.php');
	});
	

	
	//=============================================
	
	// Contact Page
	//ADD TEMP STYLE
	$('.contact_right #name,.contact_right #contact,.contact_right #enquiry').css({'color' : '#6c7072'});
	$('.contact_right #name').val('Your Name');
	$('.contact_right #contact').val('Contact Number Or Email');
	$('.contact_right #enquiry').val('Your Enquiry');
	
	//REMOVE TEMP STYLE ON CLICK
	$('.contact_right #name').click(function() {
		if($(this).val() == 'Your Name') {
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	$('.contact_right #contact').click(function() {
		if($(this).val() == 'Contact Number Or Email') {	
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	$('.contact_right #enquiry').click(function() {
		if($(this).val() == 'Your Enquiry') {	
			$(this).val('');
		}
		$(this).css({'color' : '#64caff'});
	});
	
	//Ajax Functions & error reporting
	$('.contact_btn #Submit').click(function() {
		var name = $('.contact_right #name').val();
		var contact = $('.contact_right #contact').val();
		var enquiry = $('.contact_right #enquiry').val();
		
		var dataString = ('name=' + name + '&contact=' + contact + '&enquiry=' + enquiry);
		
		$.ajax({
			type: 'POST',
			url: 'contact_process.php',
			data: dataString,
			success: function() {
				$('#contact_form').fadeOut(0);
				$('#contact_success').html('Thank You' + name + ',<br /><span style="font-size:14px">Your enquiry has been recieved and we will be contacting you shortly.</span>').fadeIn(500);
				$('#contact_success').delay(6200).fadeOut(500);
				$('.contact_right #name').val('');
				$('.contact_right #contact').val('');
				$('.contact_right #enquiry').val('');
				$('#contact_form').delay(6500).fadeIn(500);
			}
		});
		return false;
	});
	
	
	// CREATE WIDER FUNCTION TO CERTAIN PAGES
	// facility page
	$('.toggle_wide').show();
	$('.toggle_wide').click(function () {
		if($('.toggle_wide').hasClass('Subhover')) {
			$('#content_full').children().appendTo('#right_content').show();
			$('#right_content, #left_content').show();
			$('#content_full, #news_detail_container, #advert_detail_container, #video_detail_container').fadeOut();
		} else {
			$('#right_content').children().appendTo('#content_full');
			$('#content_full').show();
			$('#right_content, #left_content').fadeOut();
		}
		
		$(this).toggleClass('Subhover');
	});
	//--------------
	
	// membership page
	$('.m_pics').click(function() {
		// find the selected membership option
		var selection = $(this).find('img').attr('alt');
		var color = $(this).find('img').attr('lang');
		
		//create the function to hide or show default
		//function hideDefault() {
			$('#default').fadeOut(0);	
		//};
		//function showDefault() {
		//	$('#default').show();	
		//};
		
		if(selection == 'gold') {
			$('.membership_color').css({"background" : color});
			$('#gold_wrapper').show();
			$('#silver_wrapper').fadeOut(0);
			$('#pink_wrapper').fadeOut(0);
			$('#kids_wrapper').fadeOut(0);
			$('#student_wrapper').fadeOut(0);
			$('#weekend_wrapper').fadeOut(0);
		}
		if(selection == 'silver') {
			$('.membership_color').css({"background" : color});
			$('#silver_wrapper').show();
			$('#gold_wrapper').fadeOut(0);
			$('#pink_wrapper').fadeOut(0);
			$('#kids_wrapper').fadeOut(0);
			$('#student_wrapper').fadeOut(0);
			$('#weekend_wrapper').fadeOut(0);
		}
		if(selection == 'womens') {
			$('.membership_color').css({"background" : color});
			$('#pink_wrapper').show();
			$('#silver_wrapper').fadeOut(0);
			$('#gold_wrapper').fadeOut(0);
			$('#kids_wrapper').fadeOut(0);
			$('#student_wrapper').fadeOut(0);
			$('#weekend_wrapper').fadeOut(0);
		}
		if(selection == 'kids') {
			$('.membership_color').css({"background" : color});
			$('#kids_wrapper').show();
			$('#silver_wrapper').fadeOut(0);
			$('#pink_wrapper').fadeOut(0);
			$('#gold_wrapper').fadeOut(0);
			$('#student_wrapper').fadeOut(0);
			$('#weekend_wrapper').fadeOut(0);
		}
		if(selection == 'student') {
			$('.membership_color').css({"background" : color});
			$('#student_wrapper').show();
			$('#silver_wrapper').fadeOut(0);
			$('#pink_wrapper').fadeOut(0);
			$('#kids_wrapper').fadeOut(0);
			$('#gold_wrapper').fadeOut(0);
			$('#weekend_wrapper').fadeOut(0);
		}
		if(selection == 'weekend') {
			$('.membership_color').css({"background" : color});
			$('#weekend_wrapper').show();
			$('#silver_wrapper').fadeOut(0);
			$('#pink_wrapper').fadeOut(0);
			$('#kids_wrapper').fadeOut(0);
			$('#student_wrapper').fadeOut(0);
			$('#gold_wrapper').fadeOut(0);
		}
	});
	//----------------
	
	//Attach the go up link
	$('#go_up').show();
	$('#go_up').click(function () {
		$('#header').slideto({highlight : false});							
	});
	
	// MAKE HOME PAGE VIDEO WORK
	$('.home_tour').click(function() {
		$('.home_video').show();							   
	});
	$('.home_close').click(function() {
		$('.home_video').fadeOut(1);								
	});
	
	
	// Ad Pointer  to panel tabs
	$('.panel_tabs').css({'cursor' : 'pointer'});
	$('.panel_tabs').click(function() {
		$(this).toggleClass('Subhover');								
	});
	
	// +++++++++++++ NEWS FUNCTION ++++++++++++++ //
	// remove href links from left panels
	$('.news_container a').removeAttr('href'); // news
	// add css to enable cursor
	$('.news_container').css({'cursor' : 'pointer'}); // news
	
	//creat panel click functions for news
	$('#news_tab').click(function() {
		$('.news_container, .all_news_link').toggle();						  
	});
	
	// when news is clicked display the corect news
	$('.news_container').click(function() {
										
		// remove any classes that are not clicked
		if($('.news_container').hasClass('Subhover')) {
			$('.news_container').removeClass('Subhover');	
		}
		// add class to this
		$(this).addClass('Subhover');
		
		// change the details to selected ones
		$('#news_detail_image').html('<img src="../files/news_images/' + $(this).find('img').attr('lang') + '" width="674" height="327" title="' + $(this).find('img').attr('title') + '"/>');
		$('#news_detail_header').html($(this).find('img').attr('title'));
		$('#news_detail_text').html($(this).find('img').attr('alt'));
		
		// show new detail
		$('#news_detail_container').show();
		
		// slide viewer to read the news
		$('#news_detail_container').slideto({highlight: false});
	});
	
	// Create close function to disable news
	$('#news_detail_close').click(function() {
		$(this).parent().parent().hide();
		$('.news_container').removeClass('Subhover');
		$('#right_content').slideto({highlight: false});
	});
	// ++++++++++++++++++++++++++++++++++++++++++ //
	
	
	// +++++++++++++ LEFT ADVERT FUNCTION ++++++++++++++ //
	// remove href links from left panels
	$('.advert_left a, .advert_left2 a').removeAttr('href'); // left advert
	// add css to enable cursor
	$('.advert_left, .advert_left2').css({'cursor' : 'pointer'}); // left advert
	
	// when news is clicked display the corect left advert
	$('.advert_left, .advert_left2').click(function() {
										
		// remove any classes that are not clicked
		if($('.advert_left, .advert_left2').hasClass('Subhover')) {
			$('.advert_left, .advert_left2').removeClass('Subhover');	
		}
		// add class to this
		$(this).addClass('Subhover');
		
		// change the details to selected ones
		$('#advert_detail_image').html('<img src="files/adverts/' + $(this).find('img').attr('alt') + '" title="' + $(this).find('img').attr('title') + '"/>');
		$('#advert_detail_text').html($(this).find('img').attr('lang'));
		
		// show left advert detail
		$('#advert_detail_container').show();
		
		// slide viewer to read the left advert
		$('#advert_detail_container').slideto({highlight: false});
	});
	
	// Create close function to disable left advert
	$('#advert_detail_close').click(function() {
		$(this).parent().parent().hide();
		$('.advert_left, .advert_left2').removeClass('Subhover');
		$('#right_content').slideto({highlight: false});
	});
	// ++++++++++++++++++++++++++++++++++++++++++ //
	
	
		// +++++++++++++ VIDEO ADVERT FUNCTION ++++++++++++++ //
	// remove href links from video
	$('.video_container a').removeAttr('href'); // VIDEO advert
	// add css to enable cursor
	$('.video_container').css({'cursor' : 'pointer'}); // VIDEO advert
	
	//creat panel click functions for videos
	$('#videos_tab').click(function() {
		$('.video_container, .all_videos_link').toggle();								
	});
	
	// when VIDEO is clicked display the corect VIDEO advert
	$('.video_container').click(function() {
										
		// remove any classes that are not clicked
		if($('.video_container').hasClass('Subhover')) {
			$('.video_container').removeClass('Subhover');	
		}
		// add class to this
		$(this).addClass('Subhover');
		
		// change the details to selected ones
		$('#video_detail_box').html('<iframe width="674" height="373" style="border:solid 2px #5D5D5D;" src="http://www.youtube.com/embed/' + $(this).find('img').attr('lang') + '?rel=0&amp;hd=1" frameborder="0" allowfullscreen></iframe>');
		$('#video_detail_header').html($(this).find('img').attr('title'));
		$('#video_detail_text').html($(this).find('img').attr('info'));
		
		// show VIDEO advert detail
		$('#video_detail_container').show();
		
		// slide viewer to read the VIDEO advert
		$('#video_detail_container').slideto({highlight: false});
	});
	
	// Create close function to disable VIDEO advert
	$('#video_detail_close').click(function() {
		$(this).parent().parent().hide();
		$('.video_container').removeClass('Subhover');
		$('#right_content').slideto({highlight: false});
	});
	// ++++++++++++++++++++++++++++++++++++++++++ //
});

