/*---------------------------------
 * Initiate Jquery Functions
 *---------------------------------
 */

$(document).ready(function(){
	
	//NEW TAB POPUP
	$("a.popup_tab").attr("target", "_blank");
	
	//AUTOPOPULATE
	$(".populate").each( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	$(".populate").focus(function(){
		if ( $(this).val() == $(this).attr("title") ) {
			$(this).val("");
		}
	});
	$(".populate").blur(function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	
	//ADD LAST CLASS
	$('#navigation ul li:last-child').addClass('last');
		
	//FONT-SIZE SELECTOR
	//Small
	$("#text_size_picker .small").click( function () {
		$(this).siblings().removeClass("current");
		$(this).addClass("current");
		$("body").removeClass("text_size_medium");
		$("body").removeClass("text_size_large");
		$("body").addClass("text_size_small");
		$.cookie('textSize', 'small', {path: "/"});
		return(false);
	});
	//Medium
	$("#text_size_picker .medium").click( function () {
		$(this).siblings().removeClass("current");
		$(this).addClass("current");
		$("body").removeClass("text_size_small");
		$("body").removeClass("text_size_large");
		$("body").addClass("text_size_medium");
		$.cookie('textSize', 'medium', {path: "/"});
		return(false);
	});
	//Large
	$("#text_size_picker .large").click( function () {
		$(this).siblings().removeClass("current");
		$(this).addClass("current");
		$("body").removeClass("text_size_small");
		$("body").removeClass("text_size_medium");
		$("body").addClass("text_size_large");
		$.cookie('textSize', 'large', {path: "/"});
		return(false);
	});
	
	//COOKIES
	// Set Default State
	if ($.cookie('textSize') == null ) {
		$("#text_size_picker a.small").addClass("current");
		$.cookie('textSize', 'small', {path: "/"});
	}; 

	//Text Size
	var textSize = $.cookie('textSize');
	if (textSize == 'small') {
		$("#text_size_picker").siblings().removeClass("current");
		$("#text_size_picker a.small").addClass("current");
		$("body").removeClass("text_size_medium");
		$("body").removeClass("text_size_large");
		$("body").addClass("text_size_small");
	}
	if (textSize == 'medium') {
		$("#text_size_picker").siblings().removeClass("current");
		$("#text_size_picker a.medium").addClass("current");
		$("body").removeClass("text_size_small");
		$("body").removeClass("text_size_large");
		$("body").addClass("text_size_medium");
	}
	if (textSize == 'large') {
		$("#text_size_picker").siblings().removeClass("current");
		$("#text_size_picker a.large").addClass("current");
		$("body").removeClass("text_size_small");
		$("body").removeClass("text_size_medium");
		$("body").addClass("text_size_large");
	}
	
	//EMAIL ENCRYPT
	$(".cloak").each(function(){
		var ats, dots, address, i;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});
	
	//TABS
	$("#home_slider").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 5500);
	
	//FANCYBOX POPUPS
	$("a.fancybox").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300}); 
	$("a.modalbox").fancybox({ 'frameWidth': 400, 'width': 400 });
	$("a.fancybox_include").fancybox({ 'frameWidth': 400, 'width': 400 });
	
	//ZEBRA STRIPE
	//$("#tag:odd").addClass("alt");

});

// INITIALIZE SUPERFISH DROPDOWN
jQuery(function(){
	jQuery('#navigation ul.main').superfish();
});