/*
 * project.js v0.2.5
 * 
 */

var Project = function(){

	this.devMode = false;	// development mode (toggle navigation)
	
	this.containerWidth = 970;	// div#container's width (for getViewportRect)
	
	this.checkOS = {
		win:this.isUserAgent('Win'),
		mac:this.isUserAgent('Mac')
	}
	this.checkBrowser = {
		opera:this.isUserAgent('Opera'),
		//chrome:this.isUserAgent('Chrome'),
		firefox:this.isUserAgent('Firefox'),
		firefox2:this.isUserAgent('Firefox/2'),
		firefox35:this.isUserAgent('Firefox/3.5'),
		//safari:this.isUserAgent('Safari'),
		ie:this.isUserAgent('MSIE'),
		ie6:this.isUserAgent('MSIE 6'),
		ie7:this.isUserAgent('MSIE 7'),
		ie8:this.isUserAgent('MSIE 8')
	}
	this.preloadedImages = [];
}

Project.prototype = {

	// basic methods

	init:function(){
		this.loadScript(),
		this.setRollover(),
		this.setTargetBlank(),
		this.setScroll(),
		this.setBlur()
	},	
	loadScript:function(){
		// js directory
		var path = '/js/';
		// js files
		var scripts = [
			'jquery.easing.min.js'			
		];
		
		if($('.lightbox').length){
			scripts.push('jquery.fancybox-1.2.6.js');			
		}
		
		// for IE6
		if(this.checkBrowser.ie6){
			scripts.push('jquery.pngFix.js');
			scripts.push('imgSizer.js');
		}
		
		for(var i = 0; i < scripts.length; i++){
			var element = document.createElement('script');
			element.src = [path, scripts[i]].join('');
			element.type = 'text/javascript';
			document.body.appendChild(element);
		}
	},
	setRollover:function(){
		// add 'class="rollover"' in img or input tags
		var images = $('.rollover');

		if(!images.length) return;
		
		var offSuffix = "_off.";	// e.g. button-off.gif
		var onSuffix = "_on.";	// e.g. button-on.gif

		this.preloadImage('','.rollover',offSuffix,onSuffix);

		for(var i = 0; i < images.length; i++){
			if(images[i].getAttribute("src").match(offSuffix)){
				images[i].onmouseover = function(){
					this.setAttribute("src", this.getAttribute("src").replace(offSuffix,onSuffix));
				}
				images[i].onmouseout = function(){
					this.setAttribute("src", this.getAttribute("src").replace(onSuffix,offSuffix));
				}
			}
		}	
	},
	preloadImage:function(url,selector,offSuffix,onSuffix){
		var images = this.preloadedImages;
		var image;
		
		if(selector){
			// for rollover images		
			$(selector).each(function(){
				image = new Image();
				image.src = $(this).attr('src').replace(offSuffix,onSuffix);
				images.push(image);
			});
		}else if(url){		
			// for other image
			image = new Image();
			image.src = url;
			images.push(image);
		}
	},
	setTargetBlank:function(){
		$('a[rel="external"][href]').attr('target', '_blank');	
	},
	setScroll:function(){
		if(!$('a[href^="#"]')) return;

		var durationTime = 1000;
		var easingType = 'easeInOutCirc';

		$('a[href^="#"]').click(function(){
			var target = $(this).attr('href');

			if(target == "#"){
				$(this).blur();		
				$('html, body').animate({ scrollTop:0 }, durationTime, easingType);
				return false;
			}
					
			var targetOffset = $(target).offset().top;
					
			$(this).blur();
			$('html,body').animate({ scrollTop:targetOffset }, durationTime, easingType);
			
			return false;
		});
	},
	setBlur:function(){
		if(this.checkBrowser.ie){
			$('a').focus(function(){this.blur();});
		}
	},
	openPopup:function(linkObj, url, width, height, name){
		if(!linkObj || !url){
			alert('openPopup:params are not found');
			return;
		}
		
		if(!$(linkObj).length) return;
		
		width = width || 600;
		height = height || 500;
		name = name || 'popup';
	
		var params = "width=" + width + ",height=" + height + ",toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
		
		$(linkObj).click(function(){
			window.open(url, name, params);
			return false;
		});
	},
	closePopup:function(linkObj){
		if(!linkObj){
			alert('closePopup:params are not found');
			return;
		}
		
		var button = $(linkObj);
		if(!button.length) return;
		
		button.click(function(){
			window.close();
		});
	},
	
	// utilities
	
	isUserAgent:function(ua){
		return navigator.userAgent.indexOf(ua) != -1;
	},
	getElement:function(str){
		//str.replace('#', '');
		return document.getElementById(str);	
	},
	create:function(str){
		return document.createElement(str);
	},
	
	// development tools
	
	testNav:function(){
		if(this.isUserAgent('MSIE 6')) return;
		$('body').append('<div id="TESTNAV" style="position:fixed;z-index:999999;bottom:0px;right:-183px;font-size:9px;color:#fff;background:black;opacity:0.8;width:180px;height:35px;padding:10px 10px 10px 20px;"></div>');
		var nav = $('#TESTNAV');
		nav.load('/_testnavi.html');
		nav.mouseover(function(){
			$(this).css({right:'0px',height:'auto'});			 
		});
		nav.mouseleave(function(){
			$(this).css({right:'-183px',height:'35px'});
		});
	}
}

var KOTORI = new Project();

// define custom functions (as KOTORI.fn's methods)

