/**---------------------------------
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
 * marna.js
 * 
 * ...
 * author	: takaaki koyama
 *
 * @use jQuery later
 ---------------------------------*/
 
var marna = null;
(function($,undefined){
	
	if(window['marna'] != null) return;
	
	var def_title = document.title;
	var marna = {
		util : {
			useragents_regexp : (function(){return new RegExp([
				'iPhone',         // Apple iPhone
				'iPod',           // Apple iPod touch
				'iPad',           // Apple iPad
				'Android',        // 1.5+ Android
				'dream',          // Pre 1.5 Android
				'CUPCAKE',        // 1.5+ Android
				'blackberry9500', // Storm
				'blackberry9530', // Storm
				'blackberry9520', // Storm v2
				'blackberry9550', // Storm v2
				'blackberry9800', // Torch
				'webOS',          // Palm Pre Experimental
				'incognito',      // Other iPhone browser
				'webmate'         // Other iPhone browser
			].join('|'),'i'); })(),
			is_mobile : function() {
				return this.useragents_regexp.test(navigator.userAgent);
			},
			is_mobile_resizer : function(){
				if(navigator.userAgent.match(/iPad|iPhone|iPod/i)){
					var os_version = navigator.userAgent.match(/OS (\d)/i);
					if(os_version != null && os_version.length == 2 && os_version[1] < 5){
						return true;
					}else{
						return false;
					}
				}
				if(this.is_mobile()){
					return true;
				}
				return false;
			},
			is_flash_enabled : function(){
				if(this.is_mobile()) return false;
				var playerVersion = swfobject.getFlashPlayerVersion();
				if(playerVersion.major > 9){
					return true;
				}
				
				return false;
			}
		},
		fl : {
			SWF_NAME : "external_content",
			enabled : true,
			getSWF : function(name){
				if(this.enabled){
					if(navigator.appName.indexOf("Microsoft") != -1) {
						return window[name];
					}else {
						return document[name];
					}
				}else{
					return this.noflash
				}
			},
			ready : function(){
				$(window).trigger('startup');
			},
			isStarted : false,
			start : function(state){
				//console.log("start : "+state);
				this.getSWF(this.SWF_NAME).fl_start(state);
				this.isStarted = true;
			},
			stateChange : function(state){
				if(this.isStarted){
					this.getSWF(this.SWF_NAME).fl_stateChange(state);
				}else{
					this.start(state);
				}
			},
			internalLink : function(hash){
				if((window.location.pathname.split("/").length == 2)){
					window.location.hash = hash;
				}else{
					var loc = (hash.substr(hash.length -1) == "/") ? hash : hash + ".html";
					window.location = loc.replace("#","");
				}
			}
		},
		
		scroller : {
			enabled : true,
			isSetuped : false,
			template : function(){
				return [
					'<div id="scrollbar">',
					'	<div id="scroll_handle">',
					'		<div><div></div></div>',
					'	</div>',
					'</div>'
				].join('');
			},
			setup : function(){
				this.enabled = !marna.util.is_mobile();
				if(!this.enabled) return;
				
				var $contents = $('#contents');
				if($contents.length == 0) return;
				$contents.find('#content').addClass('scroll_target');
				$contents.append($(this.template()));
				
				//console.log('scroller.setup');
				
				$.uif.resize.add(this.resize);
				this.resize();
				
				if(marna.scroller.parcent < 1){
					$('#scrollbar').on('click',this.mouseClick);
					$('#scroll_handle').on('mousedown',this.mouseDown);
					$(document).on('mousewheel', this.mouseWheel);
				}
				
				marna.scroller.isSetuped = true;
				
			},
			dispose : function(){
				if(!marna.scroller.enabled) return;
				
				clearInterval(marna.scroller._posTimerID);
				marna.scroller._isRunning = false;
				
				$('#scrollbar').off('click',this.mouseClick);
				$('#scroll_handle').off('mousedown',this.mouseDown);
				$(document).off({
					'mousewheel' : this.mouseWheel,
					'mousemove' : this.mouseMove,
					'mouseup' : this.mouseUp
				});
				$.uif.resize.remove(this.resize);
				marna.scroller.isSetuped = false;
			},
			
			parcent : 0,
			mouseY : 0,
			
			posY : 0,
			_posY : 0,
			_posTimerID : 0,
			_isRunning : false,
			
			maxHeight : 0,
			maxY : 0,
			
			wheelSpeed : 40,
			
			resize : function(){
				if(!marna.scroller.enabled) return;
				
				marna.scroller.maxHeight = $('#contents').height();
				var p = marna.scroller.maxHeight / $('#in_content').height();
				if(p >= 1){
					p = 1;
				}
				
				var height = marna.scroller.maxHeight * p;
				marna.scroller.maxY = marna.scroller.maxHeight - height;
				
				
				$('#scroll_handle div')
					.stop(true,false)
					.animate({
						'height' : height
						},{
							duration : 500
						});
				
				if(p == 1 && marna.scroller.parcent < 1){
					//console.log('fadeOut');
					$('#scroll_handle').fadeOut(200);
					
					$('#scrollbar').off('click',marna.scroller.mouseClick);
					$('#scroll_handle').off('mousedown',marna.scroller.mouseDown);
					$(document).off('mousewheel', marna.scroller.mouseWheel);
					
				
				}else if(marna.scroller.parcent == 1 && p < 1){
					//console.log('fadeIn');
					$('#scroll_handle').fadeIn(200);
					
					$('#scrollbar').on('click',marna.scroller.mouseClick);
					$('#scroll_handle').on('mousedown',marna.scroller.mouseDown);
					$(document).on('mousewheel', marna.scroller.mouseWheel);
				}
				
				marna.scroller.parcent = p;
				marna.scroller.scrollTo(marna.scroller.posY, 0.2);
			},
			mouseClick : function(e){
				if(e.target == e.currentTarget){
					if(e.pageY > marna.scroller.posY + marna.scroller.height){
						marna.scroller.scrollTo(e.pageY - marna.scroller.height,0.5);
					}else{
						marna.scroller.scrollTo(e.pageY,0.5);
					}
				}
				return false;
			},
			mouseDown : function(e){
				marna.scroller.mouseY = e.pageY;
				$('#scroll_handle').off('mousedown',marna.scroller.mouseDown);
				$(document).on({
					'mousemove' : marna.scroller.mouseMove,
					'mouseup' : marna.scroller.mouseUp
				});
				return false;
			},
			
			mouseUp : function(e){
				$('#scroll_handle').on('mousedown',marna.scroller.mouseDown);
				$(document).off({
					'mousemove' : marna.scroller.mouseMove,
					'mouseup' : marna.scroller.mouseUp
				});
				return false;
			},
			
			mouseMove : function(e){
				var ty = marna.scroller.posY + (e.pageY - marna.scroller.mouseY);
				marna.scroller._scrollTo(ty);
				marna.scroller.mouseY = e.pageY;
				if(!marna.scroller._isRunning){
					marna.scroller.update(1);
				}
				return false;
			},
			
			mouseWheel : function(e,delta){
				marna.scroller.scrollTo(marna.scroller.posY - delta * marna.scroller.wheelSpeed, 0.2);
			},
			
			update : function(speed){
				if(marna.scroller._isRunning) return;
				
				clearInterval(marna.scroller._posTimerID);
				marna.scroller._isRunning = true;
				marna.scroller._posTimerID = setInterval(function(){
					marna.scroller._posY += (marna.scroller.posY - marna.scroller._posY) * speed;
					
					if(Math.abs(marna.scroller.posY - marna.scroller._posY) < 0.1){
						clearInterval(marna.scroller._posTimerID);
						marna.scroller._isRunning = false;
					}
					$('#scroll_handle').css('top', marna.scroller._posY);
					
					var top = (marna.scroller._posY / marna.scroller.maxY)
					
					$('#in_content').css('top', (marna.scroller._posY / marna.scroller.parcent)*-1);
				},1000/30)
				
			},
			
			_scrollTo : function(to){
				marna.scroller.posY = to;
				if(marna.scroller.posY <= 0){
					marna.scroller.posY = 0;
				}else if(marna.scroller.posY >= marna.scroller.maxY){
					marna.scroller.posY = marna.scroller.maxY;
				}
			},
			
			scrollTo : function(to,speed){
				if(marna.scroller.enabled){
					marna.scroller._scrollTo(to);
					marna.scroller.update(speed);
				}else{
					
				}
			},
			
			anchor : function(target){
				target = $(target);
				if(target.length){
					if(marna.scroller.enabled){
						marna.scroller.scrollTo(target.position().top * marna.scroller.parcent, 0.1);
					}else{
					}
				}
			},
			
			reset : function(){
				if(marna.scroller.enabled){
					marna.scroller.resize();
					marna.scroller.scrollTo(0,1);
				}
			}
		},
		
		startup : function(){
			//console.log("startup -> marna.isTop : " + marna.isTop);
			if(marna.isEnglishTop){
				this.fl.start(0);
				return;
			}
			if(!marna.isTop){
				this.fl.start(1);
				return;
			}
			
			$(window).hashchange(function(){
				//console.log(arguments);
				var hash = location.hash.replace(/^#/,'');
				if(hash == marna.prevHash) return;
				//console.log(hash);
				
				if(hash == "" || hash == "/"){
					// to top;
					
					marna.animate.toTop(marna.isSetuped? 1000 : 0);
					
					document.title = def_title;
					if(marna.isSetuped){
						if(pageTracker){
							try {
								pageTracker._trackPageview("/");
							}catch(err) {}
						}
					}
					
					marna.isTop = true;
					marna.isSetuped = true;
					
					
					//console.log("marna.isSetuped : " + marna.isSetuped);
					
				}else{
					if(marna.isTop){
						
						marna.ajax(hash,function(html){
							document.title = html.match(/<title>(.*)<\/title>/)[1];
							
							var $contents = $('<div>');
							$contents.get(0).innerHTML = html;
							$contents = $contents.find('#contents');
							
							if($('#contents').length == 0){
								$("#header").after($contents.css('margin-left',$(window).width()));
								marna.animate.toSub(marna.isSetuped? 1000 : 0);
								//console.log(marna.isSetuped? 1000 : 0);
								marna.isTop = false;
								
								marna.scroller.setup();
							}
							
							marna.isSetuped = true;
						});
						
					}else{
						
						var hash_split_prev = marna.prevHash.split('/');
						hash_split_prev.shift();
						var hash_split = hash.split('/');
						hash_split.shift();
						
						if(hash_split_prev[0] != hash_split[0]){
							
							
							marna.ajax(hash,function(html){
								document.title = html.match(/<title>(.*)<\/title>/)[1];
								
								var $in_content = $('<div>');
								$in_content.get(0).innerHTML = html;
								$in_content = $in_content.find('#in_content').width(0).fadeTo(0,0);
								
								$("#in_content").animate({
									'width' : '0px'
								},{
									duration : 1000,
									easing : 'easeInOutQuint',
									complete : function(){
										$(this).remove();
										setTimeout(function(){
											$("#content").prepend($in_content);
											$("#in_content").fadeTo(0,1);		
											marna.scroller.reset();
											marna.animate.chengeSub(1000);
										},0);
									}
								});
								
								marna.isSetuped = true;
							});
							
							marna.scroller.scrollTo(0,0.3);
							
						}else{
							
							marna.ajax(hash,function(html){
								document.title = html.match(/<title>(.*)<\/title>/)[1];
								
								var $in_article = $('<div>');
								$in_article.get(0).innerHTML = html;
								$in_path = $in_article.find('#path > ul');
								$in_article = $in_article.find('#article > div').fadeTo(0,0);
								
								$("#article").height($("#article > div").height());
								$("#article > div").fadeTo(1000,0,'easeInOutQuint',function(){
									$(this).remove();
									$("#path").html($in_path);
									$("#article").prepend($in_article);
									marna.animate.chengeSubSub(1000);
									marna.scroller.reset();
								});
								
								marna.isSetuped = true;
							});
							
							marna.scroller.scrollTo(0,0.3);
							
						}
					}
				}
				
				marna.prevHash = hash;
				marna.setNavigation(hash)
				
				
			}).hashchange();
		},
		setNavigation : function(hash){
			//console.log('setNavigation : '+hash);
			if(hash == "" || hash == "/"){
				$("#global_navi a.current, #local_navi a .current, #guide_navi .current")
					.removeClass('current').trigger('mouseout');
				$("#btn_home:not(.current)").addClass('current');
				$("#logo a").attr('href','/company/history').removeClass('current');
			}else{
				$("#logo a").attr('href','/').removeClass('current');
				var hash_split = hash.split('/');
				hash_split.shift();
				var d = hash_split[0], p = hash_split.length > 1? hash_split[1] : null;
				if(hash_split.length == 1 || p == "" || p == "index"){
					//console.log(hash_split);
					$('#global_navi a.current:not(a[href="/'+d+'/"])')
						.removeClass('current').trigger('mouseout')
					$('#global_navi a[href="/'+d+'/"]:not(.current)')
						.trigger('mouseover').addClass('current');
					
					$('#guide_navi a.current:not(a[href="/'+d+'/"])')
						.removeClass('current')
					$('#guide_navi a[href="/'+d+'/"]:not(.current)')
						.addClass('current');
					
					$('a:not(a[href="/'+d+'/"]) img.current')
						.removeClass('current').trigger('mouseout');
					$('a[href="/'+d+'/"] img:not(.current)').not('#global_navi a img')
						.trigger('mouseover').addClass('current');
						
					$('#local_navi ul ul a').removeClass('current')
						
				}else if(hash_split.length > 1){
					
					$('#global_navi a.current:not(a[href="/'+d+'/"])')
						.removeClass('current').trigger('mouseout')
					$('#global_navi a[href="/'+d+'/"]:not(.current)')
						.trigger('mouseover').addClass('current');
					
					$('#guide_navi a.current:not(a[href="/'+d+'/"])')
						.removeClass('current')
					$('#guide_navi a[href="/'+d+'/"]:not(.current)')
						.addClass('current');
					
					var url = '/' + d + '/' + p;
					if(hash.substr(-1) == '/' || hash_split.length > 2){
						url += '/';
					}else{
						url += '.html';
					}
					
					$('a:not(a[href="'+url+'"]) img.current')
						.removeClass('current').trigger('mouseout');
					$('a[href="'+url+'"] img:not(.current)').not('#global_navi a img')
						.trigger('mouseover').addClass('current');
					
					$('#local_navi > ul > li:has(ul)').trigger('mouseout');
					$('#local_navi ul ul a').removeClass('current')
					if(hash_split.length > 2){
						$('#local_navi li ul a[href="'+hash+'.html"]:not(.current)')
							.addClass('current');
					}
				}
				
				$("#btn_home.current").removeClass('current');
			}
		},
		
		ajax : function(hash, callback){
			//console.log(hash.substr(hash.length -1));
			var trackURL = hash;
			if(hash.substr(hash.length -1) == '/'){
				hash += 'index.html';
			}else if(hash.substr(hash.length -5) != '.html'){
				hash += '.html';
				trackURL += '.html';
			}
			//console.log('load : '+trackURL);
			
			$.ajax({
				url : hash,
				cache: false,
				dataType : 'html',
				success : function(res){
					callback(res);
					if(pageTracker){
						try {
							//console.log('_trackPageview : '+trackURL);
							pageTracker._trackPageview(trackURL);
						}catch(err) {}
					}
				}
			});
		},
		
		animate : {
			toTop : function(time, callback){
				marna.fl.stateChange(0);
				var sw = $(window).width();
				$("#header").css({'left':'','right':sw-220}).animate({
						'right' : '-1'
					},{
						duration : time,
						easing : 'easeInOutQuint',
						complete : function(){
							$.uif.setup('#contents');
							if(callback != null){
								callback.call(marna)
							}
						}
					});
				
				$("#footer").delay(time*0.5).animate({
						'margin-top' : '-35px',
						'height' : '35px'
					},{
						duration : time, 
						easing : 'easeInOutQuint'
					});
				
				$("#contents").animate({
						'margin-left' : sw
					},{
						duration : time,
						easing : 'easeInOutQuint',
						complete : function(){
							marna.scroller.dispose();
							$(this).remove();
						}
					});
				$("#navi_addon ul").animate({
						'left' : '0'
					},{
						duration : time, 
						easing : 'easeInOutQuint'
					});
				
				if($("#back_navi").length != 0){
					$("#back_navi").animate({
							'margin-left' : sw
						},{
							duration : time, 
							easing : 'easeInOutQuint',
							complete : function(){
								$(this).remove();
							}
						});
				}
				
			},
			
			toSub : function(time, callback){
				marna.fl.stateChange(1);
								
				$("#header")
					.css({'left':$(window).width()-220,'right':''})
					.animate({ 
							'left' : '-1'
						},{ 
							duration : time,
							easing : 'easeInOutQuint',
							complete : function(){
								$.uif.setup('#contents');
								if(callback != null){
									callback.call(marna)
								}
							}
						});
				
				$("#footer").animate({
						'margin-top' : '0',
						'height' : '0'
					},{
						duration : time*0.5, 
						easing : 'easeInOutQuint'
					});
				
				$("#contents").animate({
						'margin-left' : '220px'
					},{
						duration : time, 
						easing : 'easeInOutQuint'
					});
				$("#navi_addon ul").animate({
						'left' : '-368px'
					},{
						duration : time, 
						easing : 'easeInOutQuint'
					});
				
				if($("#back_navi").length == 0){
					var $tmplate = $('<div id="back_navi"><p><a href="/en/"><img src="/common/img/module/btn_english_off.gif" width="70" height="30" alt="English Site" /></a></p></div>');
					$("#photo_stage").append($tmplate.css('height',0));
					$tmplate.delay(time).animate({
							'height' : '30px'
						},{
							duration : time*0.5, 
							easing : 'easeInOutQuint'
						});
				}
			},
			
			chengeSub : function(time, callback){
				$("#in_content").stop(true,false).animate({
						'width' : '720px'
					},{
						duration : time,
						easing : 'easeInOutQuint',
						complete : function(){
							$.uif.setup('#contents');
							if(callback != null){
								callback.call(marna)
							}
						}
					});
			},
			
			chengeSubSub : function(time, callback){
				$("#article > div").fadeTo(time,1,'easeInOutQuint',function(){
					$.uif.setup('#contents');
					if(callback != null){
						callback.call(marna)
					}
					$("#article").height($(this).height());
					marna.scroller.resize();
				})
			}
			
		},
		
		isTop : (location.pathname.split("/").length == 2),
		isEnglish : (location.pathname.match(/^\/en\//) != null),
		isEnglishTop : (location.pathname.match(/^\/en\/(index\.html)?$/) != null),
		isSetuped : false,
		ajaxLock : false,
		prevHash : "#",
		
		windowResizeHandler : function(){
			var sh = $(window).height();
				sh = sh < 605? 605 : sh;
				$('body #page').height(sh);
		},

		init : function(){
			$(marna.onReady);
		},
		onReady : function(){
			
			$.uif.setup();
			
			$.uif.resize.add(marna.windowResizeHandler).start();
			
			//console.log('marna.isTop : '+ marna.isTop);
			
			if(marna.isTop){
				$("#global_navi a:not('#btn_onlineshop'), #logo a, #btn_home").on('click', function(){
					var $t = $(this);
					if($t.hasClass('current')){
						location.hash = '#'+$t.attr('href').replace('.html','');
						return false;
					}
					
					$("#global_navi a.current, #guide_navi a .current")
						.removeClass('current').trigger('mouseout');
					$("#logo a,#btn_home").removeClass('current');
					$t.addClass('current');
					
					location.hash = '#'+$(this).attr('href').replace('.html','');
					
					return false;
				});
				
				$("#guide_navi a").on('click', function(){
					var $t = $(this);
					var $img = $t.find('img');
					if($img.hasClass('current')){
						location.hash = '#'+$t.attr('href').replace('.html','');
						return false;
					}
					
					$("#global_navi a.current, #guide_navi a .current")
						.removeClass('current').trigger('mouseout');
					$("#logo a,#btn_home").removeClass('current');
					
					$("#guide_navi a.current").removeClass('current');
					
					$t.addClass('current');
					$img.addClass('current');
					
					location.hash = '#'+$t.attr('href').replace('.html','');
					
					return false;
				});
				
				$(document).on('click', '#in_content a[href^="/"]:not(.external), #in_content area[href^="/"]:not(.external), #news_line #news_list a', function(){
					location.hash = '#'+$(this).attr('href').replace('.html','');
					return false;
				});
			}else{
				marna.scroller.setup();
			}
			
			$("#global_navi a").on({
				'mouseover' : function(){
					var $t = $(this);
					if($t.hasClass('current')) return false;
					$t.find('span:eq(0)').stop(true,false).animate({'width' : '220px'})
				},
				'mouseout' : function(){
					var $t = $(this);
					if($t.hasClass('current')) return false;
					$t.find('span:eq(0)').stop(true,false).animate({'width' : '0'})
				}
			}).not('.current').find('span:eq(0)').width(0);
			
			$(document)
				.on('mouseenter', "#local_navi > ul > li:has(ul)", function(){
					$(this).find('ul').css('display','block');
				})
				.on('mouseleave', "#local_navi > ul > li:has(ul)", function(){
					$(this).find('ul').css('display','none');
				});
			
			if(marna.isEnglish){
				$(document).on('click',"a[href='/']", $.uif.setup.externalLink.windowOpen);
			}else{
				$(document).on('click',"a[href^='/en/']", $.uif.setup.externalLink.windowOpen);
			}
			
			$("#global_navi a, #guide_navi a").each(function(){
				$(this).append($('<span class="arr" />'));
			});
			
			
			
		}
	};
	window.marna = marna;
	
	if (marna.util.is_flash_enabled()) {
		swfobject.embedSWF(
			(marna.isEnglish? "/en/common/swf/main.swf" : "/common/swf/main.swf") + "?="+(new Date().getTime()),
			"flash_area",
			"100%",
			"100%",
			"10",
			"/common/swf/expressInstall.swf",
			{}, {
				wmode : "transparent",
				menu: "false",
				scale: "noScale",
				allowFullscreen: "true",
				allowScriptAccess: "always",
				bgcolor: "#f4f4f4"
			},{
				id : marna.fl.SWF_NAME,
				name : marna.fl.SWF_NAME
			});
	}else{
	
		var __bind = function(fn,me){ return function(){ fn.apply(me,arguments); }; },
			$w = $(window);
			
		marna.fl.enabled = false;
		marna.fl.noflash = {
			fl_start : function(s){
				this.state = s;
				this.visualImageResize();
				if(s == 1){
					if(marna.util.is_mobile()){
						$('#photo_stage').css('display','none');
						return;
					}else{
						$('#flash_wrap .visual .text').css('display','none');
					}
				}
				$('#flash_wrap .visual').delay(1000).fadeTo(1000,1,$.easing.def,__bind(this.startTimer,this));
			},
			fl_stateChange : function(s){
				if(this.state == s) return;
				
				this.stopTimer();
				if(this.state == 0){
					$("#flash_wrap").animate({
						'left' : -$w.width()
					},{
						duration : 1000, 
						easing : 'easeInOutQuint',
						complete : __bind(function(){
							if(marna.util.is_mobile()){
								$("#flash_wrap")
									.stop(true,false)
									.fadeTo(0,0,$.easing.def,function(){
										$.uif.resize.remove(marna.fl.noflash.visualImageResize)
										$('#photo_stage').css('display','none');
									});
								return;
								
							}
							
							$('#flash_wrap .text').css('display','none')
							
							$("#flash_wrap")
								.stop(true,false)
								.fadeTo(0,0,$.easing.def,__bind(this.visualImageResize,this))
								.fadeTo(1000,1,$.easing.def,__bind(this.startTimer,this));
						},this)
					});
					if(this.bnr){
						this.bnr
							.stop(true,false)
							.animate({
								'bottom' : -1 * this.bnr.height()
							},{
								duration : 500, 
								easing : 'easeInOutQuint'
							})
					}
				}else{
					if(marna.util.is_mobile()){
						$.uif.resize.add(marna.fl.noflash.visualImageResize)
					}
					
					$("#flash_wrap").fadeTo(500,0,$.easing.def,function(){
						marna.fl.noflash.visualImageResize();
						$('#photo_stage').css('display','');
						$(this).find('.text').css('display','');
						$(this).stop(true,true).fadeTo(1000,1,$.easing.def,__bind(marna.fl.noflash.startTimer,marna.fl.noflash));
					})
					
					if(this.bnr){
						this.bnr
							.stop(true,false)
							.delay(1000)
							.animate({
								'bottom' : 45
							},{
								duration : 1000, 
								easing : 'easeInOutQuint'
							})
					}
				}
				this.state = s;
			},
			INTERVAL : 3000,
			images : null,
			bnr : null,
			num_images : 0,
			current : 0,
			state : 0,
			size_datas : [],
			timerID : 0,
			startTimer : function(){
				clearTimeout(this.timerID);
				this.timerID = setTimeout(__bind(this.onTimer,this), this.INTERVAL);
			},
			onTimer : function(){
				this.current = (this.current + 1)%(this.num_images);
				this.changeImage($(this.images[this.current]),__bind(this.startTimer,this));
			},
			stopTimer : function(){
				clearTimeout(this.timerID)
			},
			setImage : function($item,callback){
				var img_node = $item.find('img:eq(0)'),
					txt_node = $item.find('text:eq(0)'),
					visual = new Image(),
					text = new Image(),
					loadCnt = 0,
					
					loadEnd = function(){
						var size_data = {
							visual : {
								w : visual.width,
								h : visual.height
							},
							text : {
								w : text.width,
								h : text.height
							},
							text_resize : (txt_node.attr('resize') == 1)
						};
					
						marna.fl.noflash.size_datas[marna.fl.noflash.size_datas.length] = size_data;
						
						var $wrap = $('<div class="visual"></div>').css({
							'position' : 'absolute',
							'width' : '100%',
							'height' : '100%',
							'left' : 0,
							'top' : 0,
							'overflow' : 'hidden'
						}).fadeTo(0,0);
						
						var left = Number(txt_node.attr('left')), 
							top = Number(txt_node.attr('top'));
					
						left = (left > 1)? left+'px' : ( 0 < left && left <= 1)? (left*100)+'%' : 0;
						top = (top > 1)? top+'px' : ( 0 < top && top <= 1)? (top*100)+'%' : 0; 
						
						var $visual = $('<div class="image">').css({
							'position' : 'absolute'
						})
						$visual.append($(visual).css({'width' : '100%','height' : '100%'}))
						
						var $text = $('<div class="text"></div>').css({
							'position' : 'absolute',
							'left' : left,
							'top' : top,
							'display' : (marna.fl.noflash.state == 1)? 'none' : ''
						})
						if(size_data.text_resize){
							$text.append($(text).css({'width' : '100%', 'height' : '100%'}))
						}else{
							$text.append($(text).attr({'width' : size_data.text.w, 'height' : size_data.text.h}))
						}
						
						$wrap.append($visual);
						$wrap.append($text);
						
						$wrap.appendTo('#flash_wrap');
						
						marna.fl.noflash.visualImageResize();
						
						
						if(callback){
							callback();
						}
					},
					
					loadComplete = function(){
						loadCnt++
						if(loadCnt == 2){
							loadEnd();
						}
					};
					
				
				visual.onload = loadComplete;
				text.onload = loadComplete;
				
				visual.src = img_node.attr('src');
				text.src = txt_node.attr('src');
			},
			changeImage : function($item,callback){
				this.setImage($item,function(){
					$('#flash_wrap .visual:last').fadeTo(1000,1,$.easing.def, function(){
						marna.fl.noflash.size_datas.shift();
						$('#flash_wrap .visual:eq(0)').remove();
						if(callback){
							callback();
						}
					});
				})
			},
			getImageSize : function(sw,sh,size_data){
				var k = Math.max( sw / size_data.visual.w , sh / size_data.visual.h);
				var s = { 
					x : Math.floor((sw - Math.ceil(size_data.visual.w * k)) * 0.5),
					y : Math.floor((sh - Math.ceil(size_data.visual.h * k)) * 0.5),
					w : Math.ceil(size_data.visual.w * k),
					h : Math.ceil(size_data.visual.h * k)
				};
				
				if(marna.fl.noflash.state==0 && size_data.text_resize){
					k = sw / 1060;
					s['tw'] = size_data.text.w * k
					s['th'] = size_data.text.h * k
				}
				
				return s;
			},
			visualImageResize : function(){
				var sw = Math.max(960,$w.width()) - (marna.fl.noflash.state==0? 220 : 220 + 720),
					sh = Math.max(605,$w.height());
				
				if(marna.fl.noflash.state == 0){
					$("#flash_wrap").css({
						'left' : 0,
						'width' : sw
					})
				}else{
					$("#flash_wrap").css({
						'left' : 940,
						'width' : sw
					})
				}
				$("#flash_wrap .visual").each(function(index){
					var $t = $(this);
					var d = marna.fl.noflash.size_datas[index];
					var s = marna.fl.noflash.getImageSize(sw,sh,d);
					
					$t.find(".image").css({
						'left' : s.x,
						'top' : s.y,
						'width' : s.w,
						'height' : s.h
					})
					
					if(marna.fl.noflash.state==0 && d.text_resize){
						$t.find(".text").css({
							'width' : s.tw,
							'height' : s.th
						})
					}
				});
			},
			
			setBnr : function($bnr_data){
				if($bnr_data.length == 0) return;
				var $bnr = $('<div id="top_bnr"></div>').css({
					'position' : 'absolute',
					'left' : 10,
					'bottom' : '-100%',
					'z-index' : 1000
				});
				
				var bnr = new Image();
				bnr.onload = function(){
					var h = this.height;
					if($bnr_data.attr('url')){
						var $bnr_link = $('<a></a>');
						$bnr_link.attr('href',$bnr_data.attr('url'));
						$bnr_link.append(bnr);
						$bnr.append($bnr_link);
					}else{
						$bnr.append(bnr)
					}
					
					marna.fl.noflash.bnr = $bnr;
					$("#photo_stage").append($bnr);
					if(marna.fl.noflash.state==0){
						$bnr
							.css({'bottom' : -h})
							.delay(1000)
							.animate({
								'bottom' : 45
							},{
								duration : 1000, 
								easing : 'easeInOutQuint'
							})
					}
				}
				bnr.src = $bnr_data.attr('src');
				
			},
			
			init : function(){
				$.ajax({
					url : (marna.isEnglish? '/en/common/xml/visual.xml' : '/common/xml/visual.xml'),
					cache: false,
					dataType : 'text',
					success : __bind(function(res){
						res = $(res);
						
						this.images = res.find('item');
						this.num_images = this.images.length;
						this.current = Math.floor(Math.random()*this.num_images);
						
						$("#photo_stage").css('overflow','hidden');
						$("#flash_area").remove();
						
						this.setBnr(res.find('banners top bnr:eq(0)'));
						
						this.setImage($(this.images[this.current]), function(){
							$w.trigger('startup');
							$.uif.resize.add(marna.fl.noflash.visualImageResize)
						});
					},this)
				})
			}
		}
		
		$(__bind(marna.fl.noflash.init,marna.fl.noflash));
	}
	
	marna.init();
	
	if(marna.util.is_mobile_resizer()){
		var fl_start = marna.fl.noflash.fl_start;
		marna.fl.noflash.fl_start = function(s){
			if(s == 1){
				$('body #page').css({'overflow':'auto','height':'auto'})
				$.uif.resize.remove(marna.windowResizeHandler);
			}
			fl_start.call(this,s);
		}
		var fl_stateChange = marna.fl.noflash.fl_stateChange;
		marna.fl.noflash.fl_stateChange = function(s){
			if(this.state == s) return;
			if(s == 0){
				$('body #page').css('overflow','hidden').scrollTop(0);
				$.uif.resize.add(marna.windowResizeHandler);
				marna.windowResizeHandler();
			}else{
				$.uif.resize.remove(marna.windowResizeHandler);
				$('body #page').css({'overflow':'auto','height':'auto'})
			}

			fl_stateChange.call(this,s);
		}
	}

	/*
	if(navigator.userAgent.match(/iPad/i)){
		var viewportmeta = document.createElement('meta');
		viewportmeta.name = "viewport"
		viewportmeta.content = 'width=device-width, initial-scale=0.8, minimum-scale=0.8';
		document.head.appendChild(viewportmeta)
	}
	*/
	
	
})(jQuery);

