/*
 * jcommon.js 3.1
 * Copyright (c) 2010 C.M.A. Co.,Ltd.
 * 
 * Last Update: 2010-06-03
 *
 */

//GoogleAnalytics
var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-6089355-1']); 
_gaq.push(['_setDomainName', 'none']); 
_gaq.push(['_setAllowLinker', true]); 
_gaq.push(['_trackPageview']); 
(function() { 
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
})();

//Utility
var absPath,sharePath = '/shared',isWebKit = navigator.userAgent.match(/WebKit/),isLinkAry = location.pathname.split('/').slice(1),jcommon={preloader:{loadedImages:[],load:function(a){var b=this.loadedImages,c=b.length;b[c]=new Image;b[c].src=a}},URIExp:new RegExp("^[https]*[^a-z]*"+document.domain),URI:function(a){this.absolutePath=a.replace(jcommon.URIExp,"").replace(/^[^a-z]*/,"").replace(/index.*$/,"").replace(/\/$/,"");this.len=isLinkAry.length;for(this.isSelfLink=false;this.len--&&!this.isSelfLink;)this.isSelfLink=this.isSelfLink||this.absolutePath==isLinkAry[this.len]},addLinkAry:function(){for(var a=0,b=isLinkAry.length;a<
b;)isLinkAry.push(isLinkAry.slice(0,++a).join("/").replace(/^\//,"").replace(/index.*$/,""))}};jcommon.addLinkAry();

//PathControl
var siteKey = 'megabass';
switch(location.host){
	case 'www.megabass.co.jp':absPath = '';break;
	case '120.29.169.184':absPath = '';break;
	case 'megab235.securesites.net':absPath = '';break;
	case 'www2.akindo2000.net':absPath = '/'+siteKey;var isBeta = true;break;
	default:absPath = '/Y:/Htdocs/'+siteKey+'/\u672c\u4f53\u30b5\u30a4\u30c8/www/\u4f5c\u696d\u7528';var isBeta = true;break;
}

//IncludeControl
(function(g){function f(c){try{return eval("typeof "+c)!="undefined"}catch(b){}return false}function h(c){var b=document.createElement("script");b.type="text/javascript";b.src=c;(document.getElementsByTagName("head").item(0)||document.body).appendChild(b)}var d;(function c(){var b=g.shift();if(!b)return d&&d();if(typeof b=="string"||b instanceof String)b={window:b};for(var e in b)if(e=="window"||!f(e))h(b[e]);var j=setInterval(function(){for(var i in b)if(!f(i))return;clearInterval(j);c()},99)})();
return function(c){return function(){var b=arguments;d=function(){c.apply(c,b)}}}})
([
	{'jQuery':absPath+'/shared/js/jquery-1.4.3.min.js'},
	{'jQuery.easing.easeInQuad':absPath+'/shared/js/jquery.easing.js',
	  'jQuery.fn.lightpop':absPath+'/shared/js/lightpop.js',
	  'jQuery.fn.flatHeights':absPath+'/shared/js/flatheights.js'
	 } 
])
(function(){
	//beta
	if(isBeta){
		$('a[href^="/"]').each(function(){var url = $(this).attr('href');$(this).attr('href',absPath+url);});
		$('img[src^="/"]').each(function(){var url = $(this).attr('src');$(this).attr('src',absPath+url);});
	}
	//ロールオーバー
	$.fn.addRollOver=function(add){$(this).filter('img').each(function(){$(this).runRollOver(add,$(this));}).end().not('img').each(function(){$(this).runRollOver(add,$(this).find('img'));});};
	$.fn.runRollOver=function(add,target){$(this).each(function(num){this.originalSrc=String(target.attr('src'));this.rolloverSrc=this.originalSrc.replace(/(\.gif|\.jpg|\.png)/,add+"$1");}).hover(function(){target.attr('src',this.rolloverSrc);},function(){target.attr('src',this.originalSrc);});};
	//現在のページへのリンク
	$.fn.addCurrentImages=function(add){$(this).each(function(){var href=new jcommon.URI($(this).attr('href'));if(href.isSelfLink){$(this).addClass('current');$(this).unbind('mouseenter');$(this).unbind('mouseleave');$(this).find('img').each(function(){$(this).unbind('mouseenter');$(this).unbind('mouseleave');this.currentSrc=this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/,add+"$1");$(this).attr('src',this.currentSrc)});}});};	
	//ページ全体にリンク
	$.fn.groupLink=function(){$(this).css({cursor:'pointer'}).hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){location.href=$(this).find('a:first').attr('href');return false})}	
	//slider
	$.fn.slider=function(a){a=jQuery.extend({movement:"slide",isCurrentImage:false,currentImage:"_on",currentClass:"current",contClass:".contents",nextClass:".next",backClass:".back",naviClass:".navigation",separate:1,overshoot:10,time:500,easeStrength:"Expo"},a);var g=$(this),i=$(this).find(a.contClass+":first"),n=$(this).find(a.nextClass+":first"),o=$(this).find(a.backClass+":first"),k=$(this).find(a.naviClass+":first"),m=i.find("ul:first>li").length,d=0,b=g.attr("id")||g.attr("class").split(" ",1);g.bind("moveContent"+b,function(j,c){var h=false,e=0,f;if(c<0||c>=m){d=c<0?0:m-a.separate;e=a.overshoot*(c<0?1:-1);h=true}else{f=k.find("li:eq("+d/a.separate+")");f.trigger("changeImage"+b,false);d=c;f=k.find("li:eq("+d/a.separate+")");f.trigger("changeImage"+b,true)}f=i.find("ul:first>li:eq("+d+")").position().left;var l=i.find("ul:first>li:eq("+d+")").position().top;if(h){h=a.movement=="slide"?e:0;e=a.movement=="updown"?e:0;i.find("ul:first").queue("fx",[]).animate({left:-f+h,top:-l+e},{duration:a.time/2,easing:"easeOutExpo"}).animate({left:-f,top:-l},{duration:a.time/2,easing:"easeInOutExpo"})}else i.find("ul:first").queue("fx",[]).animate({left:-f,top:-l},{duration:a.time,easing:"easeOutExpo"})});o.click(function(){g.trigger("moveContent"+b,[d-a.separate]);return false});n.click(function(){g.trigger("moveContent"+b,[d+a.separate]);return false});k.find("li").click(function(){if($(this).find("a").attr("href")=="#"){g.trigger("moveContent"+b,[$(this).index()*a.separate]);return false}}).bind("changeImage"+b,function(j,c,h){if(a.isCurrentImage){j=$(this).find("img").attr("src");var e=new RegExp(a.currentImage+"(.[a-z]+)$");if(c&&!j.match(e))$(this).find("img").attr("src",j.replace(/(\.[a-z]+)$/,a.currentImage+"$1"));else c||$(this).find("img").attr("src",j.replace(e,"$1"))}h||(c?$(this).addClass(a.currentClass):$(this).removeClass(a.currentClass))}).hover(function(){$(this).hasClass(a.currentClass)||$(this).trigger("changeImage"+b,[true,true])},function(){$(this).hasClass(a.currentClass)||$(this).trigger("changeImage"+b,[false,true])});return this};

	$(function(){
	
		//ロールオーバー
		$('a img.btn,.toTop a img,a.btn,#globalNav li a').addRollOver('_on');
		//現在のページへのリンク
		$('#globalNav li a,#localNav dl a').addCurrentImages('_on');	
		//外部リンクは別ウインドウを設定
		$('a[href^="http://"],area[href^="http://"]').not('[href^="http://www.megabass.co.jp/"],[href^="http://www.megabass.com/"],[href^="http://120.29.169.184/"]').click(function(){
			window.open(this.href, '_blank');
			return false;
		}).addClass('externalLink');
		//別ウィンドウを設定
		//$('a[href$=".pdf"],a[href$=".asx"]').click(function(){
		//	window.open(this.href, '_blank');
		//	return false;
		//});
		//全体にリンク
		$('.brandLineup ul.brandLineupList li','#main')
			.add('#productsList li','#main')
			.add('#colorVariation li','#main')
			.add('#lineup li','body.products').groupLink();		
		//#GlovalNav
		$.getJSON(absPath+'/shared/data/globalNav.json', function(data) {
			$('#header').append('<div id="udNav"></div>');
			$('li','#globalNav').each(function(num){
				var	
					list = data.navigation[num],
					html = [],
					i = 0;
				this.n = num;
				html.push('<div id="nav'+list.id+'" class="l'+num+'"><ul>');
				//if(num==1) alert(num+':'+list.title);
				while(list.contents[i]){
					var c = list.contents[i];
					if(c.contents){
					
						if(c.href)html.push('<li><a href="'+c.href+'">'+c.title+'</a>');
						if(c.contents.length){
							html.push('<div class="l'+i+'"><ul>');
							var j = 0;
							while(c.contents[j]){
								var inC = c.contents[j];
								if(inC.href)html.push('<li><a href="'+inC.href+'">'+inC.title+'</a></li>');
								j++;
							}
							html.push('</ul></div>');
						}
						if(c.href)html.push('</li>');
					}else{
						if(list.id=='blog'){ if(c.href)html.push('<li><a href="'+c.href+'"><img src="/shared/img/navigation/navi_g_blog_'+c.id+'.jpg" /></a></li>'); }
						else{ if(c.href)html.push('<li><a href="'+c.href+'">'+c.title+'</a></li>'); }
					}
					i++;
				}
				html.push('</ul></div>');
				
				$('#udNav').append(html.join(''));
				var offsetL = 0;//num==0?0:-10;
				$('#udNav').children('div.l'+this.n).css({top:$(this).position().top+67+42,left:$(this).position().left+offsetL});

				$(this).hover(function(){
					$('#udNav').children('div.l'+this.n).addClass('show');
				},function(){
					$('#udNav').children('div.l'+this.n).removeClass('show');
				});
			});
			$('#udNav').find('div').hover(function(){
				$(this).addClass('show');
			},function(){
				$(this).removeClass('show');
			}).find('li').hover(function(){
				$(this).children('div').addClass('show');
			},function(){
				$(this).children('div').removeClass('show');
			});
			
		});
		// Search
		$('#searchBox').load(absPath+'/shared/module/search.html');
	
 	/*------------------------------------------
	 *	ホーム
	 */ if($('#home').length){
		 	
			//Flash
			//if(true){
			if(navigator.userAgent.match(/iPhone/)||navigator.userAgent.match(/iPad/)){
				$('.hide','#swf').css({display:'block'});
				$('.hide','#swf2').css({display:'block'});
				var html = [];
				html.push('<div id="loadSlide" />');
				//html.push('<video id="anglerMovie" src="/media/angler_movie.mp4" poster="/media/dummy.jpg" width="444" height="433" controls autobuffer>');
				//html.push('<p>動画を再生するにはvideoタグをサポートしたブラウザが必要です。</p>');
				//html.push('</video><div id="dummy" />');
				$('#swf3')
					.css({float:'left',width:444,backgroundColor:'#000'})
					.append(html.join(''));
				$('#loadSlide').load('shared/module/slideshow.html',function(){
					$('#swf3 img').hide();
					$('#slide1').show();
					setInterval(function(){
						var num = Number($('#swf3>div>img').attr('src').replace(/[^0-9]+([0-9]+)[^0-9]+/,'$1'));
						if(num==13) num = 0;
						num++;
						$('#slide1').fadeOut(500,function(){
							$(this).attr('src','img/slideshow/pho_slide'+num+'.png').fadeIn(500);
						});
					},8000);
				});
			}else{
				var expressInstall = function() {
					var att = { data:absPath+"/shared/swf/expressInstall.swf", width:"960", height:"442" };
					var par = { menu:false };
					var id = "swf";
					swfobject.showExpressInstall(att, par, id, function(){
						$('.hide','#swf').show();
					});
				}
				if (swfobject.hasFlashPlayerVersion("10")) {
					var fn = function() {
						var att = { data:"loader.swf", width:"960", height:"442" };
						var par = { wmode:"transparent"};
						var id = "swf";
						swfobject.createSWF(att, par, id);
					};
					var fn2 = function() {
						var att = { data:"megabassA.swf", width:"444", height:"640" };
						var par = { wmode:"transparent"};
						var id = "swf2";
						swfobject.createSWF(att, par, id);
					};
					var fn3 = function() {
						var att = { data:"angler_movie.swf", width:"444", height:"433" };
						var par = { wmode:"transparent"};
						var id = "swf3";
						swfobject.createSWF(att, par, id);
					};
				}else {
					var fn = expressInstall();
				}
				swfobject.addDomLoadEvent(fn);
				swfobject.addDomLoadEvent(fn2);
				swfobject.addDomLoadEvent(fn3);
			}
			
			//#infoNav
		 	var	isShowInfoNav;
			$('ul.navigation>li>a','#infoNav').each(function(){
				this.src = $(this).find('img').attr('src');
			}).bind('outOver',function(){
				$(this).find('img').attr('src',this.src.replace(/_on(\.[a-z]+)$/,'$1'));
			}).click(function(){
				isShowInfoNav = false;
				$('ul.navigation>li>a>img','#infoNav').trigger('outOver');
				$('div.slider','#infoNav').height(0);
				$($(this).attr('href')).queue("fx",[]).animate({height:114},{duration:800,easing:"easeOutExpo"});
				$(this).find('img').attr('src',this.src.replace(/(\.[a-z]+)$/,'_on$1'));
				return false;
			}).hover(function(){
				$(this).find('img').attr('src',this.src.replace(/(\.[a-z]+)$/,'_on$1'));
			},function(){
				$(this).queue("fx",[]).animate({margin:0},{duration:1,easing:"linear",
					complete:function(){
						if(!isShowInfoNav){
							$($(this).attr('href')).queue("fx",[]).animate({height:0},{duration:800,easing:"easeOutExpo"});
							$(this).find('img').attr('src',this.src.replace(/_on(\.[a-z]+)$/,'$1'));
						}
					}
				});
			});
			$('div.slider','#infoNav')
			.hover(function(){
				isShowInfoNav = true;
			},function(){
				isShowInfoNav = false;
				$('ul.navigation>li>a>img','#infoNav').trigger('outOver');
				$(this).queue("fx",[]).animate({height:0},{duration:800,easing:"easeOutExpo"});
			})
			$('#newProducts').slider({separate:8});
			$('#newMegabassist').slider({separate:5});
			$('#newOnigiri').slider({separate:5});
			$('#newLink').slider({separate:5});
			/*
			//シャッターオープン
			$('.shutter').animate({margin:0},{duration:2000,easing:"linear",
				complete:function(){
					$(this).animate({height:0},{duration:500,easing:"easeInOutExpo"});
				}
			});
			*/
			//#blogAllListOpen
			$('#blogAllList,#swf3').hover(
				function(){
					$(this).children('div').queue("fx",[]).animate({top:0},{duration:500,easing:"easeOutExpo"});
				},
				function(){
					$(this).children('div').queue("fx",[]).animate({top:-433},{duration:500,easing:"easeOutExpo"});
				}
			);
		};// End if	
	/*------------------------------------------
	 *	製品情報トップ
	 */	if($('#proIndex').length){

			$('.tabSlider').slider({isCurrentImage:true,nextClass:'#none',backClass:'#none',naviClass:'.tabNav'});
			$('.brandLineup').each(function(){
				$(this).slider({separate:4,isCurrentImage:true});
			});
			
		};// End if	
	/*------------------------------------------
	 *	製品情報カテゴリインデックス
	 */	if($('#proBrand').length){
		 
			//製品情報の製品名(flash使用)
			$('h1#pageTitle').each(function(){
				var names;
				var thisHeight = $(this).height();
					//aタグあるかないか
				($(this).find('a')) ? names = $(this).find('a').text().split("|") : names = $(this).text().split("/");		
				var flashvars={
					leftMargin: 1,
					size: 30,
					title2: names[0],
					title: names[1]
				};
				$('#relatedSearchInput').attr('value',names[1]);
				$(this).html('').append('<div id="pageTitleSwf"></div>');
				swfobject.embedSWF("/shared/swf/productTitle.swf", "pageTitleSwf","700", thisHeight, "9","", flashvars, {wmode:"transparent"}); 
			});
			
			if($('body.reel').length||$('body.line').length){
				$('#index').remove();
			}

		};// End if		
	/*------------------------------------------
	 *	製品情報インデックス
	 */	if($('#proCategory').length){
		 
			$('.brandLineup').slider({separate:4,isCurrentImage:true});

		};// End if
	/*------------------------------------------
	 *	製品情報個別
	 */	if($('#proIndividual').length){
			
		 	var thisHeight
			//製品情報の製品名(flash使用)
			$('#pageTitle').each(function(){
				var names,tmp;
				thisHeight = $(this).height()*1.25;
				tmp = '<div style="height:' + thisHeight + 'px"></div>'
				$(this).wrap(tmp);
				//aタグあるかないか
				($(this).find('a')) ? names = $(this).find('a').text().split("|") : names = $(this).text().split("/");		
				
				var flashvars={
					leftMargin: 1,
					letterSpacing:2,
					size: 38,
					width: 340,
					leading:-7,
					y:0,
					title2: names[0],
					title: names[1]
				};
				$('#relatedSearchInput').attr('value',names[1]);
				swfobject.embedSWF("/shared/swf/productTitle.swf", "pageTitle","340", thisHeight, "9","", flashvars, {wmode:"transparent"}); 
			});
			
			//製品情報のzoomアイコン追加
			$('#productVisual a').each(function(){
				$(this).after('<img src="/shared/img/icon/ico_zoom.gif" class="icon"/>');
			});
			
	 		//製品情報のカラーバリエーションzoomアイコン追加
			$('#colorVariation li a').each(function(){
				$(this).append('<img src="/shared/img/icon/ico_zoom.gif" class="icon"/>');
			});
			
			//本文画像のfloatクリア判定
	 		var fClearMargin = $('div.right','#main').height()-$('#headCopy').height()-thisHeight;
			$('img','#entryBody').each(function(){
				if($(this).width()>340){// && fClearMargin>0){
					$('#entryBody').css(
						{
							marginTop: fClearMargin,
							width: 640
						}
					);
					
					return false;
				}
			});
	 		
			//製品情報の偶数・奇数節設定
			//$('.detail','#main').filter(':odd').addClass('even').end().filter(':even').addClass('odd');
			
			//lineup
			/*
	 		if(isWebKit){
				$('#lineup>ul>li>a>img').load(function(num){
					if(num==$(this).length-1){
						vCenter('#lineup>ul>li>a');
					}
				});
			}
	 		*/

		};// End if
	/*------------------------------------------
	 *	ブログトップ
	 */	if($('#bloIndex').length){
		 
			$('ul.col3>li.news dd','#main').groupLink();

		};// End if
	/*------------------------------------------
	 *	メガバシストトップ
	 */	if($('#megIndex').length){
		 
			$('.tabSlider').slider({isCurrentImage:true,nextClass:'#none',backClass:'#none',naviClass:'.tabNav'});

		};// End if
	/*------------------------------------------
	 *	メガバシスト記事
	 */	if($('#megIndividual').length){
			$('div.entry .cut','#main').each(function(){
				if($(this).find('img').width()>=640){
					$(this).addClass('cutN');
				}
			});
		 	//本文のlightpop
			$('div.entry img','#main').each(function(){
				if(!$(this).parent('a').length){
					$(this).wrap('<a href="'+$(this).attr('src')+'" />');
					var imagePath = '/shared/img/lightpop/';
					$(this).parent('a').lightpop(false,false,false,imagePath);
				}
			});

		};// End if
	/*------------------------------------------
	 *	ダイビングチャート
	 */	if($('#arcChart').length){
		 
			if (swfobject.hasFlashPlayerVersion("10")) {
				$('.contents,.pager,.navigation','#chartView').remove();
		 		$('#chartView').append('<div id="swf"></div>').show();
				var fn = function() {
					var att = { data:"main.swf", width:"780", height:"700" };
						var par = {flashvars:"ID="+location.search.substr(1,1), wmode:"transparent"};
					var id = "swf";
					swfobject.createSWF(att, par, id);
				};
				swfobject.addDomLoadEvent(fn);
			}else {
				$('#chartView').show();
		 		$('#chartView').slider({isCurrentImage:true});
			}

		};// End if
	/*------------------------------------------
	 *	検索
	 */	if($('.search').length){

	 	$('#searchOption').slider({nextClass:'#none',backClass:'#none'})
				.find('.contents a').click(function(){
					val = '"'+$(this).text()+'" '+$('#relatedSearchInput').val();
					$('#relatedSearchInput').val(val);
					return false;
				});
			
		};// End if	
	/*------------------------------------------
	 *	下階層全体
	 */	if(!$('body.products').length){
		 	var IE='\v'=='v';
			if(!IE&&!$('body.megabassist').length){
				$('#pageTitle').append('<img src="'+absPath+'/shared/img/background/bg_overlay_gra.png">');
			}
		};// End if
	/*------------------------------------------
	 *	Index下階層全体
	 */	if($('body.index').length){
			$('ul.col3>li','#main').not('.news').groupLink();
		};// End if	
	 /*------------------------------------------
	 *	
	 */
	});
})();