KOTORI.fn = {
	setPngFix:function(selector){
		
		if($('#top-contents').length){
			$('p.object').pngFix();
			$('dl.best,dl.worst').pngFix();
			$('#left-column').pngFix();
		}
		
		if($('#ranking-area').length){
			$('.items').pngFix();
		}
		
		if($('#top-vidual').length){
			$('#top-vidual').pngFix();
		}
		
	},
	setImgResize:function(){

		if($('#kotori101-vidual').length){
			imgSizer.collate($('img[class*=resize]'));	
		}

		if($('#kotori201-vidual').length){
			imgSizer.collate($('img[class*=resize]'));	
		}

		if($('#top10').length){
			imgSizer.collate($('img[class*=resize]'));	
		}
		
	},
	scrollToPosition:function(pos, time){
		var easingType = 'easeInOutCirc';
		time = time || 1000;
		pos = pos || 0;
		
		$('html, body').animate({ scrollTop:pos}, time, easingType);
	},
	getScroll:function(){
		return {
			x:document.body.scrollLeft || document.documentElement.scrollLeft,
			y:document.body.scrollTop || document.documentElement.scrollTop
		}
	},
	getViewportRect:function(){
		var windowWidth, windowHeight, tmpWidth, tmpHeight;
	
		if(KOTORI.checkBrowser.ie){
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else {
			windowWidth = tmpWidth = window.innerWidth;
			windowHeight = tmpHeight = window.innerHeight;

			if(document.body.offsetHeight > tmpHeight){
				windowWidth = tmpWidth - 16;
			}
			if(KOTORI.containerWidth > tmpWidth){
				windowHeight = tmpHeight - 16;
			}
		}

		var scrl = KOTORI.fn.getScroll();
	
		return {
			x:scrl.x,
			y:scrl.y,
	 		width:windowWidth,
	 		height:windowHeight
		}
	},
	parseFromString:function(xml){
		var root;
		if(window.DOMParser){
			var xmldom = new DOMParser();
			xmldom.async = false;
			var dom = xmldom.parseFromString(xml, "application/xml");
			if (!dom) return;
			root = dom.documentElement;
		}else if(window.ActiveXObject){
			xmldom = new ActiveXObject('Microsoft.XMLDOM');
			xmldom.async = false;
			xmldom.loadXML(xml);
			root = xmldom.documentElement;
		}
		return root;
	},
	addLightbox:function(){
		// this method is called by 'jquery.fancybox-1.2.5.pack.js'
		//var element = $('.lightbox');
		//if(!element.length) return;
		$('.lightbox').fancybox({
			'padding': 0,
			'overlayColor': '#fff',
			'overlayOpacity': 0.7,
			'zoomOpacity': true,
			'overlayShow': true,
			'zoomSpeedIn': 250,
			'zoomSpeedOut': 250
		});
	},
	slideArea:function(){
		var area = $('#destination-area');
		if(!area.length) return;
	
		var self = $('#address_delivery_other_address_flag_0');
		var other = $('#address_delivery_other_address_flag_1');
		var area = $('#destination-area');
	
		area.hide();
		
		self.click(function(){
			area.slideUp('fast');
		});
		other.click(function(){
			area.slideDown('fast');
		});
	},
	changeSeparator:function(){
		var images = $('.color-separator img');
	
		if(!images.length) return;
		
		var colors = 15; // number of color chips
		var table = [];
		var src;		
		var current;
		
		for(var i = 0; i < (colors - 1); i++){
			table.push(i + 2);
		}
		
		for(var j = 0; j < images.length; j++){
			current = Math.floor(Math.random() * (table.length - 1));
			
			src = $(images[j]).attr('src');
			src = src.replace(/colorchip[\d0-9]+/, 'colorchip' + table[current]);
			$(images[j]).attr('src', src);
			
			table.splice(current, 1);
		}
	},
	scrollTop:function(){
		$('html, body').animate({ scrollTop: 0 }, 1000, 'easeInOutCirc');
	},
	scrollToPosition:function(px){
		$('html, body').animate({ scrollTop: px }, 1000, 'easeInOutCirc');
	},
	fastScrollTop:function(){    
 		$('html, body').animate({ scrollTop: 0 }, 250, 'swing');    
	},
	getScrollY:function(){
		var y = 0;
		y = document.body.scrollTop || document.documentElement.scrollTop;
		return y;
	},
	openFlashContent:function(height){
		area = $('#flashContent');
	
		if(!area.length) return;
		if(!height) height = 2100;
		
		contentHeight = height + 'px';
		
		area.animate({
			height: contentHeight
		}, 'slow');					 
	},
	getSWF:function(movieName){
		if (navigator.appName.indexOf("Microsoft") != -1) {
					return window[movieName]
			}
			else {
					return document[movieName]
			}
	},
	scrollHandler:function(){
		KOTORI.fn.getSWF(swfName).setScroll(KOTORI.fn.getScroll());
	},
	resizeHandler:function(){
		KOTORI.fn.getSWF(swfName).setViewportRect(KOTORI.fn.getViewportRect());
	},
	addCustomPageEvent:function(){
		if(!$('#customize-contents').length) return;
		
		var tmr;
		if(KOTORI.checkBrowser.firefox35){    
						tmr = setTimeout("KOTORI.fn.addWindowEvent()", 1600);        
		}else{    
						tmr = setTimeout("KOTORI.fn.addWindowEvent()", 200);       
		}
	},
	addWindowEvent:function(){
		$(window).scroll(function(){
			KOTORI.fn.scrollHandler();
		});
		$(window).resize(function(){
			KOTORI.fn.resizeHandler();
		});	
	},
	addHomeRollover:function(){
		var image = $('#home-button img');
	
		if(!image.length) return;
	
		var logo = $('#header h1 img');
	
		var offSuffix = "_off.";	// e.g. button-off.gif
		var onSuffix = "_on.";	// e.g. button-on.gif
	
		logo.mouseover(function(){
			image.attr("src", image.attr("src").replace(offSuffix, onSuffix));
		});
		logo.mouseleave(function(){
			image.attr("src", image.attr("src").replace(onSuffix, offSuffix));
		});
	},
	addTabEvent:function(model){
		var tabs = $('#tabs a');
		
		var areas = $('#toggle-area > div');
				
		var detailArea = $('#detail');
		var specArea = $('#spec');
		
		var detailTab = $('#detail-tab a');
		var specTab = $('#spec-tab a');

		var separator1 = $('#separator1');
		var separator2 = $('#separator2');
		
		if(model == '101'){
			var comboxArea = $('#combox');
			var comboxTab = $('#combox-tab a');	
		}
		
		if(model == '201'){
			var featureArea = $('#feature');
			var photoArea = $('#photo');
			
			var featureTab = $('#feature-tab a');
			var photoTab = $('#photo-tab a');

			var separator3 = $('#separator3');
		}

		tabs.click(function(){
			var currentTab = $(this);
			var id = currentTab.parents('li').attr('id');
			
			tabs.removeClass('left');
			tabs.removeClass('right');
			tabs.removeClass('selected');
			currentTab.addClass('selected');
			
			separator1.attr('src', separator1.attr('src').replace('_on', '_off'));
			separator2.attr('src', separator2.attr('src').replace('_on', '_off'));

			if(model == '201'){
				separator3.attr('src', separator3.attr('src').replace('_on', '_off'));
			}

			areas.hide();

			if(model == '101'){	
				switch(id){
					case 'detail-tab':
					
						detailArea.show();
						specTab.addClass('left');
	
						separator1.attr('src', separator1.attr('src').replace('_off', '_on'));
	
						break;
					
					case 'spec-tab':
	
						specArea.show();
						detailTab.addClass('right');
						comboxTab.addClass('left');
	
						separator1.attr('src', separator1.attr('src').replace('_off', '_on'));
						separator2.attr('src', separator2.attr('src').replace('_off', '_on'));
	
						break;
					
					case 'combox-tab':
					
						comboxArea.show();
						specTab.addClass('right');
	
						separator2.attr('src', separator2.attr('src').replace('_off', '_on'));
						
						break;
				}
			}

			if(model == '201'){
				
				switch(id){
					case 'detail-tab':
					
						detailArea.show();
						featureTab.addClass('left');
	
						separator1.attr('src', separator1.attr('src').replace('_off', '_on'));
	
						break;
					
					case 'feature-tab':
	
						featureArea.show();
						detailTab.addClass('right');
						specTab.addClass('left');
	
						separator1.attr('src', separator1.attr('src').replace('_off', '_on'));
						separator2.attr('src', separator2.attr('src').replace('_off', '_on'));
	
						break;
					
					case 'spec-tab':
	
						specArea.show();
						featureTab.addClass('right');
						photoTab.addClass('left');
	
						separator2.attr('src', separator2.attr('src').replace('_off', '_on'));
						separator3.attr('src', separator3.attr('src').replace('_off', '_on'));
	
						break;
					
					case 'photo-tab':
					
						photoArea.show();
						specTab.addClass('right');
	
						separator3.attr('src', separator3.attr('src').replace('_off', '_on'));
						
						break;
				}
			}

			return false;	
		});
	},
	addThumbEvent:function(model){
		var specThumbs = $('#spec #thumb-list li, #spec-area #thumb-list li');
		var specImage = $('#spec-image');
		
		for(var i = 1;i <= specThumbs.length; i++){
			var src = specImage.attr('src');
			src = src.replace(/image[0-9]+/,'image' + i);
			KOTORI.preloadImage(src)
		}
		
		specThumbs.click(function(){
			KOTORI.fn.changeSpecImage(this.id, model);
			KOTORI.fn.selectSpecThumb(this.id);
		});
		
		specThumbs.mouseover(function(){
			var outline = $('#spec #' + this.id + ' span, #spec-area #' + this.id + ' span');
			
			if(outline.attr('class') == 'selected') return;
				
			outline.attr('class', 'hover');
		});
		
		specThumbs.mouseout(function(){
			var outline = $('#spec #' + this.id + ' span, #spec-area #' + this.id + ' span');
	
			if(outline.attr('class') == 'selected') return;
	
			outline.attr('class', 'outline');
		});
		
		if(model == '201'){

			var photoThumbs = $('#photo #thumb-list li, #photo-area #thumb-list li');
			var photoImage = $('#photo-image');

			for(var i = 1;i <= photoThumbs.length; i++){
				var src = photoImage.attr('src');
				src = src.replace(/image[0-9]+/,'image' + i);
				KOTORI.preloadImage(src)
			}

			photoThumbs.click(function(){
				KOTORI.fn.changePhotoImage(this.id, model);
				KOTORI.fn.selectPhotoThumb(this.id);
			});
			
			photoThumbs.mouseover(function(){
				var outline = $('#photo #' + this.id + ' span, #photo-area #' + this.id + ' span');
				
				if(outline.attr('class') == 'selected') return;
					
				outline.attr('class', 'hover');
			});
			
			photoThumbs.mouseout(function(){
				var outline = $('#photo #' + this.id + ' span, #photo-area #' + this.id + ' span');
		
				if(outline.attr('class') == 'selected') return;
		
				outline.attr('class', 'outline');
			});
		}
	},
	changeSpecImage:function(id, model){
		
		var imagePath = '/images/set/';
		
		if(model == '101'){
			
			var specPrefix = 'spec101_image';		
			
		}else if(model == '201'){
			
			var specPrefix = 'spec201_image';		
		
		}
		
		id = id.replace('thumb', '');
	
		var specSrc = imagePath + specPrefix + id + '.jpg';
		
		$('#spec-image').attr('src', specSrc);
		
	},
	changePhotoImage:function(id, model){
		
		var imagePath = '/images/set/';
		
		var photoPrefix = 'photo201_image';					
	
		id = id.replace('thumb', '');
	
		var photoSrc = imagePath + photoPrefix + id + '.jpg';
		
		$('#photo-image').attr('src', photoSrc);
		
	},
	selectSpecThumb:function(id){
		var outlines = $('#spec #thumb-list span, #spec-area #thumb-list span');
		var selected = $('#spec #' + id + ' span, #spec-area #' + id + ' span');
		
		outlines.attr('class', 'outline');
		selected.attr('class', 'selected');
	},
	selectPhotoThumb:function(id){
		var outlines = $('#photo #thumb-list span, #photo-area #thumb-list span');
		var selected = $('#photo #' + id + ' span, #photo-area #' + id + ' span');
		
		outlines.attr('class', 'outline');
		selected.attr('class', 'selected');
	},
	addOutline:function(){
		var thumbs = $('#thumb-list li[id!="thumb1"]');
		var outline = '<span class="outline"></span>';
		//var selected = '<span class="selected"></span>';
		
		thumbs.append(outline);
		//$('#thumb1').append(selected);
	},
	initPreview:function(){
		//if(!$('div#preview').length)return;
		
		if($('#kotori101-data').length){

			KOTORI.fn.addTabEvent('101');
			KOTORI.fn.addOutline();
			KOTORI.fn.addThumbEvent('101');
			
		}else{
			
			KOTORI.fn.addTabEvent('201');
			KOTORI.fn.addOutline();
			KOTORI.fn.addThumbEvent('201');
				
		}
		
	},
	templateListStyle:function(){
		//if(!$('#templates').length) return;
		$('.name').css({
			fontSize:'82%',
			letterSpacing: '0.03em'
		});
	},
	templateClickable:function(){
		//if(!$('#templates').length) return;
	
		$('.template').mouseover(function(){
			$(this).addClass('over');
		});
		$('.template').mouseleave(function(){
			$(this).removeClass('over');
		});
		$('.template').click(function(){
			window.location.replace(this.getElementsByTagName('a')[0].href);
		});
	},
	stackVoice:function(){
		//if(!$('#users').length) return;
	
		var voices = $('#voices');
		var voice = $('.voice');
		
		var usersHeight;
	
		var leftHeight = 0;
		var rightHeight = 0;
		
		var leftOffset = 0;
		var rightOffset = 20;
		
		var voiceMargin = 20;

		var itemheight = 140;

		rightHeight = rightHeight + rightOffset;
		
		voices.append('<div id="voice-left"><span class="dummy">&nbsp;</span></div><div id="voice-right"><span class="dummy">&nbsp;</span></div>');
	
		voice.each(function(){
			var voiceEle = $(this);
			var voiceHeight = voiceEle.outerHeight();
			var numOfItem = voiceEle.find('.items dl').length;

			var baloonHeight = voiceHeight - (numOfItem * itemheight);

			var itemsHeight = itemheight + parseInt(((numOfItem - 1) / 3)) * itemheight;
			
			var voiceHeight = baloonHeight + itemsHeight;
						
			if(leftHeight <= rightHeight){
				$('#voice-left').append(voiceEle);
				voiceEle.addClass('left');
				
				leftHeight = leftHeight + voiceHeight + voiceMargin;
								
			}else{
				$('#voice-right').append(voiceEle);
				voiceEle.addClass('right');
	
				rightHeight = rightHeight + voiceHeight + voiceMargin;			
			}

		});
		
		var voiceCounter = 0;
		
		var timer = setInterval(function(){
																		 
			var ele = $(voice[voiceCounter]);
			
			if(voiceCounter < voice.length){
				
				$(voice[voiceCounter]).fadeIn(300);			
				voiceCounter++;
				
			}else{

				clearInterval(timer);
							
			}			
			
		},350);
		
		
		if(KOTORI.checkOS.win){
			$('p.date span').css('letterSpacing','0.06em');
		}
		if(KOTORI.checkBrowser.ie6){
			$('.items img').mouseover(function(){
					$(this).css('border','1px solid #ccc');
			});
			$('.items img').mouseleave(function(){
					$(this).css('border','1px solid #fff');
			});
			
		}
	},
	itemRollover:function(){
		if(!$('#main')) return;
		var itemImages = $('.items dt');
		var itemLinks = $('.items .link');
		
		itemImages.mouseover(function(){
			$(this).find('.selected').show();
			$(this).siblings('.link').addClass('selected');
		});
		itemImages.mouseleave(function(){
			$(this).find('.selected').hide();
			$(this).siblings('.link').removeClass('selected');
		});
		
		itemLinks.mouseover(function(){
			$(this).siblings('dt').find('.selected').show();
		});
		itemLinks.mouseleave(function(){
			$(this).siblings('dt').find('.selected').hide();
		});
	},
	itemRolloverTop:function(){
		//if(!$('#top-contents').length) return;
		$('.item').mouseover(function(){
			$(this).find('.outline').show();															
		});
		$('.item').mouseleave(function(){
			$(this).find('.outline').hide();															
		});
		$('div.list .image').mouseover(function(){
			$(this).siblings('.title').addClass('over');
		});
		$('div.list .image').mouseleave(function(){
			$(this).siblings('.title').removeClass('over');
		});	
	},
	twitterRollover:function(){
		//if(!$('#top-contents').length) return;
		$('#twitter .follow a').mouseover(function(){
			var bg = $(this).siblings('.bg');
			var overSrc = bg.attr('src');
			overSrc = overSrc.replace('_off.', '_on.');
			bg.attr('src', overSrc);		
		});
		$('#twitter .follow a').mouseleave(function(){
			var bg = $(this).siblings('.bg');
			var overSrc = bg.attr('src');
			overSrc = overSrc.replace('_on.', '_off.');
			bg.attr('src', overSrc);		
		});
		$('#twitter .read a').mouseover(function(){
			var bg = $(this).siblings('.bg');
			var overSrc = bg.attr('src');
			var follow = $('dd.follow .bg');
			var followSrc = follow.attr('src');
	
			overSrc = overSrc.replace('_off.', '_on.');
			followSrc = followSrc.replace('_off.', '_over.');
			
			bg.attr('src', overSrc);
			follow.attr('src', followSrc);
		});		
		$('#twitter .read a').mouseleave(function(){
			var bg = $(this).siblings('.bg');
			var overSrc = bg.attr('src');
			var follow = $('dd.follow .bg');
			var followSrc = follow.attr('src');
	
			overSrc = overSrc.replace('_on.', '_off.');
			followSrc = followSrc.replace('_over.', '_off.');
	
			bg.attr('src', overSrc);
			follow.attr('src', followSrc);
		});		
	},
	showCartQuantity:function(){
		if(!$('#cart-quantity-area')) return;
		KOTORI.fn.loadJSON('/api/cartInfo', 'cart-quantity-area');
	},
	loadJSON:function(url, insertID){
		if(!url || !insertID) return;
		
		var date = new Date();
		var param = date.getTime();
		
		$.getJSON(url + '?param=' + param, function(data){
			KOTORI.fn.displayData(data, insertID);																						
		});
	},
	displayData:function(data, insertID){
	
		var id = '#' + insertID;
		var line = '';
		//line += '<span id="cart-quantity">';
		line += data.items_count;
		//line += '<img src="/images/shared/icon_quantity.png" width="10" height="13" alt="ƒR" /></span>';
		
		$(id).html(line);
	},
	headerDropMenu:function(){
		var menu = $('#template-menu');
		if(!menu.length) return;
		
		var title = $('#template-menu dt');
		var buttons = $('#template-menu dd');
	
		var image = title.find('img')
		var src = image.attr('src');
	
		title.mouseover(function(){
			src = src.replace('_off.', '_on.');
	
			image.attr('src', src);
			menu.addClass('open');
			buttons.show();
		});
		menu.mouseleave(function(){
			src = src.replace('_on.', '_off.');
	
			image.attr('src', src);
			buttons.hide();
			menu.removeClass('open');
		});
	},
	rankingRollover:function(){
		//if(!$('div#top10').length) return;
		
		var image = $('dd.image a');
		//var outline = '<img src="/images/ranking/outline.png" alt="" width="140" height="120" class="outline" />';
		
		image.mouseover(function(){
			$(this).find('.outline').show();													
		});
		image.mouseleave(function(){
			$(this).find('.outline').hide();													
		});
	},
	votingRollover:function(){
		if(!$('#voting').length) return;
		
		var image = $('dt.item a');
		//var outline = '<img src="/images/ranking/outline.png" alt="" width="140" height="120" class="outline" />';
		
		image.mouseover(function(){
			$(this).find('.outline').show();													
		});
		image.mouseleave(function(){
			$(this).find('.outline').hide();													
		});
	},
	lastEntry:function(){
		//if(!$('#sidebar').length) return;
		if($('#paging .rollover').length) return;
		
		$('div.entry:last').addClass('last');
		$('#entries').addClass('none');
		//$('#paging').hide();
	},
	chromeHeader:function(){
		if(!KOTORI.checkBrowser.chrome) return;
		
		$('#press-menu').css('left', '102px');
		$('#home-button').css('top', '-7px');
		//$('#template-menu').css('left', '439px');
		//$('#guide-menu').css('left', '-20px');
	},	
	voteDesign:function(eleId, voteType){
	
		var itemId = eleId.replace(/item.-/, "");
		
		if(KOTORI.fn.isVoted(itemId)){
			return;
		}
		
		// API URL
		var url = '/api/voteDesign';
		
		if(!voteType){
			// love
			$.get(url, {goodsId: itemId, voteType: 0});
		}else{
			// hate
			$.get(url, {goodsId: itemId, voteType: 1});
		}
	
		KOTORI.fn.setVoted(itemId);
		KOTORI.fn.voteCount(itemId, voteType);
		KOTORI.fn.setCookie(itemId);
	},	
	voteCount:function(itemId, voteType){
		//if(!$('#top-contents').length) return;
		
		for(var i = 1; i < 6; i++){
			if(!voteType){
				var countEle = $('#item' + i + "-" + itemId + ' .love');	
			}else{
				var countEle = $('#item' + i + "-" + itemId + ' .hate');	
			}
			
			var count = countEle.text();
			
			countEle.hide();
			countEle.text(parseInt(count) + 1);
			countEle.fadeIn(1000);
		}
	},
	addVoteEvent:function(){
		//if(!$('#scrapbook-area').length) return;
		
		KOTORI.fn.voteInit();
		
		var love = $('#scrapbook-area span[class*="love"]');
		var hate = $('#scrapbook-area span[class*="hate"]');
		
		love.click(function(){
			KOTORI.fn.voteDesign($(this).parents('dl').attr('id'), 0);
		});
		hate.click(function(){
			KOTORI.fn.voteDesign($(this).parents('dl').attr('id'), 1);															
		});
	
		//if(KOTORI.checkBrowser.ie6){
			love.mouseover(function(){
				if($(this).attr('class').indexOf('Voted') < 0){
					$(this).addClass('loveOver');
				}
			});
			hate.mouseover(function(){
				if($(this).attr('class').indexOf('Voted') < 0){
					$(this).addClass('hateOver');
				}
			});
		
			love.mouseleave(function(){
				if($(this).attr('class').indexOf('Voted') < 0){
					$(this).removeClass('loveOver');
				}
			});
			hate.mouseleave(function(){
				if($(this).attr('class').indexOf('Voted') < 0){
					$(this).removeClass('hateOver');
				}
			});
	
		/*}else{
			love.mouseover(function(){
				if($(this).attr('class').indexOf('voted') < 0){
					$(this).addClass('over');
				}
			});
			hate.mouseover(function(){
				if($(this).attr('class').indexOf('voted') < 0){
					$(this).addClass('over');
				}
			});
		
			love.mouseleave(function(){
				if($(this).attr('class').indexOf('voted') < 0){
					$(this).removeClass('over');
				}
			});
			hate.mouseleave(function(){
				if($(this).attr('class').indexOf('voted') < 0){
					$(this).removeClass('over');
				}
			});
		}*/
	},
	voteInit:function(){
		//var items = document.getElementById('voting').getElementsByTagName('dl');
		var items = document.getElementById('scrapbook-area').getElementsByTagName('dl');
	
		for(var i = 0; i < items.length; i++){
			
			var itemId = items[i].getAttribute('id').replace(/item.-/, "");
			
			if(KOTORI.fn.isVoted(itemId)){
				KOTORI.fn.setVoted(itemId);
			}
		}
	},
	setVoted:function(itemId){
		for(var i = 1; i < 5; i++){
			var votedItem = $('#item' + i + "-" + itemId);
			//var check = votedItem.find('.check');
			var love = votedItem.find('.love');
			var hate = votedItem.find('.hate');
				
			//if(KOTORI.checkBrowser.ie6){
				love.addClass('loveVoted');
				hate.addClass('hateVoted');
			
				love.removeClass('loveOver');
				hate.removeClass('hateOver');
			/*}else{
				love.addClass('voted');
				hate.addClass('voted');
		
				love.removeClass('over');
				hate.removeClass('over');
			}*/
				
			//check.show();
		
			/*love.mouseover(function(){
				$(this).siblings('.check').find('.balloon').show();												
			});
			love.mouseleave(function(){
				$(this).siblings('.check').find('.balloon').hide();												
			});
		
			hate.mouseover(function(){
				$(this).siblings('.check').find('.balloon').show();												
			});
			hate.mouseleave(function(){
				$(this).siblings('.check').find('.balloon').hide();												
			});
		
			check.mouseover(function(){
				$(this).find('.balloon').show();												 
			});
			check.mouseleave(function(){
				$(this).find('.balloon').hide();												 
			});*/
		}
	},
	setCookie:function(itemId){
		if(!navigator.cookieEnabled) return;
		
		var date = '';
		var expire = 1; // days
		var value = KOTORI.fn.getCookie();
	
		var dateObj = new Date();
		dateObj.setTime(dateObj.getTime() + expire * 24 * 60 * 60 * 1000);
		//dateObj.setTime(dateObj.getTime() + 10 * 60 * 1000);
		
		date = 	dateObj.toGMTString();
	
		if(value){
			value += "/" + itemId;	
		}else{
			value = itemId;
		}
		
		document.cookie = 'voted=' + value + ';expires=' + date + ';path=/';
		
		return true;
	},
	getCookie:function(){
		if(!navigator.cookieEnabled) return;
	
		var cookie = document.cookie;
		var name = "voted="
		var matchStr = new RegExp(name + "[^;]*");
		var value;
		
		if(cookie.indexOf('voted') != -1){
			value = cookie.match(matchStr) + "";
			value = value.replace(name, '');
			return value;
		}
	},
	isVoted:function(goodsId){
		if(!navigator.cookieEnabled) return;
	
		var cookie = document.cookie;
		
		if(cookie.indexOf(goodsId) != -1){
			return true;
		}else{
			return false;
		}
	},
	toggleDate:function(){
		var later = $('input.sendLater');
		
		if(!later.length) return;
		
		var input = $('td.date select.dropdown');
		
		input.change(function(){
			later.attr('checked','checked');											
		});
	},
	checkGiftMode:function(){
		if(!$('#giftmode-open, #kotori-menu2').length) return;
		
		var date = new Date();
		var param = date.getTime();
		
		$.ajax({
			 type: "POST",
			 url: "/api/checkGiftMode?param=" + param,
			 error: function(res){
				 if(res.status == 0){
					 return;
				 } else {
					 alert('ERROR : Fail to access the API.');
				 }
			 },
			 success: function(res){
				 var xml = $(KOTORI.fn.parseFromString(res));
				 
				 if(xml.attr('status') == 'success'){
				 
					 if(xml.find('type').text() != 0){
						 
						 $('#header').addClass('giftmode');
						 
						 if(KOTORI.checkBrowser.ie6){
							 
							 $('#giftmode-close').css('top',0);
							 
						 }else{
							 
							 $('#giftmode-close').animate({
								'top':0														
							 });							
							 
						 }
						 						 
						 $('#giftmode-close img').mouseover(function(){
							
							 $('#giftmode-open').show();
							
						 });
						 
						 $('#giftmode-open').mouseleave(function(){
																										 
							 $(this).hide();

						 });

						 $('#giftmode-open img').click(function(){
								KOTORI.fn.releaseGiftMode();
						 });
						 
						 // for top page
						 $('#kotori-menu2 .giftcode-off').css('display','none');
						 $('#kotori-menu2 .giftcode-on').css('display','block');

						 // for KOTORI 201 top page
						 $('#kotori201-vidual').css('top',107);
						 KOTORI.giftmode = true;

						 //$('#header .gift-mode').show();
						 //$('#top-header .gift-mode').show();
						 setInterval(KOTORI.fn.dummy,30 * 60 * 1000);
						 
					 }else{
						$('#kotori101-vidual .giftcode').show(); // 101 top
						$('dt.giftcode').show(); // header
						//$('#header .normal-mode').show();
						//$('#left-column .giftcode').show();
						
						 // for top page
						 $('#kotori-menu .off').css('display','inline');

					 }
				 }else{
					alert('API ERROR : errorCode=' + xml.attr('errorCode'));
				 }
			 }
		 });
	},
	dummy:function(){
		$.get("/api/dummy");
	},
	releaseGiftMode:function(){
		$.ajax({
			 type: "POST",
			 url: "/api/releaseGiftMode",
			 error: function(){
				 alert('ERROR : Fail to access the API.');
			 },
			 success: function(res){
				 var xml = $(KOTORI.fn.parseFromString(res));
				 
				 if(xml.attr('status') == 'success'){
						
						if(location.href.indexOf('/giftcode/use/') > 0){
							location.replace('/guide/giftcode');
						}else if(location.href.indexOf('/order_ssl/confirm') > 0){
							location.replace('/order_ssl/guest2#payment');
						}else{
							location.reload(true);
						}
				 }else{
						alert('ERROR : Fail to release GIFT CODE MODE.'); 
				 }
			 }
		 });
	},
	toggleGiftArea:function(){
		var area = $('#gift-area');
		if(!area.length) return;
		$('#header .gift-mode').mouseover(function(){
			area.show();															 
		});
		$('#top-header .gift-mode').mouseover(function(){
			area.show();															 
		});
		area.mouseleave(function(){
			area.hide();															 
		});
		$('#top-header').mouseleave(function(){
			area.hide();															 
		});
	},
	slideshow:function(){
		
		//if(!$('#magazine').length) return;
		
		if(KOTORI.checkBrowser.ie6){		
			DD_belatedPNG.fix('.outline');
		}
	
		KOTORI.fadeDuration = 1000;
		KOTORI.fadeFastDuration = 500;
		KOTORI.slideshowWidth = 930;
		KOTORI.magazineLimit = $('#magazine dl').length;
		KOTORI.magazineLoaded = false;
		
		var outline = $('.outline');
		
		outline.mouseover(function(){
			$(this).parent().parent().addClass('over');
		});
		outline.mouseleave(function(){
			$(this).parent().parent().removeClass('over');
		});
		
		outline.click(function(){
			var vol = $(this).attr('href').replace('101','').match(/[0-9]{2}/);
			KOTORI.fn.showSlideshow(vol)
			return false;
		});
	
		if(location.href.indexOf('vol=') != -1){
			
			var vol = location.href.split('vol=');
			vol = vol[1];
			
			if(vol.length != 2) return;
					
			var slideTimer = setTimeout('KOTORI.fn.showSlideshow(' + vol + ')', 1000);
			
			KOTORI.preloadImage('/images/magazine/vol' + vol + '/image0101.jpg');
	
		}else{
			
			for(var i = KOTORI.magazineLimit; i > 0; i--){
				
				var vol = i;
				
				if(vol < 10){
					vol = '0' + vol;
				}

				KOTORI.preloadImage('/images/magazine/vol' + vol + '/image0101.jpg');
				KOTORI.magazineLoaded = true;

			}		
			
		}
	},
	showSlideshow:function(vol){
				
		if(vol == 0 || vol > KOTORI.magazineLimit) return;
			
		var slideshowOverlay = $('#slideshow-overlay');
	
		if(typeof vol == 'number' && vol < 10){
			vol = '0' + vol;
		}		
			
		KOTORI.fn.loadSlideshow(vol);
	
		KOTORI.fn.hideScrollbar();
		
		slideshowOverlay.fadeIn(KOTORI.fn.fadeDuration, KOTORI.fn.positSlideshow());
	},
	loadSlideshow:function(vol){
			
		var loadPath = '/101/magazine/' + vol + '.html';
		var loadId = '#slideshow-source';
	
		$('#slideshow-content').load(loadPath + ' ' + loadId, function(){
			var slideshowFrame = $('#slideshow-frame');
			var slideshowPages = $('.page');
		
			var countTotal = $('#count-total');
			var countHere = $('#count-here');
		
			KOTORI.pageTotal = slideshowPages.length;
			KOTORI.pageHere = 1;
			
			$('#slideshow-title span').addClass('vol' + vol);
			$('#slideshow-content').addClass('vol' + vol);
				
			KOTORI.fn.showCount(countHere, countTotal);
			
			$('#slideshow-prev').hide();
			
			KOTORI.fn.showButtons(countHere, countTotal);
		
			KOTORI.fn.setSlideEvent(countHere, countTotal);
		});
	
		
	},
	showCount:function(countHere, countTotal){
	
		countTotal.text(KOTORI.pageTotal);
		countHere.text(KOTORI.pageHere);
	
	},
	showButtons:function(){
			
		var slideshowPrev = $('#slideshow-prev');
		var slideshowNext = $('#slideshow-next');
	
		// first page
		if(KOTORI.pageHere <= 1){
			if(KOTORI.checkBrowser.ie){
				slideshowPrev.hide();		
				slideshowNext.show();
			}else{
				slideshowPrev.fadeOut(KOTORI.fadeFastDuration);		
				slideshowNext.fadeIn(KOTORI.fadeFastDuration);
			}
			
		// last page
		}else if(KOTORI.pageHere >= KOTORI.pageTotal){
			if(KOTORI.checkBrowser.ie){
				slideshowPrev.show();		
				slideshowNext.hide();
			}else{
				slideshowPrev.fadeIn(KOTORI.fadeFastDuration);		
				slideshowNext.fadeOut(KOTORI.fadeFastDuration);
			}
	
		// others
		}else{
			if(KOTORI.checkBrowser.ie){
				slideshowPrev.show();		
				slideshowNext.show();
			}else{
				slideshowPrev.fadeIn(KOTORI.fadeFastDuration);		
				slideshowNext.fadeIn(KOTORI.fadeFastDuration);		
			}
		}
		
	},
	setSlideEvent:function(countHere, countTotal){
	
		var slideshowPrev = $('#slideshow-prev');
		var slideshowNext = $('#slideshow-next');
		var kotoriAnchor = $('.kotori a');
	
		var slideshowContent = $('#slideshow-content');
			
		slideshowPrev.click(function(){
			$(this).unbind();
			slideshowContent.animate({
				left: - (KOTORI.pageHere - 2) * KOTORI.slideshowWidth
			},
			KOTORI.fadeDuration, 'easeInOutCirc', function(){
				KOTORI.fn.setSlideEvent(countHere, countTotal);
			});
			
			KOTORI.pageHere--;
			
			KOTORI.fn.showCount(countHere, countTotal);
	
			KOTORI.fn.showButtons(countHere, countTotal);
			
			return false;
		});
		slideshowNext.click(function(){
			$(this).unbind();
			slideshowContent.animate({
				left: KOTORI.pageHere * - KOTORI.slideshowWidth
			},
			KOTORI.fadeDuration, 'easeInOutCirc', function(){
				KOTORI.fn.setSlideEvent(countHere, countTotal);
			});
			
			KOTORI.pageHere++;
			
			KOTORI.fn.showCount(countHere, countTotal);
	
			KOTORI.fn.showButtons(countHere, countTotal);
			
			return false;
		});
		kotoriAnchor.mouseover(function(){
			$(this).parent().parent().addClass('over');
		});
		kotoriAnchor.mouseleave(function(){
			$(this).parent().parent().removeClass('over');
		});
		
	},
	positSlideshow:function(){
		
		var container = $('#container');
		var slideshowContainer = $('#slideshow-container');
		
		KOTORI.containerWidth = container.outerWidth();
		KOTORI.containerHeight = container.outerHeight();
			
		var slideshowContainerWidth = 972;
		var slideshowContainerHeight = 570;
	
		if(KOTORI.checkBrowser.ie6){
	
			slideshowForIE6();
			
			DD_belatedPNG.fix('.pngfix');
			
		}else{
			$(window).resize(function(){
	
				getSlideshowPosition();
				
				if(KOTORI.slideshowTop <= 0){
					slideshowContainer.css('top', slideshowContainerHeight / 2);
				}else{
					slideshowContainer.css('top', '50%');
				}
				
				if(KOTORI.slideshowLeft <= 0){
					slideshowContainer.css('left', slideshowContainerWidth / 2);
				}else{
					slideshowContainer.css('left', '50%');
				}
				
			});
		}
		KOTORI.fn.setCloseEvent();
		
		function slideshowForIE6(){
			
			var slideshowOverlay = $('#slideshow-overlay');
			var viewport = KOTORI.fn.getViewportRect();
			
			getSlideshowPosition();
			
			slideshowOverlay.css('height', KOTORI.containerHeight);
			slideshowContainer.css('top', KOTORI.slideshowTop + KOTORI.fn.getViewportRect().y);
					
			$(window).scroll(function(){
				var currentTop = KOTORI.slideshowTop + KOTORI.fn.getViewportRect().y;
				
				slideshowContainer.css('top', currentTop);
							
			});
			$(window).resize(function(){
																
				getSlideshowPosition();
				
				slideshowContainer.css('top', KOTORI.slideshowTop + KOTORI.fn.getViewportRect().y);
		
				if(KOTORI.slideshowLeft <= 0){
					slideshowContainer.css('left', slideshowContainerWidth / 2);
				}else{
					slideshowContainer.css('left', '50%');
				}
			});
		}
		
		function getSlideshowPosition(){
			
			KOTORI.slideshowTop = parseInt((KOTORI.fn.getViewportRect().height - slideshowContainerHeight) / 2);
			KOTORI.slideshowLeft = parseInt((KOTORI.fn.getViewportRect().width - slideshowContainerWidth) / 2);
					
			if(KOTORI.slideshowTop < 0){
				KOTORI.slideshowTop = 0;
			}
			if(KOTORI.slideshowLeft < 0){
				KOTORI.slideshowLeft = 0;
			}
		}
	},
	setCloseEvent:function(){
		
		// close button
		$('#slideshow-close a').click(function(){
																					 
			KOTORI.fn.resetSlideEvent();
	
			return false;
		});
	},
	resetSlideEvent:function(){
	
		if(KOTORI.checkBrowser.ie6 || KOTORI.checkBrowser.ie7){
			$('#slideshow-prev').unbind().hide();
			$('#slideshow-next').unbind().hide();
		}
		
		$('#slideshow-overlay').fadeOut(KOTORI.fadeDuration, function(){
	
			$('#slideshow-prev').unbind().hide();
			$('#slideshow-next').unbind().hide();
			
			$('#slideshow-title span').removeClass();
			$('#slideshow-content').removeClass();
	
			KOTORI.fn.showScrollbar();
	
			$('#slideshow-content').css('left',0);
	
			$('#slideshow-content').empty();
			
			if(!KOTORI.magazineLoaded){
				
				for(var i = KOTORI.magazineLimit; i > 0; i--){
					
					var vol = i;
					
					if(vol < 10){
						vol = '0' + vol;
					}
	
					KOTORI.preloadImage('/images/magazine/vol' + vol + '/image0101.jpg');
					KOTORI.magazineLoaded = true;
	
				}		
				
			}
	
		});
	},
	hideScrollbar:function(){
		if(KOTORI.checkBrowser.ie6 || KOTORI.checkBrowser.ie7){
			document.body.setAttribute('scroll','no');
			$('html').addClass('noscroll');
		}else{
			$(document.body).addClass('noscroll');
		}
	},
	showScrollbar:function(){
		if(KOTORI.checkBrowser.ie6 || KOTORI.checkBrowser.ie7){
			document.body.setAttribute('scroll','yes');			
			$('html').removeClass('noscroll');
		}else{
			$(document.body).removeClass('noscroll');
		}
	},
	setHeaderSearch:function(){
		
		var area = $('#search-area');
		
		if(!area.length) return;

		var textbox = $('#search-id');


		var searchButton = $('#search-start');
		
		$('#search-open').click(function(){
			area.fadeIn(300,function(){
				searchButton.fadeIn(300)
			});
			textbox.val('');
			textbox.focus();
		});
		$('#search-close').click(function(){
			area.fadeOut(300,function(){
				searchButton.hide();
				area.removeClass('error');				
			});				 			 
		});
		textbox.focus(function(){
			area.removeClass('error');													 
		});		
		$('#search-start').click(function(){
			var id = textbox.val();
						
			if(id.match(/[a-zA-Z0-9]{6}/) != null){
				
				$.ajax({
					 type: "GET",
					 url: "/api/searchDesign?goodsId=" + id,
					 dataType: "json",
					 error: function(){
						 alert('ERROR : Fail to access the API.');
					 },
					 success: function(res){
						 
						 if(res.status == 1){
							 
							 // kotori 101
							 if(res.model_id == 1){
								 
									location.href ='/101/set/' + res.goods_id;
								 
							 // kotori 201
							 }else if(res.model_id == 2){
								 
									location.href = '/201/set/' + res.goods_id;								 
								 
							 }else{
								 
								 alert('ERROR : model_id is not correct.');
								 
							 }
							 
						 }else if(res.status == 0){
							 
							area.addClass('error');
							
						 }
					 }
				 });

			}else{
				area.addClass('error');
			}
			
			return false;
		
		});
	},
	setModelTop:function(){
		
		$('.image').mouseover(function(){
			$(this).siblings('.title, .name, .summary').addClass('over');					
		});
		
		$('.image').mouseleave(function(){
			$(this).siblings('.title, .name, .summary').removeClass('over');															
		});
		
		$('.summary').mouseover(function(){
			$(this).siblings('.name').addClass('over');
		});
		
		$('.summary').mouseleave(function(){
			$(this).siblings('.name').removeClass('over');					
		});
		
		$('.name').mouseover(function(){
			$(this).siblings('.summary').addClass('over');					
		});
		
		$('.name').mouseleave(function(){
			$(this).siblings('.summary').removeClass('over');					
		});
		
		$('.items dt').mouseover(function(){
			$(this).find('.outline, .overlay').show();
		});

		$('.items dt').mouseleave(function(){
			$(this).find('.outline, .overlay').hide();
		});

		$('.love').mouseover(function(){
			$(this).addClass('loveOver');
		});
		
		$('.love').mouseleave(function(){
			$(this).removeClass('loveOver');
		});
		
		$('.hate').mouseover(function(){
			$(this).addClass('hateOver');
		});
		
		$('.hate').mouseleave(function(){
			$(this).removeClass('hateOver');
		});
	},
	setVidual101:function(){
		
		// set vars
		
		KOTORI.positions = {
			'category1a':-3500,
			'category2a':-3000,
			'category3a':-2500,
			'category4a':-2000,
			'category5a':-1500,
			'category6a':-1000,
			'category7a':-500,
			'category1b':0,
			'category2b':500,
			'category3b':1000,
			'category4b':1500,
			'category5b':2000,
			'category6b':2500,
			'category7b':3000
		}
		
		KOTORI.positionMaps = {
			'category1a':{
				'category1a':0, 'category2a':500, 'category3a':1000, 'category4a':1500, 'category5a':2000, 'category6a':2500, 'category7a':3000,
				'category1b':-3500, 'category2b':-3000, 'category3b':-2500, 'category4b':-2000, 'category5b':-1500, 'category6b':-1000, 'category7b':-500				
			},
			'category2a':{
				'category1a':-500, 'category2a':0, 'category3a':500, 'category4a':1000, 'category5a':1500, 'category6a':2000, 'category7a':2500,
				'category1b':3000, 'category2b':-3500, 'category3b':-3000, 'category4b':-2500, 'category5b':-2000, 'category6b':-1500, 'category7b':-1000				
			},
			'category3a':{
				'category1a':-1000, 'category2a':-500, 'category3a':0, 'category4a':500, 'category5a':1000, 'category6a':1500, 'category7a':2000,
				'category1b':2500, 'category2b':3000, 'category3b':-3500, 'category4b':-3000, 'category5b':-2500, 'category6b':-2000, 'category7b':-1500				
			},
			'category4a':{
				'category1a':-1500, 'category2a':-1000, 'category3a':-500, 'category4a':0, 'category5a':500, 'category6a':1000, 'category7a':1500,
				'category1b':2000, 'category2b':2500, 'category3b':3000, 'category4b':-3500, 'category5b':-3000, 'category6b':-2500, 'category7b':-2000				
			},
			'category5a':{
				'category1a':-2000, 'category2a':-1500, 'category3a':-1000, 'category4a':-500, 'category5a':0, 'category6a':500, 'category7a':1000,
				'category1b':1500, 'category2b':2000, 'category3b':2500, 'category4b':3000, 'category5b':-3500, 'category6b':-3000, 'category7b':-2500				
			},
			'category6a':{
				'category1a':-2500, 'category2a':-2000, 'category3a':-1500, 'category4a':-1000, 'category5a':-500, 'category6a':0, 'category7a':500,
				'category1b':1000, 'category2b':1500, 'category3b':2000, 'category4b':2500, 'category5b':3000, 'category6b':-3500, 'category7b':-3000				
			},
			'category7a':{
				'category1a':-3000, 'category2a':-2500, 'category3a':-2000, 'category4a':-1500, 'category5a':-1000, 'category6a':-500, 'category7a':0,
				'category1b':500, 'category2b':1000, 'category3b':1500, 'category4b':2000, 'category5b':2500, 'category6b':3000, 'category7b':-3500				
			},
			'category1b':{
				'category1a':-3500, 'category2a':-3000, 'category3a':-2500, 'category4a':-2000, 'category5a':-1500, 'category6a':-1000, 'category7a':-500,
				'category1b':0, 'category2b':500, 'category3b':1000, 'category4b':1500, 'category5b':2000, 'category6b':2500, 'category7b':3000				
			},
			'category2b':{
				'category1a':3000, 'category2a':-3500, 'category3a':-3000, 'category4a':-2500, 'category5a':-2000, 'category6a':-1500, 'category7a':-1000,
				'category1b':-500, 'category2b':0, 'category3b':500, 'category4b':1000, 'category5b':1500, 'category6b':2000, 'category7b':2500				
			},
			'category3b':{
				'category1a':2500, 'category2a':3000, 'category3a':-3500, 'category4a':-3000, 'category5a':-2500, 'category6a':-2000, 'category7a':-1500,
				'category1b':-1000, 'category2b':-500, 'category3b':0, 'category4b':500, 'category5b':1000, 'category6b':1500, 'category7b':2000				
			},
			'category4b':{
				'category1a':2000, 'category2a':2500, 'category3a':3000, 'category4a':-3500, 'category5a':-3000, 'category6a':-2500, 'category7a':-2000,
				'category1b':-1500, 'category2b':-1000, 'category3b':-500, 'category4b':0, 'category5b':500, 'category6b':1000, 'category7b':1500				
			},
			'category5b':{
				'category1a':1500, 'category2a':2000, 'category3a':2500, 'category4a':3000, 'category5a':-3500, 'category6a':-3000, 'category7a':-2500,
				'category1b':-2000, 'category2b':-1500, 'category3b':-1000, 'category4b':-500, 'category5b':0, 'category6b':500, 'category7b':1000				
			},
			'category6b':{
				'category1a':1000, 'category2a':1500, 'category3a':2000, 'category4a':2500, 'category5a':3000, 'category6a':-3500, 'category7a':-3000,
				'category1b':-2500, 'category2b':-2000, 'category3b':-1500, 'category4b':-1000, 'category5b':-500, 'category6b':0, 'category7b':500				
			},
			'category7b':{
				'category1a':500, 'category2a':1000, 'category3a':1500, 'category4a':2000, 'category5a':2500, 'category6a':3000, 'category7a':-3500,
				'category1b':-3000, 'category2b':-2500, 'category3b':-2000, 'category4b':-1500, 'category5b':-1000, 'category6b':-500, 'category7b':0				
			}
		}
		
		KOTORI.currentNum = 1;
		KOTORI.currentNumBuffer = 1;
		KOTORI.currentGroup = 'b';
		
		// clone vidual elements for wide screen
		
		var viduals = $('.viduals');
		var groupA = $('.vidual').clone();
		viduals.prepend(groupA);
		
		var vidual = $('.vidual');
		
		for(var i = 0; i < vidual.length; i++){
			
			if(i < 7){
				$(vidual[i]).addClass('category' + (i + 1) + 'a');			
			}else if(i < 14){
				$(vidual[i]).addClass('category' + (i - 6) + 'b');			
			}else{
				$(vidual[i]).addClass('category' + (i - 13) + 'c');			
			}
			
		}
		
		var tools = $('.menu-outer, .pointer');
		var loading = $('.loading');
		var shuffle = $('.shuffle');
		var scrapbookVote = $('#scrapbook-area .flash');
		
		// events
		
		KOTORI.fn.setVidualEvent();	// vidual area event
		KOTORI.fn.setVidualCloseEvent(); // close button event
		KOTORI.fn.setVidualPointerEvent(); // pointer event
		
		// start

		KOTORI.vidualTimer = setTimeout(function(){

			if(KOTORI.checkBrowser.ie6){		
				DD_belatedPNG.fix('.menu-inner, .bottom');
			}

			vidual.fadeIn(1000, function(){
																	 
				clearTimeout(KOTORI.vidualTimer);
																	 
				if(KOTORI.checkBrowser.ie){
					
					tools.show();
					shuffle.show();
					scrapbookVote.show();
					
				}else{
					
					KOTORI.menuTimer = setTimeout(function(){
					
							tools.fadeIn(1000, function(){
																					
								shuffle.show();
								scrapbookVote.show();

								clearTimeout(KOTORI.menuTimer);
								
							});
			
					}, 1000);
					
				}
				
				loading.remove();
																	 					
			});												 
		}, 2000);
		
		KOTORI.fn.startViduals();

	},
	setVidualEvent:function(vidual){
				
		var vidualEles = vidual || $('.vidual');
						
		vidualEles.click(function(){
															
			// set category
		
			var vidual = $(this);					
			var destNum = parseInt(vidual.attr('class').match(/[0-9]/));
			
			KOTORI.fn.setCategoryGroup(destNum);						
			KOTORI.currentNum = destNum;			
			var category = 'category' + KOTORI.currentNum + KOTORI.currentGroup;
			
			KOTORI.fn.stopViduals();			
			KOTORI.fn.slideVidualToPosition(category);
			KOTORI.fn.rearrangeVidual();
			
			vidual.unbind('click');
						
			KOTORI.fn.resetVidualPointerEvent();
			
			return false;
		
		});
		
		vidualEles.mouseover(function(){
			$(this).find('.vidual-outline').show();
		});
		
		vidualEles.mouseleave(function(){
			$(this).find('.vidual-outline').hide();
		});
		
	},
	setVidualCloseEvent:function(){
		
		if(KOTORI.checkBrowser.ie8){
			$('.item-list-inner').hide();
		}
		
		$('.close').click(function(){
															 
			var itemList = $(this).parents('.item-list');
			
			if(KOTORI.checkBrowser.ie8){
				
				var itemListInner = itemList.find('.item-list-inner');
				
				itemListInner.fadeOut(150,function(){

					itemList.fadeOut(350, function(){
						KOTORI.fn.startViduals();
						KOTORI.fn.setVidualEvent();
					});				

				});

			}else{
				
				itemList.fadeOut(350, function(){
					KOTORI.fn.startViduals();
					KOTORI.fn.setVidualEvent();
				});				
			}
															 
		});
	},
	setVidualPointerEvent:function(){
		
		var pointers = $('.pointer a');
		var here = $('.pointer .here a');
		
		pointers.click(function(){
														
			// set category
		
			var pointer = $(this);
			var liEle = pointer.parent('li')
			
			$('.pointer li').removeClass('here');
		
			var destNum = parseInt(liEle.attr('class').replace('category',''));

			KOTORI.fn.setCategoryGroup(destNum);						
			KOTORI.currentNum = destNum;			
			var category = 'category' + KOTORI.currentNum + KOTORI.currentGroup;
			
			liEle.addClass('here');
			
			KOTORI.fn.stopViduals();		
			KOTORI.fn.slideVidualToPosition(category);
			KOTORI.fn.rearrangeVidual();
						
			pointers.unbind('click');
			pointers.click(function(){return false;});

			return false;
		
		});
		
		here.unbind('click');
		here.click(function(){return false;});
		
	},
	resetVidualPointerEvent:function(){
				
		var className = 'category' + KOTORI.currentNum;
		
		
		$('.here').removeClass('here');
		$('.' + className).addClass('here');

	},
	startViduals:function(){
		
		var viduals = $('.viduals');
		var slideIntervalTime = 20;
		
		if(KOTORI.checkBrowser.ie8){
			slideIntervalTime = 80;
		}

		KOTORI.slideTimer = setInterval(function(){
		
			var left = parseInt(viduals.css('left').replace('px',''));
			
			if((left % 45) == 0){
				
				KOTORI.fn.changeVidualPointer(left);
				
			}
									
			viduals.css('left', left - 1);			
																		
		},slideIntervalTime);

	},
	stopViduals:function(){		
		clearInterval(KOTORI.slideTimer);
	},
	setCategoryGroup:function(destNum){
		
		var maxDist = 3;
		var centerNum = 4;
								
		if(KOTORI.currentNum < centerNum){
			
			if(destNum > (KOTORI.currentNum + maxDist)){
				
				if(KOTORI.currentGroup == 'a'){
					
					KOTORI.currentGroup = 'b';
					
				}else if(KOTORI.currentGroup == 'b'){

					KOTORI.currentGroup = 'a';

				}
			}
			
		}else	if(KOTORI.currentNum > centerNum){
			
			if(destNum < (KOTORI.currentNum - maxDist)){

				if(KOTORI.currentGroup == 'a'){
					
					KOTORI.currentGroup = 'b';
					
				}else if(KOTORI.currentGroup == 'b'){

					KOTORI.currentGroup = 'a';

				}
			}			
		}	
		
	},
	slideVidualToPosition:function(category){
		
		var easingType = 'easeInOutCirc';
		var durationTime = 500;
		
		var left = -KOTORI.positions[category];
				
		$('.viduals').animate({
			'left': left										
		}, durationTime, easingType, function(){
			
			//KOTORI.fn.startViduals();
			KOTORI.fn.setVidualPointerEvent();		
			KOTORI.fn.showItemList(category);
			
		});
		
	},
	showItemList:function(category){
		
		var displayedVidual = $('.item-list:visible');
		var vidual = $('.' + category);
		
		if(KOTORI.checkBrowser.ie8){
			
			displayedVidual.find('.item-list-inner').fadeOut(150, function(){
				displayedVidual.fadeOut(350);
			});			
			vidual.find('.item-list').fadeIn(250, function(){
				vidual.find('.item-list-inner').fadeIn(150);															 
			});
			
		}else{
			
			displayedVidual.fadeOut(350);		
			vidual.find('.item-list').fadeIn(350);
			
		}
		
		vidual.unbind('click');
		
		KOTORI.fn.setVidualEvent(displayedVidual.parents('.vidual'));
		
	},
	changeVidualPointer:function(left){
		
		var val = Math.abs(left) % 3500;
		var cat;
		
		if(val < 301){
			//category1
			if(left <= 0){
				cat = 1;
			}else{
				cat = 7;
			}
		}else if(val < 801){
			//category2
			if(left < 0){
				cat = 2;
			}else{
				cat = 6;
			}
		}else if(val < 1301){
			//category3
			if(left < 0){
				cat = 3;
			}else{
				cat = 5;
			}
		}else if(val < 1801){
			//category4
			if(left < 0){
				cat = 4;
			}else{
				cat = 4;
			}
		}else if(val < 2301){
			//category5
			if(left < 0){
				cat = 5;
			}else{
				cat = 3;
			}
		}else if(val < 2801){
			//category6
			if(left < 0){
				cat = 6;
			}else{
				cat = 2;
			}
		}else if(val < 3300){
			//category7
			if(left < 0){
				cat = 7;
			}else{
				cat = 1;
			}
		}else{
			//category1
			if(left <= 0){
				cat = 1;
			}else{
				cat = 7;
			}
		}
		
		if(KOTORI.currentNumBuffer == cat){
			
			if(KOTORI.currentNum == KOTORI.currentNumBuffer) return;
						
			KOTORI.currentNum = KOTORI.currentNumBuffer;
			
			if(KOTORI.currentNum == 1){
				if(KOTORI.currentGroup == 'a'){
					KOTORI.currentGroup = 'b';
				}else{
					KOTORI.currentGroup = 'a';					
				}
			}
			
			$('.here').removeClass('here');
			$('.category' + KOTORI.currentNum).addClass('here');
			
			KOTORI.fn.setVidualPointerEvent();

			KOTORI.fn.rearrangeVidual();

		}else{
			KOTORI.currentNumBuffer = cat;
		}
				
	},
	rearrangeVidual:function(){
				
		var currentCategory = 'category' + KOTORI.currentNum + KOTORI.currentGroup;
		var currentCategoryPosition = KOTORI.positions[currentCategory];

		KOTORI.positions = {
			'category1a':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category1a,
			'category2a':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category2a,
			'category3a':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category3a,
			'category4a':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category4a,
			'category5a':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category5a,
			'category6a':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category6a,
			'category7a':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category7a,
			'category1b':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category1b,
			'category2b':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category2b,
			'category3b':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category3b,
			'category4b':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category4b,
			'category5b':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category5b,
			'category6b':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category6b,
			'category7b':currentCategoryPosition + KOTORI.positionMaps[currentCategory].category7b
		}
		
		$('div.vidual').each(function(){
			var vidual = $(this);
			var vidualClass = vidual.attr('class').match(/category../);
			
			vidual.css({'left': KOTORI.positions[vidualClass]});
			
		});
		
	},
	setTopVidual:function(){
		
		KOTORI.kotori101 = $('.kotori101');
		KOTORI.kotori201 = $('.kotori201');
		KOTORI.selector101 = $('.kotori101 a');
		KOTORI.selector201 = $('.kotori201 a');
		KOTORI.vidual101 = $('#kotori-vidual101');
		KOTORI.vidual201 = $('#kotori-vidual201');

		KOTORI.intro101 = $('#kotori-vidual101 .intro');
		KOTORI.intro201 = $('#kotori-vidual201 .intro');
		KOTORI.images101 = $('#kotori-vidual101 .images');
		KOTORI.images201 = $('#kotori-vidual201 .images');
		
		KOTORI.imageSets = [
			['/images/top/vidual_201_image1.jpg','/images/top/vidual_201_image2.jpg','/images/top/vidual_201_image3.jpg'],
			['/images/top/vidual_201_image4.jpg','/images/top/vidual_201_image5.jpg','/images/top/vidual_201_image6.jpg'],
			['/images/top/vidual_201_image7.jpg','/images/top/vidual_201_image8.jpg','/images/top/vidual_201_image9.jpg']
		];
		
		KOTORI.imageSetNumber = parseInt(Math.random() * 3);
		
		var menu = $('#kotori-menu1, #kotori-menu2');
		var about = $('#kotori-about');

		var contents = $('#contents');
		var footer = $('#footer');

		var aboutButton = $('#kotori-menu2 .about');
		var closeButton = $('.close');
				
		var menuTimer;
		var openingTimer;
		
		var menuTimeout = 5000;
		var duration = 500;

		if(KOTORI.checkBrowser.ie6){
			menuTimeout = 7000;
		}
		
		menuTimer = setTimeout(function(){

			if(KOTORI.checkBrowser.ie6){
				if(DD_belatedPNG){
					DD_belatedPNG.fix('#kotori-menu1, #kotori-menu2, #kotori-menu1 a, #kotori-menu2 a, #kotori-menu2 li');				
				}
			}

			if(KOTORI.checkBrowser.ie){
				
				menu.show();

			}else{
				
				menu.fadeIn(duration);

			}
			
			var contentsTimer = setTimeout(function(){
																							
				contents.fadeIn(duration);
				
				var footerTimer = setTimeout(function(){
					footer.fadeIn(duration);																																													
				},300);
				
			},300);

			KOTORI.fn.rotateTopics();

			clearTimeout(menuTimer);

		}, menuTimeout);
		
		openingTimer = setTimeout(function(){

			//KOTORI.selector201.find('img').attr('src', '/images/top/button_201.png');
			
			/*KOTORI.selector101.click(function(){
				
				KOTORI.fn.showTop101Vidual();
				
				return false;
																 
			});*/
			
			/*KOTORI.selector201.click(function(){
																 
				KOTORI.fn.showTop201Vidual();

				return false;

			});*/

			KOTORI.fn.showTop201Vidual(true);
			clearTimeout(openingTimer);
			
		}, 700);
						
		KOTORI.vidual101.click(function(){
			window.location.href = '/101/';					
		});
		
		KOTORI.vidual201.click(function(){
			window.location.href = '/201/';																
		});
		
		aboutButton.click(function(){
															 
			if(KOTORI.vidualModel == 101){

				clearTimeout(KOTORI.slide101Timeout);							

				KOTORI.clearTimer = setTimeout(function(){
					clearTimeout(KOTORI.slide101Timeout);
					clearTimeout(KOTORI.clearTimer);
				},2000);
				
			}else{
				
				clearInterval(KOTORI.slide201Interval);

				KOTORI.clearTimer = setTimeout(function(){
					clearInterval(KOTORI.slide201Interval);
					clearTimeout(KOTORI.clearTimer);
				},4000);
				
			}
															 
			if(KOTORI.checkBrowser.ie){
				about.show();
				
				if(KOTORI.checkBrowser.ie6){
					DD_belatedPNG.fix('.top, .bottom, .middle');							
				}
				
			}else{
				about.fadeIn(400);
			}
			
			return false;
															
		});
		
		closeButton.click(function(){
			
			if(KOTORI.checkBrowser.ie){
				about.hide();
			}else{
				about.fadeOut(400);
			}
			
			clearTimeout(KOTORI.clearTimer);

			if(KOTORI.vidualModel == 101){
				
				KOTORI.fn.restartTop101Vidual();		
				
			}else{
				
				KOTORI.fn.restartTop201Vidual();		
				
			}

		});
		
		KOTORI.fn.setDetailCursor();
		
	},
	setDetailCursor:function(){
		var mouseX, mouseY;
		var cursor = $('#tooltip');
		var visual = $('#top-vidual');
		var menu = $('#kotori-menu1, #kotori-menu2, #kotori-about');
		var duration = 200;
		
		//if(KOTORI.checkBrowser.ie6) duration = 0;
		
		var showDelay = 400;
		var hideDelay = 00;
		
		KOTORI.cursorOnMenu = false;								
		
		$('html').mousemove(function(e){
																 
			clearTimeout(KOTORI.showTimer);
			
			KOTORI.hideTimer = setTimeout(function(){
				cursor.fadeOut(duration);																					 
				clearTimeout(KOTORI.hideTimer);
			},hideDelay);
			
      mouseX = e.pageX + 7;
			mouseY = e.pageY - 9;
			
			if(mouseY <= 580){

				cursor.css({
					top:mouseY,
					left:mouseX
				});

				KOTORI.showTimer = setTimeout(function(){
					if(!KOTORI.cursorOnMenu) cursor.fadeIn(duration);
					clearTimeout(KOTORI.showTimer);
				},showDelay);
				
			}
			
		});
		
		menu.mouseover(function(){
			KOTORI.cursorOnMenu = true;										
		});
		
		menu.mouseleave(function(){
			KOTORI.cursorOnMenu = false;										
		});
		
	},
	showTop101Vidual:function(){

		var duration = 250;
		var introDuration = 1200;
		var slideDuration = 1200;
		
		var slideStartTime = 1400;
		var slideEndTime = 10000;
		
		var easingType = 'easeInOutCirc';

		KOTORI.vidualModel = 101;

		clearTimeout(KOTORI.slide101Timeout);
		clearInterval(KOTORI.slide201Interval);
				
		KOTORI.vidual201.hide();
		KOTORI.images201.hide();
		
		//KOTORI.selector101.unbind('click');
		//KOTORI.selector201.unbind('click');

		//KOTORI.selector101.click(function(){return false;});
		//KOTORI.selector201.click(function(){return false;});

		KOTORI.selector101.addClass('here');
		KOTORI.selector201.removeClass('here');
		
		$('#tooltip span').removeClass('tip201');
		$('#tooltip span').addClass('tip101');
		
		if(KOTORI.checkBrowser.ie6){
			KOTORI.selector101.css('background-position','bottom left');
			KOTORI.selector201.css('background-position','0px 2px');
			KOTORI.selector201.mouseover(function(){
				KOTORI.selector201.css('background-position','bottom left');																	
			});
			KOTORI.selector201.mouseleave(function(){
				KOTORI.selector201.css('background-position','0px 2px');																	
			});
			KOTORI.selector101.unbind('mouseleave');
		}

		KOTORI.intro101.fadeIn(introDuration, function(){

			KOTORI.images101.show();			

			KOTORI.introTimeout = setTimeout(function(){
	
				KOTORI.intro101.fadeOut(slideDuration);
				
				$('#kotori-vidual101 .image').fadeIn(slideDuration);
				
				/*KOTORI.selector201.click(function(){
																	 
					KOTORI.fn.showTop201Vidual();
					
					return false;
					
				});*/			
								
			},slideStartTime);
			
		});
		
		clearInterval(KOTORI.slide201Interval);
		
		KOTORI.slide101Timeout = setTimeout(function(){
																		
			KOTORI.fn.showTop201Vidual();
			clearTimeout(KOTORI.slide101Timeout);
													
		},slideEndTime);
																 
		/*KOTORI.kotori101.animate({
			'height':179
		}, duration, easingType);
		KOTORI.kotori201.animate({
			'height':25
		}, duration, easingType, function(){
			
			KOTORI.selector101.find('img').attr('src', '/images/top/button_101.png');
			KOTORI.selector101.addClass('here');

			KOTORI.selector201.find('img').attr('src', '/images/top/button_201_off.png');
			KOTORI.selector201.removeClass('here');
			
			KOTORI.vidual101.fadeIn(500);
			KOTORI.vidual201.fadeOut(500);
						
		});*/
		KOTORI.vidual101.fadeIn(500);
		KOTORI.vidual201.fadeOut(500);
				
	},
	showTop201Vidual:function(isInitial){

		var duration = 250;
		var introDuration = 1100;
		var slideDuration = 1100;
		
		var slideStartTime = 1400;
		var slideIntervalTime = 4500;
		
		var easingType = 'easeInOutCirc';

		KOTORI.slideHereNum = 1;
		KOTORI.vidualModel = 201;
		
		clearTimeout(KOTORI.slide101Timeout);
		clearInterval(KOTORI.slide201Interval);

		KOTORI.vidual101.hide();
		KOTORI.images101.hide();
		
		$('#kotori-vidual201 .image1').attr('src',KOTORI.imageSets[KOTORI.imageSetNumber][0]);
		$('#kotori-vidual201 .image2').attr('src',KOTORI.imageSets[KOTORI.imageSetNumber][1]).hide();
		$('#kotori-vidual201 .image3').attr('src',KOTORI.imageSets[KOTORI.imageSetNumber][2]).hide();
		
		if(KOTORI.imageSetNumber > 1){
			KOTORI.imageSetNumber = 0;
		}else{
			KOTORI.imageSetNumber++;			
		}

		//$('#kotori-vidual201 .image2, #kotori-vidual201 .image3').hide();
		$('#kotori-vidual201 .here').hide().removeClass('here');
		$('#kotori-vidual201 .image1').addClass('here');

		//KOTORI.selector101.unbind('click');
		//KOTORI.selector201.unbind('click');

		//KOTORI.selector101.click(function(){return false;});
		//KOTORI.selector201.click(function(){return false;});

		KOTORI.selector101.removeClass('here');
		KOTORI.selector201.addClass('here');

		$('#tooltip span').removeClass('tip101');
		$('#tooltip span').addClass('tip201');
		
		if(KOTORI.checkBrowser.ie6){
			KOTORI.selector101.css('background-position','0px 2px');
			KOTORI.selector201.css('background-position','bottom left');
			KOTORI.selector101.mouseover(function(){
				KOTORI.selector101.css('background-position','bottom left');																	
			});
			KOTORI.selector101.mouseleave(function(){
				KOTORI.selector101.css('background-position','0px 2px');																	
			});
			KOTORI.selector201.unbind('mouseleave');
		}

		KOTORI.intro201.fadeIn(introDuration, function(){

			KOTORI.images201.show();

			KOTORI.introTimeout = setTimeout(function(){
																									
				KOTORI.intro201.fadeOut(slideDuration);
				
				$('#kotori-vidual201 .here').fadeIn(slideDuration, function(){
																																		
					KOTORI.slide201Interval = setInterval(function(){
						var here = $('#kotori-vidual201 .here');

						if(KOTORI.slideHereNum == 3){

							KOTORI.slideHereNum = 1;
							
							$('.' + 'image' + KOTORI.slideHereNum).show().addClass('here');
							here.hide().removeClass('here');
							
							KOTORI.fn.showTop101Vidual();
							
						}else{
							KOTORI.slideHereNum += 1;

							$('.' + 'image' + KOTORI.slideHereNum).fadeIn(slideDuration).addClass('here');
							here.fadeOut(slideDuration).removeClass('here');

						}
						
					},slideIntervalTime);
																																					
				});
				
				if(isInitial){
					for(var i = 0;i < 3;i++){
						for(var j = 0;j < 3;j++){
							KOTORI.preloadImage(KOTORI.imageSets[i][j]);
						}
					}
				}

				/*KOTORI.selector101.click(function(){
					
					KOTORI.fn.showTop101Vidual();
					
					return false;
																	 
				});*/

			},slideStartTime);
			
			
		});
		
		if(!isInitial){		
			/*KOTORI.kotori101.animate({
				'height':25
			}, duration, easingType);
			KOTORI.kotori201.animate({
				'height':179
			}, duration, easingType, function(){
	
				KOTORI.selector201.find('img').attr('src', '/images/top/button_201.png');
				KOTORI.selector201.addClass('here');
	
				KOTORI.selector101.find('img').attr('src', '/images/top/button_101_off.png');
				KOTORI.selector101.removeClass('here');
	
				KOTORI.vidual201.fadeIn(500);
				KOTORI.vidual101.fadeOut(500);
	
			});*/
			KOTORI.vidual201.fadeIn(500);
			KOTORI.vidual101.fadeOut(500);
		}
	},
	restartTop101Vidual:function(){
		
		var slideEndTime = 5000;
				
		clearTimeout(KOTORI.slide101Timeout);
		clearInterval(KOTORI.slide201Interval);

		KOTORI.slide101Timeout = setTimeout(function(){
																		
			KOTORI.fn.showTop201Vidual();
			clearTimeout(KOTORI.slide101Timeout);
													
		},slideEndTime);
																 		
	},
	restartTop201Vidual:function(){

		var duration = 250;
		var slideDuration = 1100;
		
		var slideStartTime = 1400;
		var slideIntervalTime = 4400;

		KOTORI.vidualModel = 201;

		clearTimeout(KOTORI.slide101Timeout);
		clearInterval(KOTORI.slide201Interval);
			
		$('#kotori-vidual201 .here').fadeIn(slideDuration, function(){
																																
			KOTORI.slide201Interval = setInterval(function(){
				var here = $('#kotori-vidual201 .here');
				
				if(KOTORI.slideHereNum == 3){

					KOTORI.slideHereNum = 1;
					
					$('.' + 'image' + KOTORI.slideHereNum).show().addClass('here');
					here.hide().removeClass('here');
						
					KOTORI.fn.showTop101Vidual();
					
				}else{
					KOTORI.slideHereNum += 1;
				}
				
				$('.' + 'image' + KOTORI.slideHereNum).fadeIn(slideDuration).addClass('here');
				here.fadeOut(slideDuration).removeClass('here');
				
			},slideIntervalTime);
																																			
		});
		
	},	
	positLogoForIE6:function(logo, windowWidth, vidualWidth){
						
		var minWidth = 970;
		var minLeft = -100;
		var maxLeft = parseInt((vidualWidth - minWidth) / 2) - 80;
		
		//if(windowWidth < vidualWidth){
			
			var left = parseInt((vidualWidth - windowWidth) / 2) - 100;
						
			if(minLeft < left && left < maxLeft){
				logo.css('left', left);						
			}else if(left <= minLeft){
				logo.css('left', minLeft);				
			}else if(maxLeft <= left){
				logo.css('left', maxLeft);				
			}
		//}
		
	},
	positLogo:function(logo, windowWidth, vidualWidth, scrollY){

		var absoluteLeft = -100;
		var fixedTop = 40;
		var fixedLeft = 40;

		if(windowWidth > vidualWidth){
			
			logo.css({
				'position': 'absolute',
				'left': absoluteLeft
			});
				
		}else{
									
			var top = fixedTop - scrollY;
						
			logo.css({
				'position': 'fixed',
				'top': top,
				'left': fixedLeft
			});
		}
	},
	positMenu:function(menu, windowWidth, vidualWidth){

		var minRight = -110;
		var maxDiff = 120;

		if(windowWidth > vidualWidth){
			
			menu.css({
				'right': minRight
			});
				
		}else{
			
			var diff = parseInt((vidualWidth - windowWidth) / 2);
			
			if(diff < maxDiff){
				menu.css({
					'right': minRight + diff
				});
			}else{
				menu.css({
					'right': minRight + maxDiff
				});
				
			}
		}
	},
	open201Vidual:function(vidualArea){

		var duration = 0;
		var giftModeOffset = 107;
		var normalModeOffset = 97;
		var flashId = 'vidual201';
		
		var vidualArea = vidualArea || $('#kotori201-vidual');
		//var container = $('#container');

		//KOTORI.fn.hideScrollbar();
		
		var windowWidth = KOTORI.fn.getViewportRect().width;
		var windowHeight = KOTORI.fn.getViewportRect().height;
		var scrollY = KOTORI.fn.getViewportRect().y;
		//var containerHeight = container.outerHeight();
		
		if(KOTORI.giftmode){
			var	offsetY = giftModeOffset;
		}else{
			var	offsetY = normalModeOffset;
		}
		
		if(KOTORI.checkBrowser.opera){
			vidualArea.css({
				'position': 'fixed',
				'top': 0,
				'height': windowHeight
			});
		}else{
			vidualArea.css({
				'top': scrollY,
				'height': windowHeight
			});
			
		}
		
		KOTORI.fn.swfTarget(flashId).open201VidualComplete(offsetY, scrollY, windowWidth, windowHeight); // callback flash method

		$(window).resize(function(){
			var windowHeight = KOTORI.fn.getViewportRect().height;
			
			vidualArea.css({
				'height': windowHeight
			});																
		});
		
		if(KOTORI.checkBrowser.firefox){
			$(window).scroll(function(){
				var scrollY = KOTORI.fn.getViewportRect().y;
				
				vidualArea.css({
					'top': scrollY
				});
			});			
		}else{
			KOTORI.fn.hideScrollbar();
		}

	},
	close201Vidual:function(vidualArea){

		var duration = 0;
		var giftModeOffset = 107;
		var normalModeOffset = 97;
		var flashId = 'vidual201';
		
		var vidualArea = vidualArea || $('#kotori201-vidual');
		
		//KOTORI.fn.showScrollbar();		

		var windowWidth = KOTORI.fn.getViewportRect().width;
		var windowHeight = KOTORI.fn.getViewportRect().height;
		var scrollY = KOTORI.fn.getViewportRect().y;

		if(KOTORI.giftmode){
			var	offsetY = giftModeOffset;
		}else{
			var	offsetY = normalModeOffset;
		}
		
		$('#kotori201-vidual').css({
			'position': 'absolute',
			'top': offsetY,
			'height': 580		
		});
		
		KOTORI.fn.swfTarget(flashId).close201VidualComplete(offsetY, scrollY, windowWidth, windowHeight); // callback flash method

		$(window).unbind();
		
		if(!KOTORI.checkBrowser.firefox){
			KOTORI.fn.showScrollbar();			
		}

	},
	hideScrollbarForNonFx:function(){
		if(KOTORI.checkBrowser.ie6 || KOTORI.checkBrowser.ie7){
			document.body.setAttribute('scroll','no');
			$('html').addClass('noscroll');
		}else if(!KOTORI.checkBrowser.firefox){
			$(document.body).addClass('noscroll');
		}
	},
	get201WindowInfo:function(){

		var giftModeOffset = 107;
		var normalModeOffset = 97;
		var flashId = 'vidual201';

		var windowWidth = KOTORI.fn.getViewportRect().width;
		var windowHeight = KOTORI.fn.getViewportRect().height;
		var scrollY = KOTORI.fn.getViewportRect().y;

		if(KOTORI.giftmode){
			var	offsetY = giftModeOffset;
		}else{
			var	offsetY = normalModeOffset;
		}
		
		KOTORI.fn.swfTarget(flashId).set201WindowInfo(offsetY, scrollY, windowWidth, windowHeight); // callback flash method
		
	},
	show201LowerContent:function(){
		//if(KOTORI.checkBrowser.firefox){
			$('#header, #contents, #footer').css('visibility','visible');
		//}
	},
	hide201LowerContent:function(){
		//if(KOTORI.checkBrowser.firefox){
			$('#header, #contents, #footer').css('visibility','hidden');
		//}
	},
	swfTarget:function(str){	// for External Interface
				
		if(KOTORI.checkBrowser.ie){
			return window[str];
		} else {
			return document[str];
		}

	},
	rotateTopics:function(){
		
		KOTORI.topics = $('#topics');
		KOTORI.topicsPosition = 1;
		
		var topicsHeight = 23;		
		var topicsIntervalTime = 6000;
		var topicsDuration = 600;
		
		KOTORI.topicsTimer = setInterval(function(){
			var topicsTop = parseInt(KOTORI.topics.css('top').replace('px',''));
			
			KOTORI.topics.animate({
				'top': topicsTop - topicsHeight							 
			},topicsDuration, function(){
				
				var prev = $('.topics' +  KOTORI.topicsPosition);
				var prevTop = parseInt(prev.css('top').replace('px',''));
				
				prev.css({
					'top': prevTop + topicsHeight * 3												 
				})
				
				if(KOTORI.topicsPosition >= 3){
					KOTORI.topicsPosition = 1;
				}else{
					KOTORI.topicsPosition += 1;
				}
				
			});
			
																					 
		},topicsIntervalTime);
		
		KOTORI.topics.mouseover(function(){
			clearInterval(KOTORI.topicsTimer);
		});
		
		KOTORI.topics.mouseleave(function(){
			KOTORI.fn.restartRotateTopics();
		});
		
	},
	restartRotateTopics:function(){
		
		var topicsHeight = 23;		
		var topicsIntervalTime = 6000;
		var topicsDuration = 600;
		
		KOTORI.topicsTimer = setInterval(function(){
			var topicsTop = parseInt(KOTORI.topics.css('top').replace('px',''));
			
			KOTORI.topics.animate({
				'top': topicsTop - topicsHeight							 
			},topicsDuration, function(){
				
				var prev = $('.topics' +  KOTORI.topicsPosition);
				var prevTop = parseInt(prev.css('top').replace('px',''));
				
				prev.css({
					'top': prevTop + topicsHeight * 3												 
				})
				
				if(KOTORI.topicsPosition >= 3){
					KOTORI.topicsPosition = 1;
				}else{
					KOTORI.topicsPosition += 1;
				}
				
			});
			
																					 
		},topicsIntervalTime);

	},
	firefox2FixBasic:function(){
		
		if(!KOTORI.checkBrowser.firefox2) return;

		$('#shopping-menu .cart-button').css({
			'display':'block',
			'float':'right',
			'top':-6,
			'right':18,
			'height':24
		});
		
		$('#cart-quantity-area').css({
			'display':'block',
			'float':'left',
			'width':22,
			'textAlign':'center'
		});
		
	},
	firefox2Fix201Top:function(){
		
		if(!KOTORI.checkBrowser.firefox2) return;
		
		var timer = setTimeout(function(){																
			$('#vidual201').css({
				'display':'block',
				'visibility':'visible'
			});																		
		},1000);
		
	},
	setModelTab:function(){
		var tab = $('#model-tab');

		if(!tab.length) return;

		var tab101 = $('#kotori101-tab');
		var tab201 = $('#kotori201-tab');

		var img101 = tab101.find('img');
		var img201 = tab201.find('img');

		var area101 = $('#kotori101-area');
		var area201 = $('#kotori201-area');
		
		var src101 = img101.attr('src').replace('button_101_off.png','button_101.png');
		img101.attr('src', src101);
		
		tab101.click(function(){
			
			if(tab101.attr('class') == 'here') return;
			
			var src101 = img101.attr('src').replace('button_101_on.png','button_101.png');
			var src201 = img201.attr('src').replace('button_201.png','button_201_off.png');
			
			tab101.addClass('here');
			img101.attr('src', src101);			
			
			tab201.removeClass('here');
			img201.attr('src', src201);			
			
			area201.hide();
			area101.show();
			
			tab.removeClass('kotori201');
			tab.addClass('kotori101');
			
		});
		
		tab201.click(function(){
			
			if(tab201.attr('class') == 'here') return;
			
			var src201 = img201.attr('src').replace('button_201_on.png','button_201.png');
			var src101 = img101.attr('src').replace('button_101.png','button_101_off.png');
			
			tab201.addClass('here');
			img201.attr('src', src201);			
			
			tab101.removeClass('here');
			img101.attr('src', src101);			
			
			area101.hide();
			area201.show();
			
			tab.removeClass('kotori101');
			tab.addClass('kotori201');
			
		});
		
	},
	add201TopScrollEvent:function(){

		/*KOTORI.startY;

		var flashId = 'vidual201';
				
		$(window).scroll(function(){															
			
			var endY = KOTORI.fn.getViewportRect().y;
			
			if(KOTORI.startY){
				
				var vector = endY - KOTORI.startY;
				
				KOTORI.fn.swfTarget(flashId).on201Scroll(vector); // callback flash method
				
				KOTORI.startY = endY;
				
				if(console)console.log(vector);
				
			}else{
				
				KOTORI.startY = endY;
				
			}			
			
		});*/
		
	},
	setSpecialMovie201:function(){
				
		if(KOTORI.checkBrowser.ie6){		
			DD_belatedPNG.fix('#special-movie .detail a');
			DD_belatedPNG.fix('#special-movie .soon');
		}
		
		var flashId = 'vidual201';
		var duration = 500;
		var banner = $('#special-movie .banner');
		
		KOTORI.swf201 = KOTORI.fn.swfTarget(flashId);
		
		var specialMovieTimer = setInterval(function(){
			
			var here = banner.find('.here');
			var next = here.next();

			here.fadeOut('here',function(){
				here.removeClass('here');														 
			});

			if(here.attr('class').indexOf('last') == -1){
				next.fadeIn(duration,function(){
					next.addClass('here');															
				});
			}else{
				next = banner.find('img:first');
				
				next.fadeIn(duration,function(){
					next.addClass('here');															
				});
			}
			
		},5000);
		
	},
	movieplayer:function(){
	
		KOTORI.fadeDuration = 1000;
		KOTORI.fadeFastDuration = 500;
		KOTORI.movieplayerWidth = 800;
		KOTORI.movieplayer = false;
		
		var swf_id = 'embededPlayer';
		
	 	var flashvars = {
			clip_id: 20030141,
			fp_version: 10,
			show_portrait: 1,
			show_byline: 1,
			show_title: 1,
			hd_off: 0,
			js_api: 1,
			js_onLoad: 'KOTORI.fn.moviePlayerLoaded',
			js_swf_id: 'embededPlayer'
		};
			
		var params = {
			allowscriptaccess: 'always',
			allowfullscreen: 'true'
		};
		
		var attributes = {};
			
		swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "800", "450", "9.0.0","expressInstall.swf", flashvars, params, attributes);
		
		$('#special-movie a').click(function(){
			KOTORI.fn.showMovieplayer();
			return false;
		});
	},
	moviePlayerLoaded:function(){
		KOTORI.movieplayer = document.getElementById('embededPlayer');
		
		//KOTORI.movieplayer.api_play();
		
	},
	showMovieplayer:function(){
			
		var movieplayerOverlay = $('#movieplayer-overlay');
		
		if(!KOTORI.checkBrowser.firefox){
			KOTORI.fn.hideScrollbar();		
		}

		movieplayerOverlay.fadeIn(KOTORI.fadeDuration, KOTORI.fn.loadMovieplayer());
		
	},
	loadMovieplayer:function(){

		var flashId = 'vidual201';
		
		try{
			KOTORI.fn.swfTarget(flashId).stop201Visual();
		}catch(e){
			//return;
		}
		
		if(KOTORI.movieplayer){
			$(KOTORI.movieplayer).show();
		}

		//if(KOTORI.movieplayer.api_play) KOTORI.movieplayer.api_play();
		
		KOTORI.fn.positMovieplayer();
	},
	positMovieplayer:function(){
				
		var container = $('#container');
		var movieplayerContainer = $('#movieplayer-container');
		
		KOTORI.containerWidth = container.outerWidth();
		KOTORI.containerHeight = container.outerHeight();
			
		var movieplayerContainerWidth = 842;
		var movieplayerContainerHeight = 490;
						
		if(KOTORI.checkBrowser.ie6){
	
			movieplayerForIE6();
			
			DD_belatedPNG.fix('.pngfix');
			
		}else{
			$(window).resize(function(){
	
				getMovieplayerPosition();
				
				if(KOTORI.movieplayerTop <= 0){
					movieplayerContainer.css('top', movieplayerContainerHeight / 2);
				}else{
					movieplayerContainer.css('top', '50%');
				}
				
				if(KOTORI.movieplayerLeft <= 0){
					movieplayerContainer.css('left', movieplayerContainerWidth / 2);
				}else{
					movieplayerContainer.css('left', '50%');
				}
				
			});
		}
				
		KOTORI.fn.setMovieCloseEvent();
		
		function movieplayerForIE6(){
			
			var movieplayerOverlay = $('#movieplayer-overlay');
			var viewport = KOTORI.fn.getViewportRect();
			
			getMovieplayerPosition();
			
			movieplayerOverlay.css('height', KOTORI.containerHeight);
			movieplayerContainer.css('top', KOTORI.movieplayerTop + KOTORI.fn.getViewportRect().y);
					
			$(window).scroll(function(){
				var currentTop = KOTORI.movieplayerTop + KOTORI.fn.getViewportRect().y;
				
				movieplayerContainer.css('top', currentTop);
							
			});
			$(window).resize(function(){
																
				getMovieplayerPosition();
				
				movieplayerContainer.css('top', KOTORI.movieplayerTop + KOTORI.fn.getViewportRect().y);
		
				if(KOTORI.movieplayerLeft <= 0){
					movieplayerContainer.css('left', movieplayerContainerWidth / 2);
				}else{
					movieplayerContainer.css('left', '50%');
				}
			});
		}
		
		function getMovieplayerPosition(){
			
			KOTORI.movieplayerTop = parseInt((KOTORI.fn.getViewportRect().height - movieplayerContainerHeight) / 2);
			KOTORI.movieplayerLeft = parseInt((KOTORI.fn.getViewportRect().width - movieplayerContainerWidth) / 2);
					
			if(KOTORI.movieplayerTop < 0){
				KOTORI.movieplayerTop = 0;
			}
			if(KOTORI.movieplayerLeft < 0){
				KOTORI.movieplayerLeft = 0;
			}
		}
	},
	setMovieCloseEvent:function(){
		// close button
		$('#movieplayer-close a').click(function(){

			try{
				KOTORI.movieplayer.api_pause();
				KOTORI.movieplayer.api_seekTo(0);
			}catch(e){}

			var player = $('#embededPlayer')
			var flashId = 'vidual201';

			player.hide();
																								 
			$('#movieplayer-overlay').fadeOut(KOTORI.fadeDuration, function(){
				try{
					KOTORI.fn.swfTarget(flashId).start201Visual();
				}catch(e){
					return;
				}																																			
				KOTORI.fn.showScrollbar();
				//player.show();
			});
			
			return false;
		});
	}	
}

