
var tabset = new Class( {
	initialize: function(tabNavigation, tabGroup, selectedTab, tabClassSelector) {
		this.tabNavigation = tabNavigation;
		this.tabGroup = tabGroup;
		this.selectedTab = selectedTab;
		this.tabContainers = $$(tabClassSelector);
		this.location = window.location.hash;
		
		if($E(this.location)&& this.location !="" && this.location !=null) {
			this.selectedTab = $E(this.location);
		}
						
		(this.tabContainers).each(function(el, i) {
			if(el != this.selectedTab) {
				el.setStyle("display", "none");
			}	
		}, this);
		
		(this.tabNavigation).each(function(el, i) {
			if(el.hash == "#"+this.selectedTab.id) {
				el.addClass("on");
			}
			el.bindObj = this;
			el.onclick = this.selectTab;
			el.addEvent("mouseleave", function() {
				this.bindObj.changeS7IRPaths();
			}); 
			
			//el.onmouseover = this.changeRolloverState;
			
			//el.addEvent("mouseenter", function() {
			//	this.bindObj.changeS7IRPathsMouseOver();
			//}); 			
			
		}, this);
	},
	changeRolloverState: function() {
		var anchor = this;
		if (anchor.hasClass("on")) return;
		if (!anchor.getElements("span.s7IR-replaced").length > 0) return;
		
		var image = anchor.getElements("span.s7IR-replaced img")[0];
		var source = anchor.getElements("span.s7IR-replaced img")[0].getProperty("src");
		
		
	},
	selectTab: function () {
		this.bindObj.hideAllTabs();
		//var targetTabIDWithHash = $(this).getProperty("href");
		var targetTabIDWithHash = this.getAttribute("href",2);
		//targetTabIDWithHash  = this.hash.slice(1);
		
		targetTabIDWithHash = targetTabIDWithHash.substring(targetTabIDWithHash.indexOf("#"))
		
		
		var targetTab = $E("div"+targetTabIDWithHash);
		
		$$(targetTabIDWithHash).setStyle("display", "block");
		this.addClass("on");
		
		this.bindObj.changeS7IRPaths();
		
		return false;
	},
	changeS7IRPaths: function() {
		(this.tabNavigation).each(function(el, i) {
			if (el.getElements("span.s7IR-replaced").length > 0) {
				var theImage = el.getElements("span.s7IR-replaced img")[0];
				var tagSource = el.getElements("span.s7IR-replaced img")[0].getProperty("src");
				var location = tagSource.split("?")[0];
				var queryString = "";
				var wording = tagSource.substring(tagSource.indexOf("fs22")+4, tagSource.length);
				
				if (el.hasClass("on")) {
					queryString = "?fmt=gif&size=0,0&bgc=51,51,51&layer=comp&text={\\fonttbl\\f1HelveticaNeue-BoldCond}{\\colortbl\\red255\\green255\\blue255;}\\expnd-2\\kerning1\\cf0\\f1\\fs22";
					tagsource = location + queryString + wording;
					theImage.src = tagsource;
				}
				else {
					queryString = "?fmt=gif&size=0,0&bgc=190,190,190&layer=comp&text={\\fonttbl\\f1HelveticaNeue-BoldCond}{\\colortbl\\red51\\green51\\blue51;}\\expnd-2\\kerning1\\cf0\\f1\\fs22";	
					tagsource = location + queryString + wording;
					theImage.src = tagsource;
				}
			}
		});
	},
	
	changeS7IRPathsMouseOver: function() {
		//alert(this.tagName);

		(this.tabNavigation).each(function(el, i) {
			if (el.getElements("span.s7IR-replaced").length > 0) {
				var theImage = el.getElements("span.s7IR-replaced img")[0];
				var tagSource = el.getElements("span.s7IR-replaced img")[0].getProperty("src");
				var location = tagSource.split("?")[0];
				var queryString = "";
				var wording = tagSource.substring(tagSource.indexOf("fs22")+4, tagSource.length);
				
				if (!el.hasClass("on")) {
					queryString = "?fmt=gif&size=0,0&bgc=255,255,255&layer=comp&text={\\fonttbl\\f1HelveticaNeue-BoldCond}{\\colortbl\\red51\\green51\\blue51;}\\expnd-2\\kerning1\\cf0\\f1\\fs22";
					tagsource = location + queryString + wording;
					theImage.src = tagsource;
				}
			}
		});
	},	
	hideAllTabs: function() {
		(this.tabContainers).each(function(el, i) {
			el.setStyle("display", "none");	
		});
		
		(this.tabNavigation).each(function(el, i) {
			el.removeClass("on");
		});
	}
});
	
window.addEvent('domready', function(){
	var myTabs = new tabset($$("div#crossSell ul.tabNavigation li a"), "mygroup", $("tab1"), $$("div#crossSell div.tab"));
	var myPsiTabs = new tabset($$("div#productSupportInfo ul.tabNavigation li a"), "myPsigroup", $("psiTab1"), $$("div#productSupportInfo div.tab"));
	var ffProductDetails = new tabset($$("div#productInformation ul.tabNavigation li a"), "productInformation", $("productInformation01"), $$("div#productInformation div.tab"));
	var myStoreDetailsTabs = new tabset($$("div#storeDetailsTabControl ul.tabNavigation li a"), "myStoreDetailsgroup", $("storedetailstab1"), $$("div#storeDetailsTabControl div.tab"));
	var genericTabs = new tabset($$("div#genericTabbed ul.tabNavigation li a"), "genericTabbedGroup", $("generictab1"), $$("div#genericTabbed div.tab"));
});