// JavaScript Document
(function($) {
	$.fn.cTabs = function(options) {
		var optionObj = $.extend($.fn.cTabs.defaults, options);
		var tabs = this;
		var tabItemObj = new Object;
		
		var init = function() {
			$("." + tabs.attr("class") + " ." + optionObj.tabContentClass).css({display : "none"});
			$("." + tabs.attr("class") + " ." + optionObj.tabContentClass + ":first").css({display : "block"});
			
			if (!$("." + optionObj.tabItemClass).hasClass(optionObj.tabItemClassActive)) {
				$("."+ tabs.attr("class") + " ." + optionObj.tabItemClass + ":first").addClass(optionObj.tabItemClassActive);
				if (optionObj.tabItemRoundedCorners) {
					$("."+ tabs.attr("class") + " li:first").addClass(optionObj.tabItemClassActive);
				}
			}

			$("."+ tabs.attr("class") + " ." + optionObj.tabItemClass).each(function(i) {
				tabItemObj[i] = $(this).attr("rev");
			});
				
			$("." + tabs.attr("class") + " ." + optionObj.tabContentClass).each(function(i) {
				$(this).addClass(tabItemObj[i]);
			});
			
			
			changeTab($("." + optionObj.tabItemClassActive).attr("rev"));
			
		};
		
		var hoverTabItem = function(obj) {
			if ($(obj).hasClass(optionObj.tabItemClassHover)) {
				$(obj).removeClass(optionObj.tabItemClassHover);
				if (optionObj.tabItemRoundedCorners) {
					$(obj).parent().removeClass(optionObj.tabItemClassHover);
				}
			} else {
				$(obj).addClass(optionObj.tabItemClassHover);
				if (optionObj.tabItemRoundedCorners) {
					$(obj).parent().addClass(optionObj.tabItemClassHover);
				}
			}
		};
	
		var clickTabItem = function(obj) {
			$(obj).removeAttr("href");
			$(obj).css({cursor : "pointer"});

			$("."+ tabs.attr("class") + " ." + optionObj.tabItemClass).removeClass(optionObj.tabItemClassActive);
			if (optionObj.tabItemRoundedCorners) {
				$("."+ tabs.attr("class") + " li").removeClass(optionObj.tabItemClassActive);
			}
			$(obj).addClass(optionObj.tabItemClassActive);
			if (optionObj.tabItemRoundedCorners) {
				$(obj).parent().addClass(optionObj.tabItemClassActive);
			}
			changeTab($(obj).attr("rev"));
		};

		var changeTab = function(className) {
			$("." + tabs.attr("class") + " ." + optionObj.tabContentClass).css({display : "none"});
			$("." + tabs.attr("class") + " ." + className).css({display : "block"});
		};

		$("."+ tabs.attr("class") +" ."+ optionObj.tabItemClass).click(function(){
			clickTabItem(this);
		});		

		$("."+ tabs.attr("class") +" ."+ optionObj.tabItemClass).hover(function(){
			hoverTabItem(this);
		}, function(){
			hoverTabItem(this);			
		});		

		init();
		
		return this;
	};

})(jQuery);

$.fn.cTabs.defaults = {
	// hier alle default opties scheiden door een komma	
	tabItemClass :				"cTabItem",
	tabItemClassHover :			"cTabItemHover",
	tabItemClassActive :		"cTabItemActive",
	tabItemRoundedCorners :		false,
	tabContentClass :			"cTabContent"
	};