KOTORI.mod = {}

// define custom modules

KOTORI.basic = KOTORI.mod.basic = function(){
	KOTORI.fn.changeSeparator();
	KOTORI.fn.addHomeRollover();
	//KOTORI.fn.headerDropMenu();
	KOTORI.fn.showCartQuantity();
	//KOTORI.fn.chromeHeader();
	KOTORI.fn.checkGiftMode();
	KOTORI.fn.toggleGiftArea();
	KOTORI.fn.setHeaderSearch();
	KOTORI.fn.firefox2FixBasic();
}

KOTORI.top = KOTORI.mod.top = function(){
	KOTORI.fn.setTopVidual();
}

KOTORI.blog = KOTORI.mod.blog = function(){
	KOTORI.fn.itemRollover();
	KOTORI.fn.lastEntry();
}

KOTORI.order = KOTORI.mod.order = function(){
	KOTORI.fn.slideArea();
}

KOTORI.giftcode = KOTORI.mod.giftcode = function(){
	KOTORI.fn.toggleDate();
}

KOTORI.guide = KOTORI.mod.guide = function(){
	KOTORI.closePopup($('#close-guide'));
	KOTORI.fn.setModelTab();
}

KOTORI.preview = KOTORI.mod.preview = function(){
	KOTORI.fn.initPreview();
}

