var monroeNaz = {

	initCalendarLink : function() {
		jQuery('.events').append('<br /><a href="/connect/calendar" class="more">View Calendar</a>');
	},
	
	initSearchColor : function(){
		//Sets initial search value, and clear that value on focus
		if(jQuery('#searchform input#s').val() == ""){
			jQuery("#searchform input#s").addClass('light').val("Search");
		}
		
		jQuery("#searchform input#s").focus(function () {
			 if(jQuery(this).val() == "Search"){
				jQuery(this).val("").removeClass('light');
			}
		});
		jQuery("#searchform input#s").blur(function () {
			 if(jQuery(this).val() == ""){
				jQuery(this).addClass('light').val("Search");
			}
		});
	},
	
	//Makes it so bottom two elements don't have underline
	initMenuUnderlineFix : function() {
		
		//Removed unerline from second to last element if the set is an even number
		jQuery('#menu-main-nav li ul').each(function(){
			var total = jQuery(this).children().size();
			var evenCheck = total % 2;
			
			if(evenCheck == 0){
				jQuery(this).children('li').eq(total-2).css('border-bottom','none');
			}
		});
	
		jQuery('.menu li li:last-child').css('border-bottom', 'none');
		
		var total = jQuery('#menu-main-nav:last ul a').html();
		
		if(total == "Sign Up Now."){
			jQuery('#menu-main-nav ul:last').css('width', '157px');
			jQuery('#menu-main-nav ul:last').children('li').eq(2).css('border-bottom','1px dotted #7D4A2C');
		}
		
	},
	
	//User Login Show/Hide Script
	initUserLogin : function() {
		jQuery('#user-bar form').hide();
		
		jQuery('#user-bar h2').hover(function(){
			jQuery(this).addClass('hover');							 
		},
		function(){
			jQuery(this).removeClass('hover');
		});
		
		jQuery('#user-bar h2').click(function(){
			jQuery('#user-bar form').slideToggle("slow");
		});	
		
	},
	
	//FAQ Collaper
	initFaqHover : function() {
		jQuery(".faq .answer").hide();
		
		jQuery(".faq p.question").click(function(){
			jQuery(this).next().toggle(400);	
			return false;
		});
	},
	
	//Font Sizer
	initFontSize : function(container, target, minSize, defSize, maxSize) {
		/*Editable settings*/
		var minCaption = "Decrease Text Size"; //title for smallFont button
		var defCaption = "Default Text Size"; //title for defaultFont button
		var maxCaption = "Increase Text Size"; //title for largefont button
	 
	 
		//Now we'll add the font size changer interface in container
		smallFontHtml = "<a href='javascript:void(0);' class='smallFont' title='" + minCaption +"'>" + minCaption + "</a> ";
		defFontHtml = "<a href='javascript:void(0);' class='defaultFont' title='" + defCaption +"'>" + defCaption + "</a> ";
		largeFontHtml = "<a href='javascript:void(0);' class='largeFont' title='" + maxCaption +"'>" + maxCaption + "</a> ";
		jQuery(container).html(smallFontHtml + defFontHtml + largeFontHtml);
	 
		//Read cookie &amp; sets the fontsize
		if (jQuery.cookie != undefined) {
			var cookie = target.replace(/[#. ]/g,'');
			var value = $.cookie(cookie);
			if (value !=null) {
				jQuery(target).css('font-size', parseInt(value));
			}
		}
	 
		//on clicking small font button, font size is decreased by 1px
		jQuery(container + " .smallFont").click(function(){ 
			curSize = parseInt(jQuery(target).css("font-size"));
			newSize = curSize - 1;
			if (newSize >= minSize) {
				jQuery(target).css('font-size', newSize);
			} 
			if (newSize <= minSize) {
				jQuery(container + " .smallFont").addClass("sdisabled");
			}
			if (newSize < maxSize) {
				jQuery(container + " .largeFont").removeClass("ldisabled");
			}
			updatefontCookie(target, newSize); //sets the cookie 
	 
		});
	 
		//on clicking default font size button, font size is reset
		jQuery(container + " .defaultFont").click(function(){
			jQuery(target).css('font-size', defSize);
			jQuery(container + " .smallFont").removeClass("sdisabled");
			jQuery(container + " .largeFont").removeClass("ldisabled");
			updatefontCookie(target, defSize);
		});
	 
		//on clicking large font size button, font size is incremented by 1 to the maximum limit
		jQuery(container + " .largeFont").click(function(){
			curSize = parseInt(jQuery(target).css("font-size"));
			newSize = curSize + 1;
			if (newSize <= maxSize) {
				jQuery(target).css('font-size', newSize);
			} 
			if (newSize > minSize) {
				jQuery(container + " .smallFont").removeClass("sdisabled");
			}
			if (newSize >= maxSize) {
				jQuery(container + " .largeFont").addClass("ldisabled");
			}
			updatefontCookie(target, newSize);
		});
	 
		function updatefontCookie(target, size) { //Private function for setting cookie
			if ($.cookie != undefined) { //If cookie plugin available, set a cookie
				var cookie = target.replace(/[#. ]/g,'');
				$.cookie(cookie, size);
			} 
		}
	},
	
	initTabs : function() {
		jQuery('.tab1').addClass('current');
		jQuery('.tab2, .tab3, .tab4').hide();
		
		jQuery('ul.tab li').each(function(intIndex){
			 if (jQuery(this).is(":first-child")) { jQuery(this).addClass("current") };
									 
			$currentText = jQuery(this).html();				 
			jQuery(this).html('<a href="#">' + $currentText + '</a>');
			jQuery(this).addClass('tab' + (intIndex+1));
			
		});
		
		jQuery('ul.tab li a').click(function() {
			jQuery(this).parent().parent().children('.current').removeClass('current');
			var curChildIndex = jQuery(this).parent().prevAll().length + 1;
			
			jQuery(this).parent().addClass('current');
			
			jQuery(this).parent().parent().nextAll('div:visible').slideUp('fast',function() {
				jQuery(this).removeClass('current');
				
				jQuery(this).siblings('div[class=tab'+curChildIndex+']').slideDown('normal',function() {
					jQuery(this).addClass('current');
				});
			});
			return false;
		});
	}
}

jQuery(document).ready(function(){	
	
	monroeNaz.initSearchColor();
	
	monroeNaz.initFontSize('#sizer', '.entry-content', 12,14,18);
	monroeNaz.initUserLogin();
	monroeNaz.initFaqHover();
	
	monroeNaz.initTabs();
	monroeNaz.initMenuUnderlineFix();
	
	monroeNaz.initCalendarLink();
});
