Cufon.replace('#mainnav', { fontFamily: 'MankSans-Medium' });

window.fbAsyncInit = function() {
	FB.init({
		channelUrl: 'http://www.aviawest.com/fb-channel'
	});
};

$(function() {
	var jPlayer = $('#jplayer').jPlayer({
		ready: function () {
			$(this).jPlayer('setMedia', {
				mp3: 'http://media.aviawest.com/video/when-you-smile.mp3'
			});
		},
		loop: true,
		preload: 'auto',
		supplied: 'mp3',
		swfPath: '/includes/flash/jplayer.swf',
		volume: 0.25,
		wmode: 'window'
	});
		
	$('#jplayer-button').click(function(e) {
		e.preventDefault();
		
		if ($(this).hasClass('play')) {
			$(this).removeClass('play').addClass('pause');
			jPlayer.jPlayer('play');
		}
		else {
			$(this).removeClass('pause').addClass('play');
			jPlayer.jPlayer('pause');
		}
	});
	
	$('a.colorbox').colorbox();
	$('a.colorbox.inline').colorbox({
		inline: true,
		innerWidth: 800
	});
	$('a.youtube, a.colorbox.iframe').colorbox({
		iframe: true,
		innerHeight: 480,
		innerWidth: 800
	});
	
	$.tools.tooltip.addEffect('customFade',
		function(done) {
			if ($.support.opacity) {
				this.getTip().stop(true, true).fadeIn('fast', done());
			}
			else {
				this.getTip().show();
				done();
			}
		},
		function(done) {
			if ($.support.opacity) {
				this.getTip().stop(true, true).fadeOut('fast', done());
			}
			else {
				this.getTip().hide();
				done();
			}
		}
	);
	$('a.tooltip').click(function(e) {
		e.preventDefault();
	}).tooltip({
		delay: 0,
		effect: 'customFade',
		offset: [-30, 0],
		predelay: 30,
		relative: true,
		onBeforeShow: function() {
			var $tooltip = this.getTip();
			if (!$tooltip.find('div.arrow').length) {
				$tooltip.prepend('<div class="arrow"></div>');
			}
		}
	});
	
	$('#footer-expand-button').click(function(e) {
		e.preventDefault();
		
		var $current = $(this);
		
		if ($('#expandable-footer').is(':hidden')) {
			$current.addClass('selected');
			$('#expandable-footer').slideDown();
		}
		else {
			$current.removeClass('selected');
			$('#expandable-footer').slideUp();
		}
	});
	
	$('a.toggle').click(function(e) {
		e.preventDefault();
		
		var $div = $(this).parent().next('div');
		
		if ($div.length) {
			if ($div.is(':visible')) {
				$div.slideUp();
			}
			else {
				$div.slideDown();
			}
		}
	});
	
	$('#tweets-main').tweet({
		count: 2,
		loading_text: 'Loading tweets...',
		template: '{text} {time}',
		username: 'aviawestresorts'
	});
	
	$('#tweets-property').tweet({
		count: 2,
		loading_text: 'Loading tweets...',
		template: '{text} {time}',
		username: $('#property-twitter-username').val()
	});
	
	if ($('div.tabs').length) {
		$('div.tabs ul.nav li').click(function(e) {
			e.preventDefault();
		});
		
		$.address.init(function(e) {
			if (e.value == '/') {
				var firstTabLink = $('div.tabs ul.nav').find('a:eq(0)');
				e.value = firstTabLink.attr('rel').replace(/^address:/, '');
				$.address.value(e.value);
			}
		}).change(function(e) {
			var currentTabSelector = '#' + e.value.replace(/^\//, '');
			var $currentTabPane = $(currentTabSelector);
			
			$('div.tabs ul.nav li.selected').removeClass('selected');
			$('div.tabs ul.nav li a[href=' + currentTabSelector + ']').parent().addClass('selected');
			
			var $visibleSibling = $currentTabPane.siblings(':visible');
			if ($visibleSibling.length) {
				$visibleSibling.stop(true, true).fadeOut('fast', function() {
					$currentTabPane.stop(true, true).fadeIn('normal');
				});
			}
			else {
				$currentTabPane.stop(true, true).fadeIn('normal');
			}
		});
	} // if tabs
	
	$('#office-list, #property-list').change(function(e) {
		var currValue = $('option:selected', this).val();
		if (currValue) {
			$('#' + currValue).siblings().hide().end().show();
		}
	});
	
	$('#team-listing area').click(function(e) {
		e.preventDefault();
		
		var currLink = $(this).attr('href');
		$(currLink).siblings().hide().end().show();
	});
});
