$(function(){

	// REDIRECTS IN PLAIN JS
	var browser		= navigator.appName,
		ver			= navigator.appVersion,
		thestart	= parseFloat(ver.indexOf("MSIE"))+1,
		brow_ver	= parseFloat(ver.substring(thestart+4,thestart+7));

	if ((browser=="Microsoft Internet Explorer") && (brow_ver < 7)) {
		if (window.location !== "http://www.stittsinmed.com/redirect.php") {
			window.location = "http://www.stittsinmed.com/redirect.html";
		};
	};

	/**
	  * Javascript Tab Code 
	  * Copyright David Baker (dtbaker@gmail.com)
	  * Created for ThemeForest theme Nov 2009
	  */
	var current_tab = 1; // start with first tab.
	var tab_count = 1; // loop counter.
	var tab_auto = 0; // how many seconds to wait for auto scroll
	// first name each of our tab contents.
	$('#tab_content li').each(function(){
		$(this).attr('rel',tab_count);
		if(tab_count != current_tab)$(this).hide(); // hide all that are not current.
		else $(this).show();
		tab_count++;
	});
	tab_count = 1;
	// bind the clicks.
	function tab_gogo(this_tab_id){
		// find an existing tab, fade it out.
		var tab = $('#home_tabs li a[rel='+this_tab_id+']');
		if(current_tab){
			if($.browser.msie)$('#tab_content li[rel=' + current_tab + ']').hide();
			else $('#tab_content li[rel=' + current_tab + ']').fadeOut();
		}
		// find the tab to display... fade it in.
		if($.browser.msie)$('#tab_content li[rel=' + this_tab_id + ']').show();
		else $('#tab_content li[rel=' + this_tab_id + ']').fadeIn();
		// remove any old current list items.
		$('#home_tabs li.current').removeClass('current');
		// change the state of the holding li item to current for styling.
		$(tab).parent('li').addClass('current');
		current_tab = this_tab_id;
	}
	$('#home_tabs li a').each(function(){
		// each of the a links, find it's count and set a callback on the a link.
		$(this).attr('rel',tab_count);
		// just for first time loading.
		if(tab_count == current_tab)$(this).parent('li').addClass('current'); 
		$(this).click(function(){
			var this_tab_id = $(this).attr('rel');
			tab_auto = 0;
			tab_gogo(this_tab_id);
			return false;
		});
		tab_count++;
  	});
	if(tab_auto){
		function tab_auto_gogo(){
			if(!tab_auto)return;
			// how many tabs are there.
			var this_current = current_tab;
			if(this_current >= $('#home_tabs li a').size())this_current = 1;
			else this_current++;
			tab_gogo(this_current); //$('#home_tabs li a[rel='+this_current+']').click();
			setTimeout(tab_auto_gogo,tab_auto*1000);
		}
		setTimeout(tab_auto_gogo,tab_auto*1000);
	}
	
	// FOR LIGHTBOXES
	$('.lightbox').lightBox();
	
	// SELECTED STATE FOR MAIN NAV
	current_page = document.location.href

	if (current_page == "http://www.stittsinmed.onesandzerosweb.com/" || current_page.match(/stittsinmed.onesandzerosweb.com\/index.php/)) {
		$("ul#navigation li.main_nav:eq(0)").addClass('current');		
	} else if (current_page.match(/services/)) {
		$("ul#navigation li.main_nav:eq(1)").addClass('current');		
	} else if (current_page.match(/about/)) {
		$("ul#navigation li.main_nav:eq(2)").addClass('current');
	} else if (current_page.match(/forms/)) {
		$("ul#navigation li.main_nav:eq(3)").addClass('current');
	} else if (current_page.match(/contact/)) {
		$("ul#navigation li.main_nav:eq(4)").addClass('current');
	} else { // don't make any nav links as selected
		$("ul#navigation li.main_nav").removeClass('current');
	};
	
	// 	ROTATING FADE EFFECT ON FIRST TAB OF HOMEPAGE
	$('.slideshow').rotate_fade();
	
	// FAUX LINKS SHOULD RETURN FALSE
	$('a.faux_link').click(function() {
		return false;
	});

});
