// dot_star_browser_js
/*	CALCOLO [crossbrowser] DELLE DIMENSIONI DELLA FINESTRA	*/
bodyWidth='';bodyHeight='';

function getBodySize() {
if (self.innerWidth)
	{
		bodyWidth = self.innerWidth;
		bodyHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		bodyWidth = document.documentElement.clientWidth;
		bodyHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		bodyWidth = document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
	}
}
/*	END	*/


function populate_the_sky() {
	stars.each(function(item){
		item.x = Math.round(Math.random()*bodyWidth);
		item.y = Math.round(Math.random()*bodyHeight);
		item.x = Math.round(Math.random()*100);
		item.y = Math.round(Math.random()*100);		
		item.deep = Math.round(Math.random()*4);
		Element.setStyle(item, {position:'absolute',left:item.x+'%',top:item.y+'%'} );
		item.className='star_'+item.deep;
	});
}

function blinker() {
	for (i=0;i<(stars.length-1)/10;i++) {
		star = stars[Math.round(Math.random()*(stars.length-1))];
		deep = Math.round(Math.random()*4);
		star.className='star_'+deep;
	}
	
}

function pageLoaded(evt) {
	getBodySize();
	Element.hide('loader');
	$('sky').innerHTML='';
	//
	stars = '';timerID=''
	//
	Element.hide('sky');
	//Effect.Appear('sky',{duration:2});
	Element.show('loader');

	new Ajax.Updater('sky','ajax.php',{onComplete:function(){
											stars = document.getElementsByClassName('star');
											Element.hide('loader');
											populate_the_sky();
											Effect.Appear('sky',{duration:2});

											timerID= setInterval('blinker()',1);
}});
	$('navBarForm').onsubmit = function() {
		Effect.Fade('sky',{duration:.3});
		clearInterval(timerID);
		Element.show('loader');
		new Ajax.Updater('sky','ajax.php',{
					parameters:'galaxy_search='+$F('galaxy_search'),
					onComplete:function(){
						stars = document.getElementsByClassName('star');
						Element.hide('loader');
						populate_the_sky();
						Effect.Appear('sky',{duration:2});
						timerID= setInterval('blinker()',1);
						
					}
		});
		return false;
	}
	//
	Event.observe(window,'resize',getBodySize);
	
}
Event.observe(window,'load',pageLoaded);

