$(document).ready(function(){
	
/*	CSS fix */

	//	Footer boxes
		$(".featured-services .box:nth-child(2)").css("padding-left", "+=18").css("padding-right", "+=18");	
	
	//	Image gallery
		$(".gallery .album a:nth-child(3n+1), .single-images a:nth-child(3n+0)").css("margin-left", "+=20").css("margin-right", "+=20");


/*	Functions */
	
	//	Services list, toggle content
		$(".services-list .title a").click(function(e)
		{
				e.preventDefault();
			
			//	Box ID
				contentID = $(this).attr("rel");
			
			//	Changing arrow position from top to down
				if($(".content-"+contentID).is(':visible'))
				{
					$(this).removeClass("opened");
				}
				else
				{
					$(this).addClass("opened");
				}
			
			//	Toggle	
				$(".content-"+contentID).slideToggle('slow');
		});
	
		//	Services list, expand all
			$(".services-list .expand").click(function(e)
			{
					e.preventDefault();
				
				//	
					$(".services-list .title a").addClass("opened");
				
				//	Toggle	
					$(".services-list .content").slideDown('slow');
								
			});
		
		//	Services list, close all
			$(".services-list .close").click(function(e)
			{
					e.preventDefault();
				
				//	
					$(".services-list .title a").removeClass("opened");
				
				//	Toggle	
					$(".services-list .content").slideUp('slow');
								
			});
	
	
	//	Submit for "Stormwatch™ Updates"
		$("#form-stormwatch").validate({
			submitHandler: function()
			{
				$.post("_php/_go/go.php?f=form-stormwatch", $("#form-stormwatch").serialize(),
				function(data)
				{
					//	If success
						if(data == "true")
						{
							//	Reloading login body
								$("#form-stormwatch .insideForm").fadeOut("slow");
						}
					
					//	Hiding old messages
						$("#notification").fadeOut("slow");
					
					//	Placing message
						$("#getMessage-storm").fadeIn("slow").load("_php/_go/go.php?f=getMessage&place=storm");	
					
				});
			}
		});
	
	
	//	Form - Contacts
		$("#form-contact").validate(
		{
			submitHandler: function()
			{
				$.post("_php/_go/go.php?f=form-contact", $("#form-contact").serialize(),
				function()
				{
					$('#form-contact #insideForm').fadeOut('slow').load("_php/_go/go.php?f=getFormContact #insideForm").fadeIn("slow");
				});
			}
		});
	
	
	//	On page load showing video
		var videoID = window.location.hash.substr(1);
		
		if(videoID !== "")
		{
				//	Page title - Saving old page title
					$("body").data("video-gallery", $(".regular-title h1").text());
				
				//	Page title - Getting new title
					videoTitle = $("#show-video-"+videoID+" iframe").attr("title");
				
				//	Page title - Changing page title
					$(".regular-title h1").html(videoTitle);
					
				//	
					$(".container").children().hide("slow");
				
				//	Showing video
					$("#show-video-"+videoID).show("slow");
					
					$(".container").prepend($("#show-video-"+videoID));		
					
				//	Show back button
					$(".gallery-back-button").show("bounce", {}, 500);
		}

	
	//	Video gallery
		$(".video-item a").click(function()
		{
			//	Video ID
				videoID = $(this).attr("rel");
			
			//	Page title - Saving old page title
				$("body").data("video-gallery", $(".regular-title h1").text());
			
			//	Page title - Getting new title
				videoTitle = $(".show-video-"+videoID+" iframe").attr("title");
			
			//	Page title - Changing page title
				$(".regular-title h1").html(videoTitle);
				
			//	
				$(".container").children().hide("slow");
			
			//	
				$(".show-video-"+videoID).show();
				
				$(".container").prepend($(".show-video-"+videoID));	
			
			//	Show back button
				$(".gallery-back-button").show("bounce", {}, 500);
				
		});
	
	//
		$(".gallery-back-button a").click(function()
		{
			//	Show video gallery content
				$(".container").children().show();
			
			//	Hide current video
				$(".show-video").hide("blind", {}, 500);
			
			//	Page title - Restoring page title
				$(".regular-title h1").text($("body").data("video-gallery"));
				
			//	Hide back button
				$(".gallery-back-button").hide();
		});
		
		

});	
