window.addEvents({
	'load': function(){
		/*  Create SlideItMoo instance  */	
		var sMoo = new SlideItMoo({
			overallContainer: 'SlideItMoo_info_outer',
			elementScrolled: 'SlideItMoo_info_inner',
			thumbsContainer: 'SlideItMoo_info_items',		
			itemsSelector: '.info_item',
			itemsVisible:1,				
			itemWidth:780,
			showControls:1,
			transition: Fx.Transitions.Back.easeIn,
			duration: 800,
			direction:1,
			/* the onChange event fires when the current slide changes. We'll use it to display the next/previous article title ( in #announce ) */
			onChange: function( index ){
				/* calculate the previous slide index and the next */
				var prev = index-1 < 0 ? sMoo.elements.length-1 : index-1;
				var next = index+1 >= sMoo.elements.length ? 0 : index+1;				
			}
		});	
		$$('.info_item a').each(function(el) {
			if (el.rel == 'lightbox-p1' || el.rel == 'lightbox-p2')
				return;
			pathname = window.location.pathname.split("#");
			hrefname = window.location.href.split("#");
			el.href = "#" + pathname[0] + el.href.replace(hrefname[0], "");
		})
		$$('#menu-categories a').each(function(el) {
			if (el.href.indexOf("#") != -1)
				return;
			pathname = window.location.pathname.split("#");
			hrefname = window.location.href.split("#");
			el.href = "#" + pathname[0] + el.href.replace(hrefname[0], "");
		})
		hashChangeCheck.periodical(50);
	}
});

var oldHash = "#";
var hashChangeCheck = function()
{
	if (window.location.hash != oldHash)
	{
		oldHash = window.location.hash;
		loadPage(oldHash);
	}
}

var loadPage = function(hash)
{
	if (hash == "#" || hash == '' || hash == '/' || hash == '#/')
	{
		fadeOutContent();
		return;
	}
	page  = new Request({url: hash.replace("#", "") + "?ajax=1", 
		onSuccess: function(html) {
			if (html)
			{
				fadeInContent(html);
			}	
		},
		method: 'get',
		evalScripts: true
	});
	page.send();
}

var fadeInContent = function(content)
{
	$('float-over').innerHTML = content;
	fade  = new Fx.Tween('float-over');
	slide = new Fx.Tween('float-over');
	fade.start('opacity', '1');
	slide.start('height', (parseInt($$('.main-content')[0].getStyle('height').replace("px", "")) + parseInt($$('.main-footer')[0].getStyle('height').replace("px", "")) + 1050));
	Slimbox.scanPage();
}

var fadeOutContent = function()
{
	fade  = new Fx.Tween('float-over');
	slide = new Fx.Tween('float-over');
	fade.start('opacity', '0');
	slide.start('height', '0');
}
