/**
 * @author Aaron.Lisman
 */

(function($){

	// extend jquery with the plugin
 	$.fn.merckTabs = function(options) {	
		return new merckTabs(this,options);				
	}
	
	// constructor
	function merckTabs(el,options) {
		this.Init(el);		
	}
	
	// plugin methods and props
	$.extend(merckTabs.prototype, {
		// props, collections		
		Panes: null,
		Tabs: null,
		TargetEl: null,
		//
		Init: function(el) {
			this.TargetEl = el;
			this.Items = this.TargetEl.children("li");
			this.Panes = this.TargetEl.children("div");
			this.Tabs = this.TargetEl.find("ul.merckTabs-nav li");
			this.SetStyles();
			this.SetHandlers();
			this.OpenPane(this.Tabs.filter(":eq(0)"));
			
			this.Tabs.filter(":first").css("left",3);
		},
		SetHandlers: function() {
			var self = this;
			this.Tabs.find("a")
				.VoidLink()
				.click( function() {
					var tab = $(this).parent(); // get the li 
					self.OpenPane(tab);
				});
			//set hover states
			this.Tabs.find("a").hover( 
				function() {
					$(this).toggleClass("merckTabs-tab-over");
				},
				function() {
					$(this).toggleClass("merckTabs-tab-over");
				}
			);						
		},		
		OpenPane: function(el) {
			var self = this;
			
			var openFunc = function(){
				self.Tabs.removeClass("on");
				// give it the on class
				$(el).toggleClass("on");
				
				// hide all panes
				self.TargetEl.children("div").hide();
				// get the index of the tab
				var index = self.Tabs.index(el);
				// show pane of correct index
				self.TargetEl.children("div:eq(" + index + ")").show();
			}	
			//h4.toggleClass("module-merckAccordian-accordian-tab-open")
			//	.next("div").toggle();
			//	h4.find("a").attr("title",h4.find("a").attr("title").replace("- closed","- open"));		
			
			// to fix ie6 background behavior bug, set a small timeout
			setTimeout(openFunc,100);
		},
		SetStyles: function() {
	
		}
	});
	
})(jQuery);
