﻿Event.observe(window, 'load', function(event) {
	mnShop.init();
});

var mnShop = {
	init : function () {
		// display zoom info line
		if ($('image_zoom')) {
			$('image_zoom').appear ({duration: 1});
			$('image_zoom').fade ({delay: 5, duration: 0.5});
		}

		// animate intro images
		if ($('intro')) {
			this.cycle ();
		}

		// prepare slideshow
		if ($('slide_content0')) {
			for (var idx=0; idx < 6; idx++) {
				obj = $('slide_content'+idx);
				if (obj) {
					if (obj.hasClassName('portrait'))
						this.slideboxList.push ({content:obj.innerHTML,player:'html',width:600,height:520});
					else
						this.slideboxList.push ({content:obj.innerHTML,player:'html',width:520,height:500});
				}
			}
		}
	},
	cycleIdx : 0,
	cycleIterate : function () {
		switch (this.cycleIdx) {
			case 0: this.cycleIdx=1;	break;
			case 1: this.cycleIdx=4;	break;
			case 2: this.cycleIdx=3;	break;
			case 3: this.cycleIdx=5;	break;
			case 4: this.cycleIdx=2;	break;
			case 5: this.cycleIdx=8;	break;
			case 6: this.cycleIdx=7;	break;
			case 7: this.cycleIdx=1;	break;
			case 8: this.cycleIdx=6;	break;
		}
		return this.cycleIdx;
	},
	getTextIdx : function () {
		return 1+(this.cycleIdx-1)%4;
	},
	getAreaIdx : function () {
		var idx = 2;
		switch (this.cycleIdx) {
			case 3: case 4:	case 7:	case 8:	idx = 5;
		}
		return idx;
	},
	getAreaColor : function () {
		switch (this.cycleIdx) {
			case 1: return '#11ABAC';
			case 2: return '#A8874E';
			case 3: return '#11ABAC';
			case 4: return '#4E7169';
			case 5: return '#7AAFA3';
			case 6: return '#00959D';
			case 7: return '#A17E39';
			case 8: return '#C7B59A';
			default:	return '#333';
		}
	},
	cycle : function () {
		this.cycleIterate();
		var imgObj = $('image'+(1+(this.cycleIdx-1)%4));
		var textObj = $('text'+this.getTextIdx());
		if (imgObj && textObj) {
			imgObj.hide();
			textObj.innerHTML = '';
			textObj.hide();
			textObj.innerHTML = $('slogan'+this.cycleIdx).innerHTML;
			var pos = imgObj.src.lastIndexOf('.');
			imgObj.src = imgObj.src.substring(0, pos-1)+this.cycleIdx+imgObj.src.substring(pos);
			new Effect.Appear (imgObj, {duration: 1});
			new Effect.Appear (textObj, {duration: 1});
			new Effect.Fade (textObj, {delay: 12-1.1, duration: 1});
			new Effect.Morph ('area'+this.getAreaIdx(), {style: 'background: '+this.getAreaColor()+';', duration: 1.0});
			window.setTimeout ('mnShop.cycle()', 3000);
		}
	},
	tabDestHeight : 140,
	tabNormHeight : 57,
	tabList : Array ('material', 'care', 'time', 'sizes'),
	tabShow : function (obj) {
		for (idx=0; idx < this.tabList.length; idx++) {
			if (obj != this.tabList[idx]) {
				$('sub_'+this.tabList[idx]).setStyle({zIndex: 10});
			}
		}
		$('sub_'+obj).setStyle({zIndex: 11});

		if (obj == 'sizes') {
			if ($('sub_'+obj).getHeight() < 100) {
				new Effect.Morph ('sub_'+obj, {style: 'height: '+this.tabDestHeight+'px;', duration: 0.5});
				new Effect.Move (obj, {x: 0, y: -83, duration: 0.5});
			}
			else {
				new Effect.Move (obj, {x: 0, y: 83, duration: 0.5});
				new Effect.Morph ('sub_'+obj, {style: 'height: '+this.tabNormHeight+'px;', duration: 0.5});
			}
		}
	},
	slideboxList : Array(),
	slidebox: function (idx) {
		Shadowbox.open (this.slideboxList);
		Shadowbox.change (idx);
		return false;
	}
}