// ==========
// = Banner =
// ==========

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 setPanelUp(ppanelID) {

	if (ppanelID) {
	
		$('#stage-wrap').scrollTo('#' + ppanelID, 600);
		currentPanel = ppanelID;
		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 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);

}

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



$(document).ready(function() {
	
	$('.bigdrop').hoverIntent({
		interval: 150, 
		over: bigshow, 
		timeout: 300, 
		out: bighide
	});
	
	function bigshow() {
 		$('#' + $(this).attr('class').split(' ').slice(-1) ) .show("fast");		
 		$(this).children('a.page-item').addClass('hover');	
	}
	
	function bighide() {
		$(this).children('a.page-item').removeClass('hover');
		$('#' + $(this).attr('class').split(' ').slice(-1) ) .hide();		

	}

	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();
	
	//edit crew page
	
	 if ( document.location.href.toString().match('rebeka') || document.location.href.toString().match('sarah') || document.location.href.toString().match('zachary') || document.location.href.toString().match('katie') || document.location.href.toString().match('amanda')) {
	 	//window.alert('becky!');
	 
		setPanelUp('panel-six');	 
	 } 
	 
	 if ( document.location.href.toString().match('jasmine') || document.location.href.toString().match('kevin-york') ) {
	 	setPanelUp('panel-four')
	 }
	 
	 if ( document.location.href.toString().match('laura') || document.location.href.toString().match('amanda') || document.location.href.toString().match('cheri') || document.location.href.toString().match('john') ) {

 		setPanelUp('panel-nine');	 

	 }
	
	
	// Highlight Copy/Text
	
	$('.highlight-white').each(function(){
			
			$(this).wrapInner("<span class=\"highlight-white\"></span>");
			
	});	
	
	$('.post-content p').each(function(){
			
			$(this).wrapInner("<span class=\"highlight-white\"></span>");
			
	});
	

	
	// 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");});
		
	}
	

	

	var namemsg = 'your name';
	var emailmsg = 'your email';
	var messagemsg = 'your message';
	
	if ($('#name')) {
		$('#name').val(namemsg).css("color", "#8ebae0");
	}
	if ($('#email')) {
		$('#email').val(emailmsg).css("color", "#8ebae0");
	}
	if ($('#message')) {
		$('#message').val(messagemsg).css("color", "#8ebae0");
	}	
	
	$("#name").focus( function () {
		$("#name").val("").css("color", "#333");
	})	
	$("#email").focus( function () {
		$("#email").val("").css("color", "#333");
	})	
	$("#message").focus( function () {
		$("#message").val("").css("color", "#333");
	})
	
	 $('#footerform').submit(function() { 
        		return false; 
    	   });
            
            $('#footerform').ajaxForm({
                success: showResponse
            });
            
            function showResponse(responseText, statusText)  { 
     
    			$(".footerform").html(responseText).css({'color' : '#333'}); 
			}             



});

function gsetCookieShort(name2,value2) {
        gsetCookie(name2, value2, null, '/', gGetCookieDom());
}

function ggetCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


function gsetCookie(name, value, expiredays, path, domain, secure) {
  var ExpireDate = new Date ();
  path = '/';
  ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
  var curCookie = name + "=" + escape(value) +
      ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()) +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function gGetCookieDom(){
var thisdomain = document.domain;
var setdom = thisdomain.replace(/^(www|tools)\./, '');
return '.'+setdom;
}
