﻿/// <reference path="jquery.js" />
/* JavaScript File 

	Enhances a Scott's Tab Control.
	It requires multiple tab controls on one page;
	it will combine all of them into one tab control!

	Requires a reference to the jQuery.js library!
	<script type="text/javascript" language="javascript" src="js/jquery.js" />
	
Example:
<div class="CombineTabs">
	<div>
		<ul class="tabRow">
			<li class="tabSelected"><a href="#"><span class="tabContent" >
				Tab One
			</span></a><span class="tabConnect"></span></li>
		</ul>
		
		<div class="GroupSlider">
			<div class="TopRight"><div class="TopLeft">
				<h1>Tab One Content</h1>
				<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
			</div></div><div class="BottomRight"><div class="BottomLeft"></div></div>
		</div>
	</div>
	<div>
		<ul class="tabRow">
			<li class="tabSelected"><a href="#"><span class="tabContent" >
				Tab Two
			</span></a><span class="tabConnect"></span></li>
		</ul>
		
		<div class="GroupSlider">
			<div class="TopRight"><div class="TopLeft">
				<h1>Tab Two Content</h1>
				<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
			</div></div><div class="BottomRight"><div class="BottomLeft"></div></div>
		</div>
	</div>
</div>
	
	
*/

$(CombineAllScottsTabControls);
function CombineAllScottsTabControls (){
	$(".CombineTabs").each(function(){
	
//	var CombineTabsContainer = $(".CombineTabs").eq(0);
	var CombineTabsContainer = $(this);
	
	var tabRow = CombineTabsContainer.find("ul.tabRow").eq(0);
	var tabPage = CombineTabsContainer.find(".TopLeft").eq(0);



	var allTabs = CombineTabsContainer.find("ul.tabRow > li");
	//Store the contents of the tab into a variable attached to the tab
	allTabs.each(function(){
		//Adds the contents of the tab to a variable attached to the tab!
		
		//get the contents of the tab 
		var TabContents = $(this).parent().next().find(".TopLeft").children();
		//add a div to the tabPage, then move the contents there
		TabContents = $("<div></div>").prependTo(tabPage).append(TabContents);

		//hide the tab contents		
		TabContents.hide();

		//Move the tab to the master tab
		$(this).appendTo(tabRow);
		//Create an association between the tab and the contents:
		this.tabContents = TabContents; 
	});
	
	//Remove all former tab controls
	CombineTabsContainer.find("ul.tabRow").parent().slice(1).remove();


	//Add the click handlers
	allTabs.mouseover(function(){ SelectTab(this, 500); }); 

	//Select the first default tab

	
	SelectTab(allTabs.get(0), 0 );
	
	//now, if any of the links equal the current link, then we should select it!
	allTabs.each(function(){
		if ($(this).find("a").get(0).href == location.href) {
			SelectTab(this, 0);
			return false;
		}
	});
	
	});
}
function SelectTab(tabItem, animationSpeed){
	//De-select all tabs:
	$(tabItem).parent().find("li").removeClass("tabSelected").addClass("tab");
	
	//Select the current tab:
	$(tabItem).addClass("tabSelected").removeClass("tab");
	
	
	//Let's show the current tab contents
	//We will animate, unless there is an "embed" tag present (or "object" tag)
	
	var AlwaysAnimate = false;
	if (tabItem.tabContents.find("embed,object").length == 0 || AlwaysAnimate){
		//There are no embed tags (it's ok to animate)
		//tabItem.tabContents.show(animationSpeed); 
		//tabItem.tabContents.siblings().hide(animationSpeed); 
		tabItem.tabContents.slideDown(animationSpeed);
		tabItem.tabContents.siblings().slideUp(animationSpeed);
	} else {
		//There are embed tags, which means we shouldn't animate
		//because it will look really bad with flash embedded.
		tabItem.tabContents.show();
		tabItem.tabContents.find("embed,object").css("visibility", "visible");
		tabItem.tabContents.siblings().hide();
		tabItem.tabContents.siblings().find("embed,object").css("visibility", "hidden");
	}

	return false; //prevent the link from being followed
}