KOTORI.catalog = KOTORI.mod.catalog = function(){

	if(KOTORI.checkOS.win && !(KOTORI.checkBrowser.ie)){
		KOTORI.fn.templateListStyle();
	}
	
	KOTORI.fn.templateClickable();
}

KOTORI.review = KOTORI.mod.review = function(){
	KOTORI.fn.stackVoice();
}

KOTORI.ranking = KOTORI.mod.ranking = function(){
	KOTORI.fn.rankingRollover();
}

KOTORI.magazine = KOTORI.mod.magazine = function(){
	KOTORI.fn.slideshow();
}

KOTORI.kotori101Top = KOTORI.mod.kotori101Top = function(){
	KOTORI.fn.setVidual101();
	KOTORI.fn.setModelTop();
	KOTORI.fn.addVoteEvent();
	KOTORI.setRollover();
}

KOTORI.kotori201Top = KOTORI.mod.kotori201Top = function(){
	KOTORI.fn.setModelTop();
	KOTORI.fn.setSpecialMovie201();
	KOTORI.fn.movieplayer();
	//KOTORI.fn.add201TopScrollEvent();
	//KOTORI.fn.firefox2Fix201Top();
}

KOTORI.kotori101About = KOTORI.mod.kotori101About = function(){
	KOTORI.fn.addOutline();
	KOTORI.fn.addThumbEvent('101');
}

