// remap jQuery to $
(function($){})(window.jQuery);

/* trigger when page is ready */
$(document).ready(function (){
    
	$('#username, #password').defaultValue();
	
	$('nav[role="home"] section').bind({
		mouseenter: function(event) {
			var img = $(this).attr('class');
			//$(this).css("background-image", "url(/images/backgrounds/home_"+img+".jpg)");
			$(this).addClass('selected');
	},
		mouseleave: function(event) {
			//$(this).css("background-image", "none"); 
			$(this).removeClass('selected');
		}
	});
	

});


$(document).ready(function() {
    // INDEX SWAP IMAGE //////////////////////////////////////////////////
    
   	$(".c1").hover(function(){
        $("#emr-color").stop().fadeTo(500, 0);
    }, function() {  
        $("#emr-color").stop().fadeTo(500, 1);
    }); 
     
     
    $(".c2").hover(function(){
		$("#business-color").stop().fadeTo(500, 0);
    }, function() {  
        $("#business-color").stop().fadeTo(500, 1);
    }); 
     
    $(".c3").hover(function(){
		$("#it-color").stop().fadeTo(500, 0);
    }, function() {  
        $("#it-color").stop().fadeTo(500, 1);
    }); 
    $(".login form button").click(function() {
        $(".login form").submit();
    });
    // CURRENT PAGE HIGHLIGHT//////////////////////////////////////////////////
	// var url = window.location.href;
	// url = url.substr(url.lastIndexOf("/") + 1);
	// $(".subpages").find("a[href='" + url + "']").addClass("on");
    
});

$(function(){
	
	var url = $.param.fragment();

	if (url != '') {
		
		var link = $('#subNav').find('a[href="#'+url+'"]');
		
		$('#subNav a').removeClass('subSelect');
		link.addClass('subSelect');
		
		var navObj = link.attr('data-link');

		loadContent(navObj);
		
	}
	else {
		
		if($('#subPageContent').hasClass('fourzerofour')){ return; }
		
		var link = $('#subNav li:first-child a');
		
		var navObj = link.attr('data-link');
		
		loadContent(navObj);

	}
	
	function loadContent(navObj) {
		
		$("#subPageContent").load(navObj + " .content_wrap", function() {
        
			$("#subPageContent .content_wrap").animate({opacity: 1}, function(){
				jQuery(function($) {
					// settings
					var animationDuration    = 1000,
						singleSlideDuration  = 6000,
						initialSlideDuration = 9000;

					var $lists = $('ul.fadeshow'),
						timer;

					var next = function () {
						if (timer) {
							clearTimeout(timer);
							timer = null;
						}

						$lists.each(function () {
							var $list    = $(this),
								$current = $list.find('li.active:first'),
								$next    = $current.next();

							// wrap-around if we've reached the last element
							if ($next.length === 0) {
								$next = $list.find('li:first');
							}

							$current.fadeOut(animationDuration);
							$next.fadeIn(animationDuration, function () {
								$next.addClass('active');
								$current.removeClass('active');
								timer = setTimeout(next, singleSlideDuration);
							});
						});
					};

					$lists.click(next);
					timer = setTimeout(next, initialSlideDuration);
				});
			});
			initServicesNav();
			
    	});
	}
	
  // sub page ajaxification!
	$("ul#subNav li a").click(function() {
		
		var $this = $(this);
		
		$("#subNav li a").removeClass("subSelect");
		
		$this.addClass("subSelect");

		$("#subPageContent .content_wrap").animate({opacity: 0}, function() {

		    $("#subPageContent").load($this.attr("data-link") + " .content_wrap", function() {

				$("#subPageContent .content_wrap").animate({opacity: 1}, function(){
					jQuery(function($) {
						// settings
						var animationDuration    = 1000,
							singleSlideDuration  = 6000,
							initialSlideDuration = 9000;

						var $lists = $('ul.fadeshow'),
							timer;

						var next = function () {
							if (timer) {
								clearTimeout(timer);
								timer = null;
							}

							$lists.each(function () {
								var $list    = $(this),
									$current = $list.find('li.active:first'),
									$next    = $current.next();

								// wrap-around if we've reached the last element
								if ($next.length === 0) {
									$next = $list.find('li:first');
								}

								$current.fadeOut(animationDuration);
								$next.fadeIn(animationDuration, function () {
									$next.addClass('active');
									$current.removeClass('active');
									timer = setTimeout(next, singleSlideDuration);
								});
							});
						};

						$lists.click(next);
						timer = setTimeout(next, initialSlideDuration);
					});
				});
					initServicesNav();
					
		    });
		});

	});



});

