//-----------------------------------------------------------------
//	Object：MM
//-----------------------------------------------------------------
MM = {
	//-----------------------------------------------------------------
	//	Object：MM.tab >> タブコントロール
	//-----------------------------------------------------------------
	tab : {
		//-----------------------------------------------------------------
		//	関　数：init
		//	概　要：初期化
		//	戻り値：なし
		//-----------------------------------------------------------------
		init : function(){
			var ctrl = Xa.getObject('rankCol');
			ctrl = ctrl.getElementsByTagName('ul')[0];
			
			
			var uta  = Xa.getObject('utaTab');
			var shop = Xa.getObject('shopTab');
			var call = Xa.getObject('callTab');

			var dp = MM.cookie.get();
			if( dp ){
				var idx = dp['MMRankIdx'];
				shop.style.display = "none";
				call.style.display = "none";
				uta.style.display  = "none";
				if( idx == 0 ){
					uta.style.display  = "block";
					ctrl.style.backgroundPosition = "0 -60px";
				}else if( idx == 1 ){
					shop.style.display = "block";
					ctrl.style.backgroundPosition = "0 -30px";
				}else if( idx == 2 ){
					call.style.display = "block";
					ctrl.style.backgroundPosition = "0 0";
				}else{
					uta.style.display  = "block";
					ctrl.style.backgroundPosition = "0 -60px";
				}
			}else{
				shop.style.display = "none";
				call.style.display = "none";
				uta.style.display  = "block";
				ctrl.style.backgroundPosition = "0 -60px";
			}
			
			ctrl = ctrl.getElementsByTagName('li');
			for( var i=0; i<ctrl.length; i++ ){
				var c = ctrl[i];
				
				c.onclick = function(){
					var ctrl = Xa.getObject('rankCol');
					ctrl = ctrl.getElementsByTagName('ul')[0];
					
					var uta  = Xa.getObject('utaTab');
					var shop = Xa.getObject('shopTab');
					var call = Xa.getObject('callTab');

					shop.style.display = "none";
					call.style.display = "none";
					uta.style.display  = "none";

					if( this.className == 'uta' ){
						ctrl.style.backgroundPosition = "0 -60px";
						uta.style.display  = "block";
						var dp = 'MMRankIdx=0';
					}else if( this.className == 'shop' ){
						ctrl.style.backgroundPosition = "0 -30px";
						shop.style.display = "block";
						var dp = 'MMRankIdx=1';
					}else{
						ctrl.style.backgroundPosition = "0 0";
						call.style.display = "block";
						var dp = 'MMRankIdx=2';
					}
					MM.cookie.set(dp);
					return false;
				}
				
				var a = c.getElementsByTagName('a')[0];
				a.onfocus = function(){
					this.blur();
				}
			}
		}
	},
	//-----------------------------------------------------------------
	//	Object：MM.slider >> スライダーコントロール
	//-----------------------------------------------------------------
	slider : {
		idx  : 0,
		cur  : null,
		cidx : -1,
		x    : null,
		y    : null,
		page : 0,
		roll : 0,
		move : false,
		//-----------------------------------------------------------------
		//	関　数：init
		//	概　要：初期化
		//	戻り値：なし
		//-----------------------------------------------------------------
		init : function(){
			this._initSideCtrl();
			this._initFootCtrl();
			this._initViewCtrl();
		},
		//-----------------------------------------------------------------
		//	関　数：_initSideCtrl
		//	概　要：フッターコントロールの初期化
		//	戻り値：なし
		//-----------------------------------------------------------------
		_initSideCtrl : function() {
			var ctrl = Xa.getObject('rightCtrlCol');
			ctrl = ctrl.getElementsByTagName('a')[0];
			
			ctrl.onclick = function(){
				if( MM.slider.move ) return false;
				new Effect.MoveBy("viewColWrap", 
					0, 
//					-1452, { 
					-726, { 
					duration:1, 
					fps:60, 
					delay:0, 
					beforeStartInternal: function(effect) { 
						var ctrl = Xa.getObject('specialColFoot');
						ctrl = ctrl.getElementsByTagName('ul')[0];
						ctrl = ctrl.getElementsByTagName('li');

						var btnf = ctrl[0].getElementsByTagName('a')[0];
						var btne = ctrl[1].getElementsByTagName('a')[0];

						if( MM.slider.page == 2 ){
							MM.slider.page = 0;
							btnf.style.backgroundPosition = "0 -23px";
							btne.style.backgroundPosition = "0 0";
							if( MM.slider.roll == 1 ){
								var ctrl = Xa.getObject('viewColWrap');
								ctrl.style.left = "0";
							}
						}else{
							MM.slider.page = 2;
							btnf.style.backgroundPosition = "0 0";
							btne.style.backgroundPosition = "0 -23px";
						}

						MM.slider.roll = 2;
						MM.slider.move = true;
					}, 
					afterFinishInternal: function(effect) { 
						if( MM.slider.page == 2 ){
							var ctrl = Xa.getObject('viewColWrap');
							ctrl.style.left = "0";
						}else{
							var ctrl = Xa.getObject('viewColWrap');
							//ctrl.style.left = "-1452px";
							ctrl.style.left = "-726px";
						}
						MM.slider.move = false;
					} 
					
				});
				return false;
			}
			
			ctrl = Xa.getObject('leftCtrlCol');
			ctrl = ctrl.getElementsByTagName('a')[0];

			ctrl.onclick = function(){
				if( MM.slider.move ) return false;
				new Effect.MoveBy("viewColWrap", 
					0, 
//					1452, { 
					726, { 
					duration:1, 
					fps:60, 
					delay:0, 
					beforeStartInternal: function(effect) { 
						var ctrl = Xa.getObject('specialColFoot');
						ctrl = ctrl.getElementsByTagName('ul')[0];
						ctrl = ctrl.getElementsByTagName('li');

						var btnf = ctrl[0].getElementsByTagName('a')[0];
						var btne = ctrl[1].getElementsByTagName('a')[0];

						if( MM.slider.page == 2 ){
							MM.slider.page = 0;
							btnf.style.backgroundPosition = "0 -23px";
							btne.style.backgroundPosition = "0 0";
							var ctrl = Xa.getObject('viewColWrap');
//							ctrl.style.left = "-2904px";
							ctrl.style.left = "-1452px";
						}else{
							MM.slider.page = 2;
							btnf.style.backgroundPosition = "0 0";
							btne.style.backgroundPosition = "0 -23px";
						}
						MM.slider.roll = 1;
						MM.slider.move = true;
					}, 
					afterFinishInternal: function(effect) { 
						if( MM.slider.page == 2 ){
							var ctrl = Xa.getObject('viewColWrap');
							ctrl.style.left = "0";
						}else{
							var ctrl = Xa.getObject('viewColWrap');
							//ctrl.style.left = "-1452px";
							ctrl.style.left = "-726px";
						}
						MM.slider.move = false;
					} 
				});
				return false;
			}
			
		},
		//-----------------------------------------------------------------
		//	関　数：_initFootCtrl
		//	概　要：フッターコントロールの初期化
		//	戻り値：なし
		//-----------------------------------------------------------------
		_initFootCtrl : function() {
			var ctrl = Xa.getObject('specialColFoot');
			ctrl = ctrl.getElementsByTagName('ul')[0];
			ctrl = ctrl.getElementsByTagName('li');
			
			for( var i=0; i<ctrl.length; i++ ){
				var c = ctrl[i];
				var a = c.getElementsByTagName('a')[0];
				if( i == 0 ){
					a.style.backgroundPosition = "0 -23px";
				}else{
					a.style.backgroundPosition = "0 0";
				}
				
				a.idx = i;
				
				a.onmouseover = function(){
					var s = MM.slider;
					if( s.idx != this.idx ){
						this.style.backgroundPosition = "0 -23px";
					}
				}
				
				a.onmouseout = function(){
					var s = MM.slider;
					if( s.idx != this.idx ){
						this.style.backgroundPosition = "0 0";
					}
				}
				
				a.onfocus = function(){
					this.blur();
				}
				
				a.onclick = function(){
					var s = MM.slider;
					if( s.move ) return false;
					
					s.idx = this.idx;
					
					var ctrl = Xa.getObject('specialColFoot');
					ctrl = ctrl.getElementsByTagName('ul')[0];
					ctrl = ctrl.getElementsByTagName('li');
					
					for( var i=0; i<ctrl.length; i++ ){
						var c = ctrl[i];
						var a = c.getElementsByTagName('a')[0];

						if( i == this.idx ){
							a.style.backgroundPosition = "0 -23px";
						}else{
							a.style.backgroundPosition = "0 0";
						}
					}
					if( this.idx == 0 ){
						if ( MM.slider.page == 2 && !MM.slider.move ){
							new Effect.MoveBy("viewColWrap", 
								0, 
//								1452, { 
								726, { 
								duration:1, 
								fps:60, 
								delay:0,
								beforeStartInternal: function(effect) { 
									var ctrl = Xa.getObject('viewColWrap');
//									ctrl.style.left = "-2904px";
									ctrl.style.left = "-1452px";
									MM.slider.page = 0;
									MM.slider.move = true;
								},
								afterFinishInternal: function(effect) { 
									var ctrl = Xa.getObject('viewColWrap');
//									ctrl.style.left = "-1452px";
									ctrl.style.left = "-726px";
									MM.slider.move = false;
								}
							}); 
							
						}
					}else{
						if ( MM.slider.page == 0 && !MM.slider.move ){
							new Effect.MoveBy("viewColWrap", 
								0, 
//								-1452, { 
								-726, { 
								duration:1, 
								fps:60, 
								delay:0,
								beforeStartInternal: function(effect) { 
									var ctrl = Xa.getObject('viewColWrap');
//									ctrl.style.left = "-1452px";
									ctrl.style.left = "-726px";
									MM.slider.page = 2;
									MM.slider.move = true;
								},
								afterFinishInternal: function(effect) { 
									var ctrl = Xa.getObject('viewColWrap');
									ctrl.style.left = "0";
									MM.slider.move = false;
								} 
							}); 
							
						}
					}
					
					
					
					return false;
				}
			}
		},
		//-----------------------------------------------------------------
		//	関　数：_initViewCtrl
		//	概　要：ビューコントロールの初期化
		//	戻り値：なし
		//-----------------------------------------------------------------
		_initViewCtrl : function() {
			var ctrl = Xa.getObject('viewCol');
			
			ctrl.onmouseout = function(){
				var s  = MM.slider;
				var r  = s.cur;
				var rs = r.style;
				rs.display = "none";
			}
			
			ctrl = ctrl.getElementsByTagName('div');
			
			this.cur = ctrl[1];
			
			as = this.cur.getElementsByTagName('a');
			for( i=0; i<as.length; i++ ){
				a = as[i];
				a.onfocus = function(){
					this.blur();
				}
			}
			
			for( var i = 2; i < ctrl.length; i++ ){
				var c = ctrl[i];
				var a = ctrl[i].getElementsByTagName('a')[0];
				if( a ){
					c.href=a.href;
				}
				c.idx = i - 2;

				if( c.idx == 5 ){
					continue;
				}
				
				if( c.idx > 5 ){
					c.idx += 4;
				} 

				c.onmouseover = function() {
					var s  = MM.slider;
					var r  = s.cur;
					var rs = r.style;
					if( MM.slider.page == 2 ){
						var l  = 145 * this.idx;
					}else{
//						var l  = 2 + 145 * this.idx;
						var l  = 1 + 145 * (this.idx-5);
					}
					
					as = r.getElementsByTagName('a');
					for( i=0; i<as.length; i++ ){
						a = as[i];
						a.style.display='none';
					}
					
					idx = this.idx;
					if( idx > 5 ) idx -= 5;
					as[idx].style.display='block';
					
					rs.display = "block"
					rs.left = l + "px";
					r.cidx = s.cidx = this.idx;
				}
	
				c.onmouseout = function(e) {
					e = e ? e : event;
					if ( e.stopPropagation ){
						e.stopPropagation();
					} else if ( typeof(e.cancelBubble) !== 'undefined' ){
						e.cancelBubble = true;
					}

				}
				

			}
			
			ctrl = Xa.getObject('viewColWrap');
			cols = ctrl.getElementsByTagName('div');

			var len = cols.length;
			var c  = cols[6];
			var cc = c.cloneNode(true);
			ctrl.appendChild(cc);

			for(var i=1; i < 6; i++ ){
				var c  = cols[i];
				var cc = c.cloneNode(true);
				ctrl.appendChild(cc);
			}
			
			
			new Effect.Opacity("viewColWrap", {
				from:0.0, 
				to:1.0,  
				duration:3, 
				fps:60, 
				delay:0,
				afterSetupInternal: function(effect) { 
					var ctrl = Xa.getObject('viewColWrap');
//					ctrl.style.left = "-1452px";
					ctrl.style.left = "-726px";

				}
			}); 

			
		}
		
	},
	//-----------------------------------------------------------------
	//	Object：MM.dlg >> ダイアログ関連
	//-----------------------------------------------------------------
	dlg : {
		self : null,
		//-----------------------------------------------------------------
		//	関　数：init
		//	概　要：初期化
		//	戻り値：なし
		//-----------------------------------------------------------------
		init : function(){
			ua = navigator.userAgent;
			if( ua.indexOf("Mac") != -1 ){
				var isMSIE = /*@cc_on!@*/false;
				if( isMSIE ){
					w  = document.all.wrapper;
					as = w.getElementsByTagName("a");
					for(i=0; i<as.length; i++ ){
						if( as[i].className == 'mburl' ){
							as[i].target="_blank";
						}
					}
				}else{
					$$('a.mburl').each(function(link){
						new Control.Modal(link,{
							opacity:0.6,
							width:500,
							height:500
						});
					});
				}
				
			}else{
				$$('a.mburl').each(function(link){
					new Control.Modal(link,{
						opacity:0.6,
						width:500,
						height:500
					});
				});
/*
				$$('div.col').each(function(link){
					new Control.Modal(link,{
						opacity:0.6,
						width:500,
						height:500
					});
				});
*/
			}
			this.self = "http://" + location.hostname + "/index.php";
		},
		send : function(f){
			new Ajax.Request(
//				'http://mu-motest.avexnet.jp/index.php',
				this.self,
				{	method : 'post',
					postBody : Form.serialize(f),
					onComplete : function(req){
						$('dialogMsg').style.display = 'block';
						var text = req.responseText;
						if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
							var esc = escape( text );
							if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
								text = decodeURIComponent( esc );
							}
							$('dialogMsg').innerHTML = text;
						}else{
							$('dialogMsg').innerHTML = text;
						}
					}
				}
			);
		}
	},
	//-----------------------------------------------------------------
	//	Object：MM.cookie >> クッキー処理
	//-----------------------------------------------------------------
	cookie : {
		name:'mu-moGT',
		//-----------------------------------------------------------------
		//	関　数：init
		//	概　要：初期化
		//	戻り値：なし
		//-----------------------------------------------------------------
		init : function(){
		
		},
		//-----------------------------------------------------------------
		//	関　数：_enable
		//	概　要：cookieの使用が可能か調査
		//	戻り値：true/false
		//-----------------------------------------------------------------
		_enabled : function(){
			return window.navigator.cookieEnabled;
		},
		//-----------------------------------------------------------------
		//	関　数：set
		//	概　要：cookieに値を設定
		//	戻り値：なし
		//-----------------------------------------------------------------
		set:function(dp,d){
			if( d=='' || d==null ){
				document.cookie = this.name+'='+escape(dp)+';';
			}else{
				var day = new Date();
				day.setTime(day.getTime()+(d*1000*60*60*24));
				document.cookie = this.name+'='+escape(dp)+';expires='+day.toGMTString();
			}
		},
		//-----------------------------------------------------------------
		//	関　数：get
		//	概　要：cookieから値を取得
		//	戻り値：取得した値
		//-----------------------------------------------------------------
		get:function(){
			var arr = document.cookie.split(' ');
			var len = arr.length;
			for( var i=0; i<len; i++ ){
				var e = arr[i];
				if( this.name==e.substr(0,this.name.length) ){
					var tmp =e.split('=');
					var t = unescape(tmp[1]);
					if((t.length-1) == t.lastIndexOf(';')){
						t = t.slice(0,t.length-1);
					}
					var c = t.split('&');
					var n = c.length;
					var ret  = new Array();
					var tret = new Array();
					for( var j=0;j<n;j++ ){
						tret = c[j].split('=');
						ret[tret[0]]=tret[1];
					}
					return ret;
				}
			}
			return null;
		}
	},
	win : {
		open : function(theURI){
			PopUpWin=window.open(theURI,'theWin','scrollbars=1,width=750,height=770,resizable=1,directories=0,toolbar=0,status=1,location=0');
			PopUpWin.focus();
		
		}
	}
};

window.onload = function() {
	MM.cookie.init();
	MM.tab.init();
	MM.slider.init();
	MM.dlg.init();
}

