
	$(function() {






		var ClassTab = function(tabs_, pages_, select_) {
			this.tabs = tabs_;
			this.pages = pages_;
			this.select = select_;
		}
		ClassTab.prototype = {
			rollOver : function(index_) {
				var tabs = this.tabs;
				var imgs = tabs.find("img");
				
				imgs.each(function(idx_){
					var index = imgs.index(this);
					var img = $(this);
					img.unbind("mouseenter").unbind("mouseleave");//img.unbind('hover');ではできないらしい
					
					if(index_ == idx_) {
						img.attr("src", img.attr("src").replace("_off.", "_on."));
					}
					else {
						img.attr("src", img.attr("src").replace("_on.", "_off."));

						img.hover(function () {
							$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
						},function () {
							$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
						});
					}
				});
			},
			showpage : function(index_) {
				var pages = this.pages;
				
				pages.each(function(idx_){
					if(idx_ == index_) {
						$(this).removeClass("ui-tabs-hide");
					}
					else{
						$(this).addClass("ui-tabs-hide");
					}
				});
			},
			init : function() {
				var tabs = this.tabs;
				var imgs = tabs.find("img");
				var pages = this.pages;
				var select = this.select;
				var cls = this;
				
				pages.each(function(idx_){
					if(idx_ == select) {
						$(this).removeClass("ui-tabs-hide");
					}
					else{
						$(this).addClass("ui-tabs-hide");
					}
				});
				
				tabs.click(function(){
					var index =  tabs.index(this);
					cls.showpage(index);
					
					//選択されたタブの番号をクッキーに保存
					$.cookie("topTab", index, { path:'/',expires: 30 });
					
					return false;
				});
				
				imgs.click(function(){
					var index = imgs.index(this);
					cls.rollOver(index);
					
				});
				
				cls.rollOver(select);
				
			}
		};
		


		//トピックスのタブ実装
		var tabSelect = 0;
		if($.cookie("topTab")) {
			tabSelect = $.cookie("topTab");
		}
		var tab = new ClassTab($("#tab > ul > li"), $("#tab > div"), tabSelect);
		tab.init();
		


		//バナークリック数カウント
		$('.cat8Mod ul a').each(function() {
			$(this).click(function(){
				_gaq.push(['_trackEvent','トップページ 広告クリック数', $(this).find("img").attr('alt'), $(this).attr('href')]);
			});
		});


		
	});







