/* Dropdown menu */
$(document).ready(function(){
	$("div.flight-info").hide();
	$("#nav li.flights a.toggle").click(showFlight);
	
	function showFlight(who) {
		if ($("div.flight-info").css('display') == 'none') {
			$("div.flight-info").show();
		} else {
			$("div.flight-info").hide();
		}
		return false;
	}
});


$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};

/* Sliding windows */
var currentItem = null;
var undoTimerHodler = false;
$(document).ready(function() {
	// Init Animations
	$('#slider div.block .bg').css({opacity: ".5", filter: "alpha(opacity=50)"});
	$('#slider div.block .text-bg').css({opacity: "0"});
	$('#slider div.block .text').css({opacity: "0"});
	// Set Events
	$('#slider div.block').bind('click', doItem);
	$('#slider div.block').hover(hoverItem, unhoverItem);
	// Init Vars
	currentItem = null;
});
function hoverItem() {
	$(this).children(".bg").animate({opacity: 1}, 200,'linear');
}
function unhoverItem() {
	if (currentItem != this) {
		$(this).children(".bg").animate({opacity: .5}, 200,'linear');
	}
}
function doItem() {				
	if (currentItem == this) {
		$(this).children(".bg").animate({opacity: .5}, 200,'linear');
		$('#slider div.block').animate({width: 240}, 200,'linear');
		$(this).children(".bg").children(".text-bg").animate({opacity: 0}, 200,'linear');
		$(this).children(".bg").children(".text").animate({opacity: 0}, 200,'linear');
		currentItem = null;
	} else {
		$(this).children(".bg").animate({opacity: 1}, 200,'linear');
		$(this).animate({width: 402}, 200,'linear');
		$(this).children(".bg").children(".text-bg").animate({opacity: .75}, 200,'linear');
		$(this).children(".bg").children(".text").animate({opacity: 1}, 200,'linear');
		$('#slider div.block').not(this).animate({width: 186}, 200,'linear');
		$('#slider div.block').not(this).children(".bg").animate({opacity: 0.5}, 200,'linear');
		$('#slider div.block').not(this).children(".bg").children(".text-bg").animate({opacity: 0}, 200,'linear');
		$('#slider div.block').not(this).children(".bg").children(".text").animate({opacity: 0}, 200,'linear');
		currentItem = this;
	}
}

/* Prepare Links - using jQuery
 * Checks the document, when ready, for all link nodes with a class name "external" and opens them in a new window when clicked.
 */
$(document).ready(function(){
	$("a").filter(".external").click(function (){
		var NewWindow = new OpenWindow($(this).attr("href"));
		return NewWindow.open();
	})
    .end();
});

/* OpenWindow Class
 * Creates an OpenWindow object that allows you to define the URL, window name, and features for firing a pop-up window. @param {String} href
 */
function OpenWindow(href)
{
	// Set default values
	var _href     = href;
	var _name     = "external";
	var _features = "";
	
	function __construct() {
		// Define methods		
		this.getHref     = function() { return _href; }
		this.setHref     = function(href) { _href = href; }
		this.getName     = function() { return _name; }
		this.setName     = function(name) { _href = name; }
		this.getFeatures = function() { return _features; }
		this.setFeatures = function(features) { _features = features; }
		
		this.open = function() {
			window.open(_href, _name, _features);
			return false;
		}
	};
	
	return new __construct();
}

/* Son of Suckerfish Drop Down Menu - http://www.htmldog.com/ */
$(document).ready(function(){
	var sfEls = $("ul#nav li");
	for (var i = 0; i < sfEls.length; i++) {
		$(sfEls[i]).hover(function(){
			$(this).addClass("sfhover");
		},
		function(){
			$(this).removeClass("sfhover");
		});
	}
});

$(document).ready(function(){
	var sfEls = $("ul#search-nav li");
	for (var i = 0; i < sfEls.length; i++) {
		$(sfEls[i]).hover(function(){
			$(this).addClass("sfhover");
		},
		function(){
			$(this).removeClass("sfhover");
		});
	}
});