/////////////
// Actions //
/////////////

// Set Global Variables


// Document Ready
$(document).ready( 
	function() {
		
		// Get Time
		var dateTime = new Date().getTime();
		
		// Hide Scroll Bars Via JS
		$("body").css("overflow", "hidden");
		$("#content").css("height", "5000px");
		
		// Set all background positions manually to fix IE bug in backgroundPosition script
		$("#header-wrapper").css({backgroundPosition: '0px -100px'});
		$("#hero").css({backgroundPosition: '0px -400px'});
		$("#heroTwo").css({backgroundPosition: '0px -400px'});
		
		// Reset Scroll Position on Refresh
		scrollPage(0);
		
		// Load Additional JS Content
		$("#load-js-content").load("/content/template/js-content.php");
		
		// Run Load Scripts
		loadHomePage();
			// still need to .load the extra homepage content. this way it will only show on the homepage with js
			// these pages must be built and implemented via HTML .php
	}
);


/*
 * scrollPage()
 */
function scrollPage(altPageY) {
	
	if ( $.browser.msie ) {
		$("html").animate({ scrollTop: (altPageY-90)}, 500 );
		
	} else if ( $.browser.mozilla ) {
		$("html").animate({ scrollTop: altPageY}, 500 );
		
	} else {
		$("body").animate({ scrollTop: altPageY}, 500 );
		
	}

}


/*
 * click()
 */
function click(id) {
	$('#' + id + ' a').click();
}


/*
 * jquerySeoLinks()
 */
function jquerySeoLinks() {
  if (document.getElementsByTagName) {
    var links = document.getElementsByTagName("a");
    for (var i=0; i < links.length; i++) {
      if (links[i].className.match("navLink")) {
        links[i].onclick = function() {
        	
        	var currentId = $(this).parent().attr('id');
        	
        	// remove all active menu item classes
        	$('#navigation li').removeClass('active-menu-item');
        	
        	// reset all bg images to normal
        	$('#nav-who').css( { background: "url(/media/images/nav-who.png) center top no-repeat" } );
			$('#nav-what').css( { background: "url(/media/images/nav-what.png) center top no-repeat" } );
			$('#nav-our').css( { background: "url(/media/images/nav-our.png) center top no-repeat" } );
			$('#nav-contact').css( { background: "url(/media/images/nav-contact.png) center top no-repeat" } );
        	
        	// set active class to bypass hover feature
        	$(this).parent().addClass('active-menu-item');

        	// set background next
        	$(this).parent().css( { background: "url(/media/images/" + currentId + "-hover.png) center top no-repeat" } );
        	
        	var altPageY=this.getAttribute("alt");
        	scrollPage(altPageY);
        	
          return false;
        };
      }
    }
  }
}


/*
 * animateHeader()
 */
function animateHeader() {
	$("#header-wrapper").animate({backgroundPosition: '100% 22px'}, 12000, function() {
		$("#header-wrapper").animate({backgroundPosition: '0% 22px'}, 12000);
	});
}


/*
 * loadHomePage()
 */
function loadHomePage() {
	
	// Set the SEO Links Before Nav Is Displayed
	jquerySeoLinks();
	
	// Set Navigation Fade In / Fade Out Before Nav Is Displayed
	mosevoNavigate();
	
	$("#html-cover").animate({opacity: '0'}, 800, function() {
		$("#header-wrapper").css('position','fixed').animate({backgroundPosition: '50% 22px'}, function() {
			
			// Animate the header
			animateHeader();
			setInterval('animateHeader()', 32000);		
			
			$("#header-content").fadeIn('slow', function() {
				// add header-wrapper background color
				$("#header-wrapper").css('background-color','#000000');
				
				// slide down hero backgrounds
				$("#hero").animate({backgroundPosition: '0px 0px'}, 400, function() { 
					$("#heroTwo").animate({backgroundPosition: '0px 0px'}, 400, function() {
						$(".hero-content").fadeIn('slow');
						$("#heroTwoContent").fadeIn('slow');
						$(".breadcrumb").css('visibility','visible');
						$(".footer").css('visibility','visible');
						$("#html-cover").remove();				
					});
				});
			}
			);
		}
		);
	});
}




/*
 * Hero Overlay Function
 */
$(function() {

	// select the thumbnails and make them trigger our overlay
	$("#hero a.lightbox").overlay({

		// each trigger uses the same overlay with the id "gallery"
		target: '#gallery',

		// set top to 0 to position under nav bar 
		top: -55,
		
		// optional exposing effect
		expose: '#000000'

	// let the gallery plugin do its magic!
	}).gallery({

		// the plugin accepts its own set of configuration options
		speed: 600
	});
});


/*
 * mosevoNavigate()
 */
function mosevoNavigate() {

	var fadeSpeed = 100;

	$('#navigation li:even').hover(
	
		function() {
		
			var currentId = $(this).attr('id');
	
			if( $(this).hasClass('active-menu-item')) { /* do not fade out */ } else {
				$(this).animate({ opacity: 0.2}, fadeSpeed,
					function() {
						$(this).css( { background: "url(/media/images/" + currentId + "-hover.png) center top no-repeat" } );
					});
				$(this).animate({ opacity: 1.0}, fadeSpeed);
			} // if clicked do nothing
		},
		function() {
		
			var currentId = $(this).attr('id');
			
			if( $(this).hasClass('active-menu-item')) { /* do not fade out */ } else {
				$(this).animate({ opacity: 0.2}, fadeSpeed,
					function() {
						$(this).css( { background: "url(/media/images/" + currentId + ".png) center top no-repeat" } );
					});
				$(this).animate({ opacity: 1.0}, fadeSpeed);
			} // if clicked do nothing
		}
	);
	
}
