//
// 2008-10-10
// Copyright (c) Art. Lebedev Studio | http://www.artlebedev.ru/
// Author - Svetlana Shustrova | soulntse@design.ru
//

/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
function changeStorySquare(eSquare, sAction) {
	if (eSquare) {
		var sClassName = eSquare.className;
		var sNewClass = 'square';
		switch(sAction) {
			case 'over':
				sNewClass += (sClassName.indexOf('showstory') == -1)? ' show' : ' showstory';
				break;
			case 'out':
				if (sClassName.indexOf('showstory') >= 0) sNewClass += ' showstory';
				break;
			case 'expand':
				sNewClass += ' showstory';
				break;
			case 'collapse':
				sNewClass += ' show';
				break;
		}
		eSquare.className = sNewClass;
	}
}



/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
function SimpleAnimation(eImage, iFrameHeight, iFrameCount, iFrameDelay) {
	if (eImage) {
		this.eImage = eImage
		this.iFrameHeight = iFrameHeight;
		this.iFrameCount = iFrameCount;
		this.iFrameDelay = iFrameDelay;
		this.iCurrentFrame = 0;
		this.iLastFrame = 0;
		this.TO = null;
		return this;
	} else return null;
}

SimpleAnimation.prototype.start = function(iFirstFrame, iLastFrame) {
	oThis = this;
	this.iCurrentFrame = iFirstFrame;
	this.iLastFrame = iLastFrame;
	this.showCurrentFrame();
	if (iFirstFrame < iLastFrame)
	this.TO = setTimeout(function(){ oThis.showNextFrame() }, this.iFrameDelay);
	else
	this.TO = setTimeout(function(){ oThis.showPreviousFrame() }, this.iFrameDelay);
}

SimpleAnimation.prototype.showNextFrame = function() {
	if (this) {
		if (this.iCurrentFrame < this.iLastFrame) {
			oThis = this;
			this.iCurrentFrame++;
			this.showCurrentFrame();
			this.TO = setTimeout(function(){ oThis.showNextFrame() }, this.iFrameDelay);
		} else this.onFinishEvent();
	}
}
SimpleAnimation.prototype.showPreviousFrame = function() {
	if (this) {
		if (this.iCurrentFrame > this.iLastFrame) {
			oThis = this;
			this.iCurrentFrame--;
			this.showCurrentFrame();
			this.TO = setTimeout(function(){ oThis.showPreviousFrame() }, this.iFrameDelay);
		} else this.onFinishEvent();
	}
}

SimpleAnimation.prototype.showCurrentFrame = function() {
	if (this) {
		if (this.iCurrentFrame)
		var iTop = '-' + (this.iFrameHeight * (this.iCurrentFrame - 1));
		else
		var iTop = this.iFrameHeight; if (this.eImage) this.eImage.style.top = iTop + 'px';
	}
}

SimpleAnimation.prototype.onFinishEvent = function() {
	if (this && this.onFinish) this.onFinish();
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * */

function bigBang() {
	var eStars = document.getElementById('stars');
	if (eStars) {
		eStars.style.display = "block";
		var iFrames = 7;
		var iVertStep = Math.round(eStars.offsetHeight / 2 / iFrames);
		var iHorzStep = Math.round(eStars.offsetWidth / 2 / iFrames);
		bigBangStep(eStars, iVertStep, iHorzStep, 1, iFrames, 8);
	}
}

function bigBangStep(eStars, iVertStep, iHorzStep, iStep, iFrames, iDelay) {
	if (eStars) {
		eStars.style.clip = 'rect(' + (iVertStep * (iFrames - iStep)) + 'px,' + (iHorzStep * (iFrames + iStep)) + 'px,' +
		(iVertStep * (iFrames + iStep)) + 'px,' + (iHorzStep * (iFrames - iStep)) + 'px)';
		if (iStep < iFrames)
		setTimeout(function(){ bigBangStep(eStars, iVertStep, iHorzStep, ++iStep, iFrames, iDelay) }, iDelay)
	}
}


window.onload = function() {
	var eCityAnim = new SimpleAnimation(document.getElementById('city-img'), 163, 5, 150);
	if (eCityAnim) {
		eCityAnim.start(1, 5);
	}
//	alert('1');
}


