﻿//================================================
// CN WoW Community Site
// (c)2009 Blizzard Entertainment. Shanghai Easenet. All rights reserved.
//================================================

var page = {
	start: function() {
		//new Swiff("http://images.warcraftchina.com/wlk/boot/lich-king.swf", { width: 458, height: 319 }).inject("lichking");
		//new Swiff("http://images.warcraftchina.com/wlk/boot/frostmourn.swf", { width: 277, height: 499 }).inject("frostmourn");
		page.promoSlide.init();
		page.legalTip.init();
		//page.sc2PromoTip.init();
		return this;
	},
	legalTip: {
		close: function() {
			this.tip.set('tween').tween('top',-40);
			return this;
		},
		init: function() {
			this.tip = new Element("iframe",{'id':"legal-box",'src':"boot-legal.html",'width':"778",'height':"39",'frameborder':"0",'scrolling':"no",'marginheight':"0",'marginwidth':"0"}).inject($('guide'),'top');
			return this;
		}
	},
	sc2PromoTip: {
		close: function() {
			this.sc2Tip.set('boot-sc2-frame').tween('top',-this.pageSize.y);
			return this;
		},
		init: function() {
			this.getPageSize();
			this.sc2Tip = new Element("iframe",{'id':"boot-sc2-frame",'src':"boot-sc2.html",'width':this.pageSize.x,'height':this.pageSize.y,'frameborder':"0",'scrolling':"no",'marginheight':"0",'marginwidth':"0"}).setStyles({
				position: "absolute",
				"z-index": 60001,
				left: 0,
				top: 0
			}).inject($(document.body));
			window.addEvent('resize', function(event){
				page.sc2PromoTip.getPageSize();
				var b=$('boot-sc2-frame');
				b.width=page.sc2PromoTip.pageSize.x;
				b.height=page.sc2PromoTip.pageSize.y;
				});
			return this;
		},
		getPageSize: function() {
			var s1=$(document.body).getScrollSize();
			var s2=$(document.body).getSize();
			this.pageSize={'x':s1.x>s2.x?s1.x:s2.x,'y':s1.y>s2.y?s1.y:s2.y};
			
		}
	},
	promoSlide: {
		data: {
			promoAEls:[],
			promoImgEls:[],
			promoFxs:[],
			index:0,
			switchInDuration: 1000,
			switchOutDuration: 2000,
			switchstayedDuration: 2000
		},
		stop: function() {
		},
		init: function() {
			this.promotion = $("promotion");
			this.shadeInit();
			this.slideInit();
			return this;
		},
		shadeInit: function() {
			this.promoShade = new Element('div').addClass('shade').inject(this.promotion,'top');
			this.promotion.addEvents({
				mouseenter: function() {
					this.promoShade.setStyle('display','none');
				}.bind(this),
				mouseleave: function() {
					this.promoShade.setStyle('display','');
				}.bind(this)
			});
			return this;
		},
		slideInit: function() {
			this.data.promoAEls=this.promotion.getElements('a');
			this.data.promoImgEls=this.promotion.getElements('img');
			
			this.data.promoAEls.each(function(el) {
				el.setStyle('display',"none");
			});
			this.data.promoImgEls.each(function(el) {
				el.setStyle('display',"none");
			});
			if((this.promoListLen=this.data.promoAEls.length)!=this.data.promoImgEls.length){
				return this;
			}
			
			this.data.promoFxs.push(new Fx.Tween(this.promotion,{
				duration: this.data.switchInDuration
			}));
			this.data.promoFxs.push(new Fx.Tween(this.promotion,{
				duration: this.data.switchOutDuration,
				onComplete: function(){
					this.data.promoImgEls[this.data.index].setStyle('display',"none");
					this.data.promoAEls[this.data.index].setStyle('display',"none");
					if(++this.data.index>=this.promoListLen){
						this.data.index=0;
					}
					this.slidein(this.data.index);
				}.bind(this)
			}));
						
			this.slidein();
		},
		slidein: function() {
			this.data.promoAEls[this.data.index].setStyle('display',"");
			this.data.promoImgEls[this.data.index].setStyle('display',"");
			this.data.promoFxs[0].start('opacity',0,1);
			this.slideout.delay(this.data.switchstayedDuration+this.data.switchInDuration,this);
		},
		slideout: function() {
			this.data.promoFxs[1].start('opacity',1,0);
		}
	}
};

window.addEvent('domready',page.start);

