
var firstPanel = "";
var lastPanel = "";

var currentPanel = "";

var previousPanel = "";
var nextPanel = "";

function setNavLinks () {

	previousPanel = $("#" + currentPanel).prev("li.panel").attr("id");
	nextPanel = $("#" + currentPanel).next("li.panel").attr("id");

	if (!previousPanel) {

		$("#previous-panel").addClass("disabled");

	} else {

		$("#previous-panel").removeClass("disabled");

	}

	if (!nextPanel) {

		$("#next-panel").addClass("disabled");

	} else {

		$("#next-panel").removeClass("disabled");

	}

}

function goto_previousPanel() {

	if (previousPanel) {

		$('#stage-wrap').scrollTo($('#' + previousPanel), 600 );
		currentPanel = previousPanel;
		setNavLinks();
	}

}

function goto_nextPanel(lastPanelId) {
	
	if (lastPanelId) {
		
		if (nextPanel != lastPanelId) {

			$('#stage-wrap').scrollTo($('#' + nextPanel), 600 );
			currentPanel = nextPanel;
			setNavLinks();
			
		} else {
			
			$('#stage-wrap').scrollTo($('#' + firstPanel), 600 );
			currentPanel = firstPanel;
			setNavLinks();
			
		}
		
	} else {
		
		if (nextPanel) {

			$('#stage-wrap').scrollTo($('#' + nextPanel), 600 );
			currentPanel = nextPanel;
			setNavLinks();
		}
		
	}

}


// ======================================================================================================


function makeExcerptLinks (parent_element, mouseover_styleClass) {
	
	var $kids = $(parent_element).children();
	
	jQuery.each($kids, function() {
		
		var theUrl = $(this).find("a:first").attr("href");
		
		$(this).bind("mouseover", function(e) { $(this).addClass(mouseover_styleClass) });
		$(this).bind("mouseout", function(e) { $(this).removeClass(mouseover_styleClass) });
		$(this).bind("click", function(e) { window.location.href = theUrl });
		
	});
	
}


// ======================================================================================================


function resetMenu () {

	$(".nav-link").removeClass('hover');
	$("div.nav-menu").hide();

}

function toggleMenu (theMenuId,theTarget) {
	
	var is_visible = ($("#" + theMenuId + ":visible").length > 0);
	
	if (!is_visible) {
		
		resetMenu();

		if (theMenuId) {
			
			// $("div#" + theMenuId).show();
			$("div#" + theMenuId).toggle("blind");
			
		}
		
		if (theTarget) { $(theTarget).closest("li").addClass('hover'); $(theTarget).addClass('hover'); }
		
	}

}


// ======================================================================================================


function embedFlash (theFileSrc, theContainerId, theWidth, theHeight, flashvars, params, attributes) {

	var flashvars = (flashvars) ? flashvars : false;
	var params = (params) ? params : false;
	var attributes = (attributes) ? attributes : false;

	swfobject.embedSWF(theFileSrc, theContainerId, theWidth, theHeight, "8.0.0","/includes/swfs/expressInstall.swf", flashvars, params, attributes);

}

// ======================================================================================================


jQuery(document).ready(function($) {

	// firstPanel = $("#stage").find("li:first").attr("id");
	// lastPanel = $("#stage").find("li:last").attr("id");
	// 
	// currentPanel = firstPanel;
	// 
	// previousPanel = $("#" + currentPanel).prev("li.panel").attr("id");
	// nextPanel = $("#" + currentPanel).next("li.panel").attr("id");
	// 
	// setNavLinks();
	// resetMenu();
	// 
	// var about_offset = $("#nav-link-about").position();
	// var about_offset_left = about_offset.left + 1;
	// $("#menu_about").css("left",about_offset_left);
	// 
	// var portfolio_offset = $("#nav-link-portfolio").position();
	// var portfolio_offset_left = portfolio_offset.left + 1;
	// $("#menu_portfolio").css("left",portfolio_offset_left);
	
	
	// Add on class to current page links and parents
	
	if (page_id && (page_id != "")) {
		
		$('.page-item-' + page_id).each(function(){ $(this).addClass("on");});
		
	}
	
	if (parent_id && (parent_id != "")) {
		
		$('.page-item-' + parent_id).each(function(){ $(this).addClass("on");});
		
	}
	
	if (grandparent_id && (grandparent_id != "")) {
		
		$('.page-item-' + grandparent_id).each(function(){ $(this).addClass("on");});
		
	}
	
	// $("#text").mouseenter(function() { resetMenu(); });
	
});