KOTORI.kotori201About = KOTORI.mod.kotori201About = function(){
	KOTORI.fn.addOutline();
	KOTORI.fn.addThumbEvent('201');
}

// for compatibility

KOTORI.releaseGiftMode = function(){
	KOTORI.fn.releaseGiftMode();
}

KOTORI.checkGiftMode = function(){
	KOTORI.fn.checkGiftMode();
}

KOTORI.voteDesign = function(){
	KOTORI.fn.voteDesign();
}

KOTORI.scrollTop = function(){
	KOTORI.fn.scrollTop();
}

KOTORI.open201Vidual = function(){
	KOTORI.fn.open201Vidual();
}

KOTORI.close201Vidual = function(){
	KOTORI.fn.close201Vidual();
}

KOTORI.get201WindowInfo = function(){
	KOTORI.fn.get201WindowInfo();
}

KOTORI.hideScrollbarForNonFx = function(){
	KOTORI.fn.hideScrollbarForNonFx();
}

KOTORI.add201TopScrollEvent = function(){
	KOTORI.fn.add201TopScrollEvent();
}

// propaties

KOTORI.giftmode = false;

// main routine

$(function(){
	KOTORI.init();	// initialize
	
	if(KOTORI.devMode) KOTORI.testNav();	// development mode
	
	KOTORI.basic();
	
	if(KOTORI.getElement('top-vidual'))	KOTORI.top();
	
	if(KOTORI.getElement('kotori101-vidual'))	KOTORI.kotori101Top();
	
	if(KOTORI.getElement('kotori201-vidual'))	KOTORI.kotori201Top();
	
	if(KOTORI.getElement('kotori101-about')) KOTORI.kotori101About();

	if(KOTORI.getElement('kotori201-about')) KOTORI.kotori201About();
	
	if(KOTORI.getElement('entries')) KOTORI.blog();

	if(KOTORI.getElement('order')) KOTORI.order();
	
	if(KOTORI.getElement('gift')) KOTORI.giftcode();

	if(KOTORI.getElement('guide')) KOTORI.guide();

	if(KOTORI.getElement('preview')) KOTORI.preview();

	if(KOTORI.getElement('templates')) KOTORI.catalog();
	
	if(KOTORI.getElement('users')) KOTORI.review();
	
	if(KOTORI.getElement('top10')) KOTORI.ranking();

	if(KOTORI.getElement('magazine')) KOTORI.magazine();

});

