$(document).ready(function(){

/*** TOP - Slide Banner function ***/

	// create the horizontal scroller function
	jQuery.fn.hScroller = function(speed)
	{
		//var args = arguments[0] || {}; // get the arguments
		var s = $(this[0]); // get the element

		s.css("right", '0px') // set the tickers initial position

		// scroll one image along
		s.animate
		(
			{ right: s.outerWidth() }, speed, 'linear', 
			function()
			{
				// take the first image off the front of the queue and place it at the end
				$(this).find(".scrollerSet:first").insertAfter($(this).find(".scrollerSet:last"));
				// reset the scroller to take into account the scroll and wait 6 seconds before calling the scroller function again
				$(this).css("right", '0px').delay(10000).hScroller(speed);
			}
		);
	}
	
	// create the vertical scroller function
	jQuery.fn.vScroller = function(speed)
	{
		//var args = arguments[0] || {}; // get the arguments
		var s = $(this[0]); // get the element

		s.css("top", '0px') // set the tickers initial position

		// scroll one image along
		s.animate
		(
		 	//NLP changed to make a single right hand panel image
			{ top: -330 }, speed, 'linear', 
			function()
			{
				// take the first image off the front of the queue and place it at the end
				$(this).find(".scrollerSet:first").insertAfter($(this).find(".scrollerSet:last"));
			
				// reset the scroller to take into account the scroll and wait 6 seconds before calling the scroller function again
				$(this).css("top", '0px').delay(4000).vScroller(speed);
			}
		);
	}
	
/*** END - Slide Banner function ***/

/*** TOP - Fade Gallery function ***/

	$.fn.fadeGallery = function(speed)
	{
		// The fade gallery container
		$this = $(this);
		
		// The top most gallery image
		$topmost = $this.find("img:first");
		
		// fade the topmost image out 
		$topmost.animate({ opacity: 0 }, speed);
		
		// fade the second topmost image in
		$topmost.next().animate({ opacity: 1 }, speed,
			function()
			{
				// take the first image off the top of the queue and place it at the bottom
				$topmost.insertAfter($this.find("img:last"));
				
				// Loop the animation
				$this.delay(speed).fadeGallery(speed);
			}
		);
	}
	
/*** END - Fade Gallery function ***/

	// start the top fading images
	$("#FadeGallery").fadeGallery(5000);
	
	// start the bottom scroller working with an initial delay of 5 seconds
	$("#ServiceApps #Ticker .scroller").delay(7000).hScroller(3000);

	// start the top image links scroller working with an initial delay of 5 seconds
	$("#TopLinks .scroller").delay(2000).vScroller(1000);
	 
	
	// bind the login panel animation to the customer login button click
	$("#CustomerLogin").click
	(
		function()
		{
			loginpanel = $("#LoginPanel");
			
			if(loginpanel.css("top") == "0px")
			{
				$("#LoginPanel").animate({ top: -90, marginBottom: -90 });
			} else {
				$("#LoginPanel").animate({ top: 0, marginBottom: 0 });
			}
		}
	);
	
	// Keep the login form visible if incorrect info is submitted
	if(document.loginform.ServiceID.value != "" || document.loginform.UserID.value != "" || document.loginform.Password.value != "")
	{
		$("#LoginPanel").css("margin-bottom", 0);
		$("#LoginPanel").css("top", 0);

		$("#LoginFields input").css("color", "red");
	};

});
