/*
*ロールオーバー対象画像変更関数
*/
jQuery.fn.imgreplace = function(classname,suffix){
	classname = classname || 'swap';
	suffix = suffix || '_on';
	return this.not('[src*="'+ suffix + '."]').each(function() {
		var img = jQuery(this);
		var src = img.attr('src');
		var _on = [
			src.substr(0, src.lastIndexOf('.')),
			src.substring(src.lastIndexOf('.'))
		].join(suffix);
		jQuery('<img>').attr('src', _on);
		img.attr('src', _on);
		img.removeClass(classname);
	});
};

/*
*ロールオーバー関数
*/
jQuery.fn.rollover = function(toggle,classname,suffix){
	classname = classname || 'swap';
	suffix = suffix || '_on';
	return this.not('[class!="' + classname +'"]').each(function() {
		var img = jQuery(this);
		var src = img.attr('src');
		var _on = [
			src.substr(0, src.lastIndexOf('.')),
			src.substring(src.lastIndexOf('.'))
		].join(suffix);

		if (toggle == "on"){
			img.attr('src', _on);
		}else{
			img.attr('src', src.replace(suffix,""));
		}

	});
};
/*
*コンテンツナビ選択関数
*/
jQuery.fn.naviselection = function(flag) {
	flag = flag || false;
	if(!flag){
		$(this).find('a').removeClass("productNav");
		$(this).find('a').addClass("active");
	}else if(flag){
		$(this).find('a').removeClass("active");
		$(this).find('a').addClass("productNav");
	}
};
/*
*タブクリック時画像変更関数
*/
jQuery.fn.clicktabs = function(ids,classname,suffix){
	classname = classname || 'swap';
	suffix = suffix || '_on';
	var s_id = $(this).attr('id');
	var i = 0;
	var b = true;
	jQuery.each(ids, function() {
		var img = $('#' + this);
		var src = img.attr('src');
		if (s_id == this){
			src = src.replace(suffix,"");
			var srcArr = src.split('.');
			var src = srcArr[0] + suffix + '.' + srcArr[1];
			img.attr('src', src);
			img.removeClass(classname);
			b = false;
		}else{
			img.attr('src',src.replace(suffix,""));
			img.attr('class',classname);
		}
		if (b){
			i++;
		}
	});

	return i;

};
/*
*タブ画像変更関数
*/
jQuery.fn.changetabs = function(count,ids,classname,suffix){
	classname = classname || 'swap';
	suffix = suffix || '_on';
	var i = 0;
	return jQuery.each(ids, function() {
		var img = $('#' + this);
		var src = img.attr('src');

		if (i == count){
			src = src.replace(suffix,"");
			var srcArr = src.split('.');
			var src = srcArr[0] + suffix + '.' + srcArr[1];
			img.attr('src', src);
			img.removeClass(classname);
		}else{
			img.attr('src',src.replace(suffix,""));
			img.attr('class',classname);
		}
		i ++;
	});

};
$(function(){
	//ロールオーバーイベント
	//マウスオーバー
	$("img.swap").mouseover(function(){
		//ロールオーバー
		$(this).rollover("on");
	});
	//マウスアウト
	$("img.swap").mouseout(function(){
		//ロールアウト
		$(this).rollover("out");
	});
});
$(function(){
		$("#gNavi img").fadeTo(1,0);
		$("#gNavi img").hover(
		  function () {
			$(this).stop().fadeTo(100, 1);
		  },
		  function () {
			$(this).stop().fadeTo(500, 0);
		  }
		);
		$(".over").hover(
		  function () {
			$(this).stop().fadeTo(100, 0.7);
		  },
		  function () {
			$(this).stop().fadeTo(500, 1);
		  }
		);

		//giants 100527追加
		$(".over02").hover(
		  function () {
			$(this).stop().fadeTo(300, 1);
		  },
		  function () {
			$(this).stop().fadeTo(500, 0);
		  }
		);

		var active = "/common/images/header/btn_gnavi_active.gif";
		if($("#g01 .gNav01 img")[0] !== undefined){
			$("#g01 .gNav01 img")[0].src = active;

		}else if($("#g02 .gNav02 img")[0] !== undefined){
			$("#g02 .gNav02 img")[0].src = active;

		}else if($("#g03 .gNav03 img")[0] !== undefined){
			$("#g03 .gNav03 img")[0].src = active;

		}else if($("#g04 .gNav04 img")[0] !== undefined){
			$("#g04 .gNav04 img")[0].src = active;

		}else if($("#g05 .gNav05 img")[0] !== undefined){
			$("#g05 .gNav05 img")[0].src = active;

		}else if($("#g06 .gNav06 img")[0] !== undefined){
			$("#g06 .gNav06 img")[0].src = active;
		}
		/*--/giants追加--*/

		$("#g01 .gNav01 img,"+
		  "#g02 .gNav02 img,"+
		  "#g03 .gNav03 img,"+
		  "#g04 .gNav04 img,"+
		  "#g05 .gNav05 img,"+
		  "#g06 .gNav06 img").unbind('mouseover').unbind('mouseout').fadeTo(1,1);
});
/*
*Firefox用CSS呼び出し
*/
var firefox = (navigator.userAgent.indexOf("Firefox") != -1)? true : false;
if(firefox) document.write('<link rel="stylesheet" type="text/css" media="print" href="/common/css/fx_print.css" />');
/*
*サイト内検索
*/
$(function(){
	$('#searchBox')
		.blur(function(){
			var $$=$(this);
			if($$.val()=='' || $$.val()==$$.attr('title')){
			$$.css('color', '#333')
				.val($$.attr('title'));
		}
	})
		.focus(function(){
			var $$=$(this);
			if($$.val()==$$.attr('title')){
			$(this).css('color', '#333')
				.val('');
		}
	})
		.parents('form:first').submit(function(){
			var $$=$('#searchBox');
			if($$.val()==$$.attr('title')){
			$$.triggerHandler('focus');
		}
	}).end()
	.blur();
});


/*
*ソーシャルブックマーク
*/
$(function(){
	$(".share_twitter").click(function(){
		window.open('http://twitter.com/home?status='+encodeURIComponent(document.title)+' '+encodeURIComponent(document.URL));
		return false;
	});
	$(".share_google").click(function(){
		window.open('http://www.google.com/bookmarks/mark?op=edit&bkmk='+encodeURIComponent(document.URL)+'&title='+encodeURIComponent(document.title));
		return false;
	});
	$(".share_delicious").click(function(){
		window.open('http://del.icio.us/post?url='+encodeURIComponent(document.URL)+'&title='+encodeURIComponent(document.title));
		return false;
	});
	$(".share_hatena").click(function(){
		window.open('http://b.hatena.ne.jp/add?mode=confirm&is_bm=1&title='+encodeURIComponent(document.title)+'&url='+encodeURIComponent(document.URL));
		return false;
	});
	$(".share_livedoor").click(function(){
		window.open('http://clip.livedoor.com/redirect?link='+encodeURIComponent(document.URL)+'&title='+encodeURIComponent(document.title)+'&ie=UTF-8');
		return false;
	});
	$(".share_yahoo").click(function(){
		window.open('http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?t='+encodeURIComponent(document.title)+'&u='+encodeURIComponent(document.URL)+'&opener=bm&ei=UTF-8','popup','width=550,height=480,resizable=yes,scrollbars=yes');
		return false;
	});
});


