$(document).ready(function(){
	//initiate
	setTimeout(function(){
		fInit();
	},2000);

	//ajax page navigation
	$("a.ajax").click(function() {
		if(!$(this).hasClass("navSelected")){
			var lnk = $(this).attr("href");
			$.ajax({
				url: lnk,
				type: "POST",
				data: "ajax=1",
				beforeSend: function() {
					$("div#main").hide();
					$('#loader').show();
				},
				success: function(d) {	
					$("div#main").fadeIn(200);
					$('#loader').hide();
					$("div#main").html(d);
					fInit();								
				},
				complete: function() {
					// hide ajax loader
					//$('#loader').fadeOut(500);
				}
			});
			$("a.ajax").removeClass("navSelected");
			$(this).addClass("navSelected");
		}
        return false;
    });
	
	/*$('#splashPopup').fadeIn()
	
	splashProgressBar();
	
	$('#splashClose').click(function(){
		$('#splashPopup').stop().fadeOut(600);
		return false;
	});*/
	
});

//init
function fInit(){
	$('.contentPanel').stop(true,true);
	
	//SHADOWBOX
	//Shadowbox.init();
	$('a.lightbox').lightBox();
	
	//INITIATE SCROLL BARS
	if($('.scrollable').length){
		$('.scrollable').tinyscrollbar({
			sizethumb:18
		});
	}
	
	//HIDE ALL PANELS & SCROLL BARS
	$('.contentPanel').hide();
	if($('.scrollbar').hasClass('hasScroll')){
		$('.scrollbar').addClass('disable');
	}
	
	//SHOW FIRST PANEL & SCROLL BAR
	hideContent();
	$('.aSelected').show();
	showContent();
	
	//PANEL HEADER ON CLICK EVENTS
	$('#tabMenu li').click(function(){
		
		//CHECK IF SELECTED
		var isSelected = false;
		if ($(this).hasClass('hSelected')){
			isSelected = true;
		}
		
		if(isSelected == false){
			var tabIndex = $('#tabMenu li').index(this);
				
			//HIDE CONTENT AND IMAGES DURING ANIMATION	
			$('.contentPanel').stop(true,true);	
			hideContent();
			//HIDE ALL SCROLLBARS
			if($('.scrollbar').hasClass('hasScroll')){
				$('.scrollbar').addClass('disable');
			}
			//CHANGE SELECTED NAV
			$('.hSelected').removeClass('hSelected');		
			$(this).addClass('hSelected');	
			
			//ANIMATE PANELS
			$('.aSelected').hide(0, function(){
				//CHANGE SELECTED PANEL
				$('.aSelected').removeClass('aSelected');
				$('.contentPanel:eq(' + tabIndex + ')').addClass('aSelected');
			
				$('.aSelected').slideDown(600, function(){
					showContent();
				});
			});
		}
	});
}

function splashProgressBar(){
	$('#splashFooter').animate(
		{left:0}, 
		60000, 
		'linear',
		function(){
			$('#splashPopup').fadeOut(600);
		}
	);
}

function hideContent(){
	$('.overview').hide();
	$('.overview img').slideUp();
	$('.nonoverview').hide();
	$('.nonoverview img').slideUp();
	$('.sectionDivider').slideUp();
	$('.sectionDividerSml').slideUp();
}

function showContent(){
	$('.overview').fadeIn(200);
	$('.overview img').slideDown();
	$('.nonoverview').fadeIn(200);
	$('.nonoverview img').slideDown();
	$('.sectionDivider').slideDown();
	$('.sectionDividerSml').slideDown();
	
	if($('.aSelected .scrollbar').hasClass('hasScroll')){
		$('.aSelected .scrollbar').removeClass('disable');
	}
}
