
$(document).ready(function(){
	
	spauld.init();
	$('.executable[rel]').each(function(){
		var $this = $(this);
		var rel = $this.attr('rel');
		try {
			spauld[rel].init($this);
		}
		catch(err){}
		
	});	
	
});
$(document).load(function(){
	
})

var spauld = {
	init: function(){
		$('body').addClass(this.browserClass);
		this.searchFocus();
		
	},
	browserClass: function(){
		var $browser = $.browser;		
		if($browser.mozilla){
			if($browser.version < 1.8){
				return "ff1";
			}
			else if($browser.version > 1.8 ){
				return "ff2";
			}
			else {
				return "ff3";				
			}			
		}
		else if($browser.webkit){
			return 'webkit';
		}
		else if($browser.opera){
			return 'opera';
		}		
	},
	
	searchFocus: function(){
		
		var $texts = $('input[type=text][title], textarea[title]');
    
	    $texts.each(function(){
	        var $this = $(this);
	        if($this.val() == "" || $this.val() == $this.attr('title')){
	            $this.val($this.attr('title')).addClass('default');
	        }       
	    });
	    
	    $texts.focus(function(){
	         var $this = $(this);
	          $this.val(($this.val()===$this.attr('title'))?'':$this.val()).removeClass('default');
	        }).blur(function(){
	            var $this = $(this);
	            $this.val(($this.val()==='')?$this.attr('title'):$this.val()).addClass(($this.val()===$this.attr('title'))?'default':'');
	        });	     
			
			
		}
}


/* 
 * 
 * Show and hide content spaulding for you page
 * 
 */

spauld.spauldfu = {
	init: function(el){
		$("ul.expand_sfy").hide(); 
		
		$("div.expandable").click(function(){
			$(this).next().slideToggle("fast");
			return false;
		});
	
	}
	
}

/* 
 * 
 * Show and hide locations
 * 
 */

spauld.locationFinder = {
	init: function(el){
		$("div.location_finder_content").hide(); 
		
		$("div.location_finder_inner").click(function(){
			$(this).toggleClass('expand').parent().find('div.location_finder_content').slideToggle("normal");
			return false;
		});
	
	}
	
}

/* 
 * 
 * Show and hide More content on centers and facilities Page
 * 
 */

spauld.searchFilterMore = {
	init: function(el){
		var $el = $(el);
		$el.find('ul.moreSearch').hide();
		
		$('.viewMore a').toggle(
		
		function(){
			$(this)
			.parent()
			.siblings('.moreSearch')
			.slideDown()
			.end().end()
			.text('Less')
			.attr('class','hide');
			
			},
		function(){
			$(this)
			.parent()
			.siblings('.moreSearch')
			.slideUp()
			.end().end()
			.text('More')
			.attr('class','show');
		}
	
			
		);	
	}
	
}


spauld.accordBox = {
	init: function(el){
		var $el = $(el);
		var $accord = $el.find('.accordion');
		$accord.accordion({autoHeight:false, collapsible:false, header:'.tab', effect: 'slide', initialIndex:0});
		if ($('body').hasClass('ie7')) {
			$accord.bind('accordionchangestart', function(event, ui){
				ui.oldContent.find('button').hide();
			});
			$accord.bind('accordionchange', function(event, ui){
				ui.newContent.find('button').show();
			})
		}
	}
	
}

spauld.tabBox = {
	init: function(el){
		
		var $el = $(el);
		var $tabItems = $el.find('ul.tabItems')
		var $tabContent = $el.find('.tabContent .content');
		
		var preCurrent = $tabItems.find('.current');
		
		if(preCurrent.size() > 0){
			preCurrent = preCurrent.prevAll().size();			
		}
		else{
			preCurrent = 0;
		}
		
		$tabItems.tabs($tabContent, {
			initialIndex: preCurrent	
		});
	}
	
}

// open and close all
spauld.expandBox = {
	init: function(){
    $("#open_close h3.expand").toggler({initShow: "div.collapse:eq(0)"});
    
    $("#open_close").expandAll({
      trigger: "h3.expand", 
      ref: "h3.expand", 
      showMethod: "slideDown", 
      hideMethod: "slideUp", 
      oneSwitch : false
    });
	}
}	

// font resize all
spauld.resize = {
	init: function(){
	
		// Now, let's resize that font
		$('a.resize').click(function(){
			var ourText = $('#wrapper .main_body_content .container');
			var currFontSize = ourText.css('fontSize');
			var currLineHeight = ourText.css('lineHeight');
			var finalNum = parseFloat(currFontSize, 12);
			var finalHeight = parseFloat(currLineHeight, 18);
			var stringSize = currFontSize.slice(-2);
			var stringHeight = currLineHeight.slice(-2);
			if (this.id == 'large') {
				finalNum = 16;
				finalHeight = 30;
			// in case we want to dynamically scale
			// finalNum *=1.2;
			// finalHeight *=1.2;
			//if(finalNum >= 20.74){finalNum = 20.74;}
			//if(finalHeight >31.1){finalHeight = 31.1;}
			}
			if (this.id == 'xlarge') {
				finalNum = 20;
				finalHeight = 30;
			}
			else 
				if (this.id == 'normal') {
					finalNum = 12;
					finalHeight = 18;
				}
			ourText.css('fontSize', finalNum + stringSize);
			ourText.css('lineHeight', finalHeight + stringHeight);
			
			// Prevent default click action.
			return false;
		});
	}
};

// dropdown menu
spauld.dropdownmenu = {
	init: function(el){
		
		$('div.sp_menu').hide();
		$('div.sp_submenu').hide();
		this.hoverState();
		if ($('body').hasClass('ie6')) {
			$('.sp_menu').bgiframe();
		}
		$('ul li.expandable a.active').hover(function(e){
		e.preventDefault();
		
			$(this).addClass('current')
			.parent()
			.addClass('current');
			$(this).parent().find('div.sp_menu').show();
			$('div.sp_submenu').hide();
				
			$(this).parent().hover(function(){},function(){
				$(this).parent().find("div.sp_menu").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				$(this).removeClass('current').end()
			});
		
		})
		},
		
		hoverState: function(){
			$('div.sp_submenu').hide();
			$('ul li a.activeRegion').hover(function(e){
				e.preventDefault();
				$(this).addClass('subhover') //On hover over, add class "subhover"
				$(this).parent().addClass("subhover");
				$(this).parent().find('div.sp_submenu').slideDown();
				$(this).parent().hover(function(){
				}, function(){ //On Hover Out
					$(this).parent().find("div.sp_submenu").hide(); //On hover out, remove class "subhover"
					$(this).parent().removeClass("subhover").end();
					$(this).removeClass("subhover").end();
				});
				
			})
		}
};

// see all
spauld.seeAll = {
	init: function(el){
		var $el = $(el);
		$el.find('ul.see_all').hide();
		
		$('.see_more a').toggle(
		
		function(){
			$(this)
			.parent()
			.siblings('.see_all')
			.slideDown()
			.end().end()
			.text('See Less')
			.attr('class','learn_more hide');
			
			},
		function(){
			$(this)
			.parent()
			.siblings('.see_all')
			.slideUp()
			.end().end()
			.text('See All')
			.attr('class','learn_more show');
		}
	
			
		);	
	}
	
};

