/***********************************************
***  BUTTON ROLLOVER & PRELOAD  ****************
************************************************/

$(function(){
	// button rollover
	if ($('.imgBtn') != null) {
		$('.imgBtn').hover(function(){
				if(!$(this).is('.disabled'))
					$(this).attr("src", $(this).attr("src").replace(/^(.*?)(?:-hover)?(\..*?)$/i,'$1-hover$2'));
			},
			function(){
					if(!$(this).is('.disabled'))
						$(this).attr("src", $(this).attr("src").replace(/^(.*)-hover(\..*?)$/i, '$1$2'));
				});
	}
	// preload image rollovers
	if ($("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']") != null) {
	    $("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']").each(function(){
			    $("<img>").attr("src", $(this).attr("src").replace(/(btn-.*)(\..*?)/i, '$1-hover$2'));
		    });
	}
});


/***********************************************
***  EXTERNAL LINKS  ***************************
************************************************/

$(document).ready(function() {
	$("a[rel=external]").each(function() {
		$(this).addClass('external');
		$(this).attr({
			title: "Open this page in a new window",
			target: "_blank"
		});
	})
});

/***********************************************
***  EXTERNAL FROM  ****************************
************************************************/

$(document).ready(function() {
	$(".homeForm form, .sidebarAd").each(function() {
		$(this).attr({
			target: "_blank"
		});
	})
});


/***********************************************
***  COMPACT FORM (LABEL OVER INPUT)  **********
************************************************/

$(function(){
	$('form.compact input, form.compact select, form.compact textarea').focus(function(){
			$('label[for=' + $(this).attr('id') + ']').hide();
		});
	$('form.compact input, form.compact select, form.compact textarea').each(function(ele){
			if($(this).val().length > 0)
				$('label[for=' + $(this).attr('id') + ']').css({ display: "none" });
		});
	$('form.compact input, form.compact select, form.compact textarea').blur(function(){
			if($(this).val().length == 0)
				$('label[for=' + $(this).attr('id') + ']').show();
		});
	$('form.compact').removeClass('compact');
});

/***********************************************
***  TABS **************************************
************************************************/
/**
 * jQuery.geeTabs - Adds tab functionality to a page
 * Date: 2010/01/08
 *
 * @author Brian Xerri
 * @version 1.1.0
 * @jQuery Version: jquery-1.3.2.js
 *
 ***************************
 * - Added GoToTab function so can change tab from external source
 *
 * Copyright: GeeMultimedia
 **/
$(function(){
	    $.fn.geeTabs = function(options) {
		    var settings = $.extend({}, $.fn.geeTabs.defaults, options);
			
		    var menuTabs = this.each(function(index) {

			    $(this).click(function() {
				    $.fn.geeTabs.goToTab(index);
			    });

		    });

			$.fn.geeTabs.goToTab = function(tabIndex) {

				var o = $.meta ? $.extend({}, settings, $this.data()) : settings;

				menuTabs.filter('li.selected').removeClass('selected');
				menuTabs.eq(tabIndex).addClass('selected');

				$(o.tabbedContentSelector + '.current').removeClass('current');
				$(o.tabbedContentSelector + ':eq(' + tabIndex + ')').addClass('current');

				return false;
			};
	    }

	    $.fn.geeTabs.defaults = {
		    tabbedContentSelector: '.tabContent .tab'
	    };		
});