function exists(selector) {
    return $(selector).length > 0;
}

var current_hash = ''
var $tabs;

function pageload(hash) {
	if(hash != current_hash) {
		$tabs.tabs('select','#'+hash);
	}
}

function setupLightbox(){
	$('a.lb').lightBox({fixedNavigation:true});
}

function setupTabs(){
	
	
	if (!exists("ul#trip-tabs")) return;
	
	$("div#trip-tabs-container a").each(function(i){
		if (this.href.indexOf("#") == -1) {
			this.href += "?ajax";
		}
	});
	
	$tabs = $("div#trip-tabs-container").tabs({ show: function(event, ui) { setupLightbox(); } });
	//alert($tabs);
}

function setupMainMenu(){
	$("#extra-menu li").hover(
		function(){ $(this).addClass("hover"); },
		function(){ $(this).removeClass("hover");}
	);
	if (!($.browser.msie && $.browser.version < 7)){
		$(".trip-type").hover(
	    function() {
	        if (!$(this).hasClass("selected")) {
	            $("#trip-menu li.selected ul").hide();
	        }
	    },
	    function() {
	        $("#trip-menu li.selected ul").show();
	    }
	    );
	}
}

function setupCaptions(){
	$('img.captify').captify({
			// all of these options are... optional
			// ---
			// speed of the mouseover effect
			speedOver: 'fast',
			// speed of the mouseout effect
			speedOut: 'normal',
			// how long to delay the hiding of the caption after mouseout (ms)
			hideDelay: 500,	
			// 'fade', 'slide', 'always-on'
			animation: 'slide',		
			// text/html to be placed at the beginning of every caption
			prefix: '',		
			// opacity of the caption on mouse over
			opacity: '0.7',					
			// the name of the CSS class to apply to the caption box
			className: 'caption-bottom',	
			// position of the caption (top or bottom)
			position: 'bottom',
			// caption span % of the image
			spanWidth: '100%'
		});
}

function fixGChatLink() {
	if (! exists("a.googlechat")) return;
	
    $("a.googlechat").click(function() {
        var h = $(this).attr("href");
        window.open(h, 'Google Chat', 'width=300,height=500');
        return false;
    });
}

$(function() {
	setupMainMenu();
	setupTabs();
	setupLightbox();
	fixGChatLink();
	//setupCaptions();
});