var hash = '';

// for use with RSH and mootools 1.2
window.dhtmlHistory.create(
{
	toJSON: function(o)
	{
		return JSON.encode(o); 
	},
	fromJSON: function(s)
	{
		return JSON.decode(s); 
	} 
}); 

window.addEvent('load', function() {
	// get RSH to work
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(Page.update);
	
	// call hash or set home as default
	if ( dhtmlHistory.isFirstLoad() )
	{
		var site = ( dhtmlHistory.getCurrentLocation() == '' ) ? 'home' : dhtmlHistory.getCurrentLocation();
		Page.update(site);
	}
	
});

Page = {
	loaderShow: function()
		{
			//$('loader').setStyle('background-image', 'url(images/design/ajax-loader.gif)');
		},
	loaderHide: function()
		{
			//$('loader').setStyle('background-image', 'none');
		},
	show: function(id)
		{
			$(id).setStyle('display', 'block');
		},
	hide: function(id)
		{
			$(id).setStyle('display', 'none');
		},
	toggle: function(id)
		{
			if ( $(id).getStyle('display') == 'none' )
			{
				Page.show(id);
			}
			else
			{
				Page.hide(id);
			}
		},
	update: function(newLocation, historyData)
		{
			dhtmlHistory.add(newLocation, true);
			
			// for use with other functions
			hash = newLocation;			
			
			new Request.HTML({ 
				update: $('content'),
				method: 'post',  
				url: 'geco.php',  
				data: 'hash=' + hash, 
				evalScripts: true,
				onRequest: function()
					{
						Page.loaderShow();
					},
				onComplete: function()
					{
						Page.loaderHide();
						
						// prevent a href="#" from opening
						$$('a').each(function(el) {
							if ( el.href.lastIndexOf("#") === el.href.length - 1 )
							{
								el.addEvent('click', function(e){
									new Event(e).preventDefault(); // no stop !
								});									
							}
						});
						
						// set position of second line
						$('line-bottom').setStyles({top: ($('content').getCoordinates().bottom + 25) + 'px'});
							
					}
				}).send();
		
		},
	popup: function(url, width, height)
		{
		 win = window.open(url, 'popup', 'width=' + width + ',height=' + height + ',status=no,scrollbars=no,resizable=no');
		 win.focus();
		}
} // end Page

