// JavaScript Document

var firstCLick = true;
var currentTab = '';
var currentSubpage = '';
var activeLink = '.first-page-link';
transitionInProgress=false;
$("#disableFlash").css({'display' : 'block'});
$("html").css({'cursor' : 'wait'});
$("a").css({'cursor' : 'wait'});


$(document).ready(function(){
	$("html").css({'cursor' : 'default'});
	$("a").css({'cursor' : 'pointer'});
	$("#disableFlash").css({'display' : 'none'});
	$("#flashContent").css({'cursor' : 'default'});
	$(".faderDiv, .page-content").css({'display' : 'none','position' : 'absolute','top' : '0'});
	
	$('.subpage-link').click(function(event) {									  
		event.preventDefault();
		if(!transitionInProgress){
			transitionInProgress = true;
			var classHolder = String($(event.target).attr('class').split(' ').slice(-1));
			//$(activeLink).css({'color' : '#555'});	
			$(activeLink).removeClass('activeLink');
			activeLink = "."+classHolder; 
			//$(activeLink).css({'color' : '#cc3399'});
			$(activeLink).addClass('activeLink');
	 		changeSubSection(classHolder);			
		}
	});
	
	function changeSubSection(clickedID){		
		$("html").css({'cursor' : 'wait'});
		$("a").css({'cursor' : 'wait'});
		$("#disableFlash").css({'display' : 'block'});
		var contentNumber = clickedID.substring(12, clickedID.length);
		
		var newSubPage = "#subpage-content"+contentNumber;
		if(newSubPage!=currentSubpage){
			$(".page-content").css({'display' : 'none'});
		
			$(newSubPage).fadeIn('slow', function() {
				currentSubpage = newSubPage;			
				transitionInProgress = false;
				$("html").css({'cursor' : 'default'});
				$("a").css({'cursor' : 'pointer'});
				$("#disableFlash").css({'display' : 'none'});
				$("#flashContent").css({'cursor' : 'default'});
				$(".page-content").css({'display' : 'none'});
				$(currentSubpage).css({'display' : 'block'});
			});
		}
		else{
			transitionInProgress = false;
				$("html").css({'cursor' : 'default'});
				$("a").css({'cursor' : 'pointer'});			
		}
	}
});

function changeSection(sectrionNumber){
	$("html").css({'cursor' : 'wait'});
	$("a").css({'cursor' : 'wait'});
	$("#disableFlash").css({'display' : 'block'});
	
	$(function(){
		if(firstCLick){
			
		 	/*$("#header-background").animate({
				height: '455px'			
		  		}, 1000, function() {
		  	});
			$("#header-top-background").animate({
				height: '202px'			
		  		}, 1000, function() {
		  	});
			$("#headerFlash").animate({
			height: '300px',
			width: '525px',
			left: '250px',
			top: '-208px'
			
		  }, 1000, function() {
		  });
			$("#sectionContainer").animate({
			top: '-130px'
			
		  }, 500, function() {
		  });
			*/
			
			
			$("#headerFlash").css({'height' : '320px', 'width' : '560px', 'left' : '300px', 'top' : '-228px'});
		 	$("#header-background").css({'height': '455px'});	
			$("#header-top-background").css({'height': '202px'});
			
			$("#main-background").css({'display' : 'block'});
			//$("html").css({'height' : '100%'});
			//$("body").css({'height' : '100%'});
			//$("#mainDiv").css({'height' : '100%'});
			$("#sectionContainer").css({"top" : "-180px"});
			$("#welcome").css({"display" : "none"});
			$("#logo-container").css({"margin-left" : "120px"});
			firstCLick = false;
			$("#homePageFooter").css({"display" : "none"});
		}
		
		var newSection = "#section"+sectrionNumber;
		
		if(newSection!=currentTab){
			
			$(".faderDiv").css({'display' : 'none'});
			//$(".firstLink").css({'color' : '#cc3399'});
			$('.firstLink').addClass('activeLink');
			
			$(".page-content").css({'display' : 'none'});
			$(".first-page-content").css({'display' : 'block'});
			$(newSection).fadeIn('slow', function() {
				//$(activeLink).css({'color' : '#555'});				
				$(activeLink).removeClass('activeLink');
				activeLink = '.first-page-link';
				//$(activeLink).css({'color' : '#cc3399'});				
				$(activeLink).addClass('activeLink');
				currentTab = newSection;			
				transitionInProgress = false;
				currentSubpage = '.first-page-content';
				$("html").css({'cursor' : 'default'});
				$("a").css({'cursor' : 'pointer'});
				$("#disableFlash").css({'display' : 'none'});
				$("#flashContent").css({'cursor' : 'default'});
				$(".faderDiv").css({'display' : 'none'});
				$(currentTab).css({'display' : 'block'});
			});
		}
		
	});
}
