// JavaScript Document

var mainContainer = "#actualContainer";
var navigation = "#navigationRow";

/* START AJAX HISTORY FIX*/
	
	// PageLoad function
	// This function is called when:
	// 1. after calling $.historyInit();
	// 2. after calling $.historyLoad();
	// 3. after pushing "Go Back" button of a browser
	function pageload(hash) {
		// hash doesn't contain the first # character.
		if(hash) {
			// restore ajax loaded state
			setPage(hash + ".php", null, hash);
			//$(mainContainer).load(hash + ".php");
		} else {
			// start page
			setPage("home.php", null, "home");
			//$(mainContainer).empty();
		}
	}
	
/* END AJAX HISTORY FIX */

function showContent(content){
	$(mainContainer).html(content);	
	$(mainContainer).slideDown("slow");
	$('.rounded').corner();
	$('#tabContainer').tabs();
	
	//show positions if in positions page
	if(document.getElementById('positionsContainer')){
		getPositions();
	}
}

function setPage(url, params, name){
	$(mainContainer).slideUp("slow", function(){
   		$.get(url, params, function(data){
							setTopNav(name);
							showContent(data);
						});
					});
}

function getPositions(){
	$.get('/manage/positions/positionList', null, function(data){
							$('#positionsContainer').html(data);
						});	
}

function setTopNav(name){
	if(name=='home'){
		$('#headerFrames').show();	
		$('#headerSmallFrames').hide();	
	}
	else{
		$('#headerSmallFrames').show();	
		$('#headerFrames').hide();			
	}
	//set the selected class and 
	$(navigation).children(".selected").each(function(i){
													  $(this).removeClass("selected").removeClass('nav'+$(this).attr("number"));
													  });
	$(navigation).children("#"+name).addClass('selected').addClass('nav'+$(navigation).children("#"+name).attr("number"));
	makeNav();
}

function makeNav(){
	//reset bound events for all so the new selected does not have click and mouse events
	$(navigation).children().unbind();
	//set mouse over and out classes
	$(navigation).children().not('.selected').mouseover( function() { $(this).addClass('over') } );
	$(navigation).children().mouseout( function() { $(this).removeClass('over') } );
	//make navigation links
	$(navigation).children().not('.selected').click( function() { 
															  //$.historyLoad($(this).attr("id")); 
															  var tempId = $(this).attr("id");
															  if(tempId=='home')tempId='index';
															  top.location.href = tempId+'.php';
															  });
}