//ANIMATION OBJECT
animation = {
	
	animations: new Array(),
	speed: 20,
	frame: 1,
	run: function( a, t, o, p ) {

		animations = 0;

		for( var id in this.animations ) ++animations;

		animationExists = this.animations[a+o] ? true : false;

		this.animations[a+o] = [a, t, o, p];

		if( !animations ) this.animate();

	},
	animate: function() {

		var animations = 0;

		for( var id in this.animations ) {

			if( !((this.frame*this.speed)%(this.animations[id][1]*this.speed)) ) this[this.animations[id][0]](id, this.animations[id][2], this.animations[id][3]);

			++animations;

		}

		if( animations ) {

			++this.frame;

			setTimeout('animation.animate()', this.speed);

		}

	},
	quit: function( id ) {

		delete this.animations[id];

	}
	
}

//ANIMATION: FADE
animation['Fade'] = function( id, o, p ) {

	var fadeTo = p[0];
	var explorer = navigator.appName == 'Microsoft Internet Explorer' ? true : false;

	object = document.getElementById(o);

	if( typeof this.fader == 'undefined' ) this.fader = new Object();

	if( !this.fader[o] ) {

		if( object.style.display == 'none' ) {

			explorer ? object.style.filter = 'alpha(opacity=0)' : object.style.opacity = 0;

			this.fader[o] = 0;

			object.style.display = '';

		}

		else {

			explorer ? object.style.filter = 'alpha(opacity=100)' : object.style.opacity = 1;

			this.fader[o] = 100;

		}

	}

	var fadingRatio = 0.5;

	this.fader[o] = this.fader[o] + (fadeTo - this.fader[o]) * fadingRatio;

	explorer ? object.style.filter = 'alpha(opacity='+this.fader[o]+')' : object.style.opacity = this.fader[o]/100;

	if( Math.round(this.fader[o]) == fadeTo ) {

		explorer ? object.style.filter = 'alpha(opacity='+fadeTo+')' : object.style.opacity = fadeTo/100;

		if( !fadeTo ) object.style.display = 'none';
		
		if( p[1] ) p[1]();

		delete this.fader[o];

		animation.quit(id);

	}

}

//AJAX LOADER
function getContent(url, func) {

	xmlRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	xmlRequest.onreadystatechange = function() { if( xmlRequest.readyState == 4 ) func(xmlRequest.responseText); };
	xmlRequest.open('GET', url, true);
	xmlRequest.send(null);

}

//INLINE POPUP
InlinePopup = {
	
	open: function( URL ) {
		
		document.getElementById('InlinePopup').style.display = '';
		
		animation.run('Fade', 1, 'Canvas', [80, function() { InlinePopup.show( URL ) }]);
		
	},
	show: function( URL ) {
		
		document.body.style.cursor = 'progress';
		
		document.getElementById('Frame').style.display = '';
		document.getElementById('Frame').style.left = Math.round((document.body.offsetWidth-document.getElementById('Frame').offsetWidth)/2)+'px';
		document.getElementById('Frame').style.display = 'none';
		
		getContent(URL, function( Content ) {
								 
			document.getElementById('PopupContent').innerHTML = Content;
		
			animation.run('Fade', 1, 'Frame', [100]);
			
			document.body.style.cursor = 'default';
			
		});
		
	},
	close: function() {
		
		animation.run('Fade', 1, 'Frame', [0,function() {
			
			animation.run('Fade', 1, 'Canvas', [0,function() {
				
				document.getElementById('InlinePopup').style.display = 'none';
				
			
			}])
			
		}]);
		
	}
	
}

