var DescriptionRotate = Class.create();
DescriptionRotate.prototype = {
	initialize: function(descQueue, cssRule, pauseTime) {
		this.cssRule = cssRule;
		this.descQueue = descQueue;
		this.index = 1;
		this.currentDesc;
		this.pauseTime = pauseTime;

		setTimeout(function() {
			this.loadNextDesc();
		}.bind(this), this.pauseTime)
	},

	loadNextDesc: function() {
		// if index is bigger than amount of images, start from 0
		if(this.index >= this.descQueue.length) {
			this.index = 0;
		}

		// get the current image from list.
		this.currentDesc = this.descQueue[this.index];

		var descEl = $$(this.cssRule).first();

		// start effects
		new Effect.Opacity(descEl, {
			// start effects 3 seconds after method load
			duration: 1.0,
			transition:Effect.Transitions.linear,
			from: 1.0,
			to: 0.0,
			afterFinish: function(effect) {
				//Hack to ensure image will be changed completely
				new Effect.Opacity(descEl, {
					duration: 0.2,
					transition:Effect.Transitions.linear,
					from: 0.0,
					to: 0.0,
					afterFinish:function(effect) {
						descEl.innerHTML = this.currentDesc;
						new Effect.Appear(descEl);
					}.bind(this)
				});
			}.bind(this)
		});

		// increment the index for next image
		this.index += 1;

		setTimeout(function() {
			this.loadNextDesc();
		}.bind(this), this.pauseTime)
	}
};

var EastSeven = Class.create();
EastSeven.prototype = {
	initialize: function() {
		this.flyerEl = $$('.flyer').first();

		$$('.flyer').each(function(el) {
			el.observe('mouseover', this.flyerOnMouseover.bindAsEventListener(this));
			el.observe('mouseout',  this.flyerOnMouseout.bindAsEventListener(this));
		}.bind(this));

		$$('.textSliderTrigger').each(function(el) {
			var textWrap = $$('.textSliderWrap').first();
			textWrap.hide();

			el.observe('click', function() {
				textWrap.toggle();
			}.bind(this));
		}.bind(this));

		$$('a').each(function(link) {
			Event.observe(link, 'focus', function() { link.blur(); } );
		});

		$$('a.printButton').each(function(link) {
			link.show();
		});

		// browser detection
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);



		// if browser is IE, then replace images with DIV's that uses activeX
		if (itsAllGood) {
			$$('.flyer img').each(function(el) {
				this.switchPNGHandling(el);
			}.bind(this));

			$$('.booking_inquiry img').each(function(el) {
				var div = this.switchPNGHandling(el);
				$$('.booking_inquiry div').each(function(el) {
					el.observe('mouseover', function() {
						this.bookingOnMouseover(el);
						div.style.width = 111; div.style.height = 110;
					}.bind(this));
					el.observe('mouseout',  function() {
						this.bookingOnMouseout(el);
						div.style.width = 101; div.style.height = 100;
					}.bind(this));
				}.bind(this));
			}.bind(this));

			$$('#medals .changestate a').each(function(el) {
				el.observe('mouseover', function() {
					el.down('.normal').style.display = 'none';
					el.down('.onhover').style.display = 'block';
				});
				el.observe('mouseout', function() {
					el.down('.normal').style.display = 'block';
					el.down('.onhover').style.display = 'none';
				});
			}.bind(this));

			$$('.logo a').each(function(el) {
				el.observe('mouseover', function() {
					el.down('.normal').style.display = 'none';
					el.down('.hover').style.display = 'block';
				});
				el.observe('mouseout', function() {
					el.down('.normal').style.display = 'block';
					el.down('.hover').style.display = 'none';
				});
			}.bind(this));

			$$('#medals img').each(function(el) {
				//this.switchPNGHandling(el);
			}.bind(this));
		}
	},

	flyerOnMouseover: function() {
		new Effect.Morph(this.flyerEl, {
			style: { top: '-140px' },
			duration: 0.25
		});
	},

	flyerOnMouseout: function() {
		new Effect.Morph(this.flyerEl, {
			style: { top: '-120px' },
			duration: 0.25
		});
	},

	bookingOnMouseover: function(el) {
		new Effect.Morph(el, {
			style: {
				width: '111px',
				height: '110px'
			},
			duration: 0.25
		});
	},

	bookingOnMouseout: function(el) {
		new Effect.Morph(el, {
			style: {
				width: '101px',
				height: '100px'
			},
			duration: 0.25
		});
	},
	switchPNGHandling: function(img) {
		var src = img.src;
		var div = document.createElement("DIV");
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
		div.style.width = img.width + "px";
		div.style.height = img.height + "px";
		img.replaceNode(div);

		img.style.visibility = "visible";

		return div;
	}
};

Event.observe(window, 'load', function() {
	var eastseven = new	EastSeven();
});

function printWindow() {
	Browser = parseInt(navigator.appVersion);
	if (Browser >= 4) window.print();
}
