window.addEvent('domready',function() {
	if (checkURL(location.href)) {
		$('homePagePre').setStyle('display', 'none');
		$('homePage').setStyles({
			display: 'block',
			visibility: 'visible'
		});
	}
	else {
		$('homePage').setStyle('display', 'none');
		$('homePagePre').setStyle('visibility', 'visible');
		selHome = new historyManager(location.href)
	}
})

function checkURL(currentURL)
{
	if(getURL(currentURL)=='homepage')
		return true;
	else	
		return false;
}

function getURL(_url)
{
	var locationURI = new URI(_url);
	if(locationURI.get('fragment'))
		return locationURI.get('fragment');
	if(locationURI)
		return locationURI;
}

var historyManager = new Class({
	initialize:function(baseURL)
	{
		this.baseURL = new URI(baseURL).get('fragment');
		if(!this.baseURL)
			this.baseURL = new URI(baseURL);
		this.currentURL = this.baseURL;
		this.timer = this.checkForUpdates.periodical(200,this);
	},
	checkForUpdates:function()
	{
		currentURL = this.getURL();
		if(this.currentURL.toString()!=currentURL.toString())
			this.changeURLEvent(currentURL);
	},
	changeURLEvent:function(url)
	{
		if(url==this.baseURL.toString())
			this.changeURL('');
		else	
			this.changeURL(url);
		
	},
	changeURL: function(newURL){
		this.currentURL = newURL;
		//var selHome = getURL();
			$('homePagePre').setStyle('display', 'none');
			$('homePage').setStyles({
				display: 'block',
				visibility: 'visible'
			});
	},
	getURL:function()
{
	var locationURI = new URI(location.href);
	if(locationURI.get('fragment'))
		return locationURI.get('fragment');
	if(locationURI)
		return locationURI;
}
})

