$(document).ready(function(){
	
	Site.init();
	
	// Init the map if the maps tab is visible
	if($('.location-details').length != 0) {
		initMap();
	}
	
	// Init the map if we click on the tab to display it

	
});

var Site = {
	
	init:function() {
		
		//HANDLE EXTERNAL LINKS
		Site.externalLinks();
			
		//TEXT RESIZE & PRINT
		if($('#text-resize').length != 0) {
			Site.textResize();
			Site.print();
			Site.contrast();
		}
		
		//TABS
		if($('#tabs').length != 0) {
			$('#tabs').tabs();
			Site.tabScroll();
			
			$('.ui-tabs-nav li a').click(function() {
				initMap();   
    		});
			
		}
		
		//SEARCH
		if($('#search').length != 0) {
			Site.search();
		}
		
		//HOME FEATURE
		if($('#feature-carousel').length != 0) {
			Site.homeFeature();
		}

	
	},
	
	
	//CONTRAST ---------------------
	
	homeFeature:function() {
	
		$("#feature-carousel").carouFredSel({
			auto: 5000,
			height: 300,
			items: {
				visible: 1,
				height: 300,
				width: 960
			},
			next: "#feature-carousel-next",
			prev: "#feature-carousel-prev",
			scroll: {
				fx: "crossfade",
				easing: "linear",
				pauseOnHover: true
			},
			width: 960
		});
	},		
	
	//TEXT RESIZE ---------------------------
	textResize:function() {
	
		if($.cookie('TEXT_SIZE')) {
			$('#primary-inner').addClass($.cookie('TEXT_SIZE'));	
		}
		
		$('#text-resize').click(function() {
			
			if ($('#primary-inner').hasClass('large')) {
				$('#primary-inner').removeClass('large');
				$.cookie('TEXT_SIZE', null, { path: '/', expires: 10000 });
			} else {
				$('#primary-inner').addClass('large')
				$.cookie('TEXT_SIZE', 'large', { path: '/', expires: 10000 });
			}
			return false;
		});
	},
	
	//PRINT ---------------------------
	print:function() {
		
		$('#print').click(function(){
			window.print();
		});
		
	},
	
	//SEARCH -------------------------
	search:function() {
	
		$('#search input').focus(function() {
			$(this).css({'background-position':'-280px -28px'});			
			$(this).prev('label').css({'left':'-9999px'});
		});
		
		$('#search input').blur(function() {
			$(this).css({'background-position':'-280px 0'});
			if ($(this).val() == '')
				$(this).prev('label').css({'left':'9px'});
		});
	
	},
	
	//CONTRAST ---------------------
	
	contrast:function() {
	
		if($.cookie('CONTRAST')) {
			$('body').addClass($.cookie('CONTRAST'));	
		}
		
		$('#toggle-contrast').click(function() {
							
			if ($('body').hasClass('contrast')) {
				$('body').removeClass('contrast');
				$.cookie('CONTRAST', null, { path: '/', expires: 10000 });
			} else {
				$('body').addClass('contrast')
				$.cookie('CONTRAST', 'contrast', { path: '/', expires: 10000 });
			}
			return false;
		});
	
	},
	
	//STOP PAGE SCROLL ON LOAD ---------------------
	//When linking from contact page to tabed item in locations and maps the page would scoll to the
	//bottom.  This function stops this from happening. 
	tabScroll:function() {

		$(window).scrollTop(0);
	
	},
	
	//EXTERNAL LINKS ---------------------
	
	externalLinks:function() {
	
		var extLinks = $('a.external');
			if ( extLinks.length ) {
				extLinks.each(function() { 
					$(this).attr('target', '_blank');
			});
		}
	
	}
		

};





