var controller = {
		
	initialize : function ()
	{
		this.navigation();	// sets navigation menu
		this.newsfeed();	// news feed - ajax powered
		this.gallery();		// gallery   - ajax powered
		this.video.set();	// videogallery - ajax powered
		this.reference();	// reference - ajax powered
		this.referenceall();	// reference - ajax powered
	},
	
	navigation : function () 
	{
		var menu = document.getElementById('menu');
		var buts = menu.getElementsByTagName('a');
		var url  = document.location.href.toString();
		var page = url.substring(url.lastIndexOf('/')+1, url.lastIndexOf('.'));
		
		for(i=0; i<buts.length; i++)
		{
			if(page.toLowerCase().match(buts[i].id.replace('menu-', '')))
			{
				buts[i].parentNode.className = 'selected';				
			}			
		}		
	},
	
	toggle : function(el)
	{
		if(typeof el == 'string'){
			id = el;
			var el = $$('a[rel='+id+']').first();
		} else {
			id = el.element().readAttribute('rel');
			var el = el.element();		
		}
		
		if(el.innerHTML.match('zavřít'))
		{
			el.update('zobrazit');
			new Effect.Parallel([
				new Effect.SlideUp(id, { sync: true}),
				new Effect.Opacity(id, { sync: true, from: 1, to: 0 })
			], { duration: 0.7, delay: 0.2 });
		} else {
			el.update('zavřít');
			new Effect.Parallel([
				new Effect.SlideDown(id, { sync: true}),
				new Effect.Opacity(id,   { sync: true, from: 0, to: 1 }
			)], { duration: 0.7, delay: 0.2 });
		}
		
		
	},
	
	slideup : function (el)
	{		
		el = $(el);
		el.stopObserving('click');
		el.update('zobrazit');
		el.observe('click', controller.slidedown);
		id = el.readAttribute('rel');
		alert(this);
		new Effect.Parallel([
			new Effect.SlideUp(id, { sync: true}), 
			new Effect.Opacity(id, { sync: true, from: 1, to: 0 })
		], { duration: 0.7, delay: 0.2 });
		return false;
	},
	
	slidedown : function (event)
	{        
		event.stop();		
		el = event.element();
		el.stopObserving('click');
		id = el.readAttribute('rel');
		el.update('zavřít');
		el.observe('click', function(){ 
			controller.slideup(el);
		});
		new Effect.Parallel([
			new Effect.SlideDown(id, { sync: true}), 
			new Effect.Opacity(id,   { sync: true, from: 0, to: 1 }
		)], { duration: 0.7, delay: 0.2 });
	},	
	
	newsfeed : function ()
	{
		nws = $('news');		
		mode = (document.location.href.match('aktuality')) ? '' : '&m=feed';
		if(nws)
		{
			nws.update('<p><blink>Nahrávám..</blink></p>');
			new Ajax.Request('./sys/cnt.php?a=news'+mode, {
				method: 'get',
				onSuccess: function(data){
					nws.update(data.responseText);
				}
			});
		}
	},
	
	gallery : function ()
	{
		gll = $('gall');
		if(gll)
		{
			gll.update('<p><blink>Nahrávám..</blink></p>');
			new Ajax.Request('./sys/cnt.php?a=gall', {
				method: 'get',
				onSuccess: function(data){
					gll.update(data.responseText);
					Lightview.updateViews();
				}
			});
		}
	},
	
	video : {
		
		set : function ()
		{
			vds = $('vids');
			if(vds)
			{
				vds.update('<p><blink>Nahrávám..</blink></p>');
				new Ajax.Request('./sys/cnt.php?a=vids', {
					method: 'get',
					onSuccess: function(data){
						vds.update(data.responseText);
					}
				});
			}
		},
		
		play : function (url)
		{
			// lightview
			Lightview.show({ href: url });
		}
		
	},

	reference: function (id)
	{
		if($('refr'))
		{
			if(typeof id=='undefined')
			{
				id = 0;
			}
			new Ajax.Updater('refr', './sys/cnt.php?a=refr&i='+id, { method: 'get' });
			return false;
		}		
	},
	referenceall: function (id)
	{
		if($('refrall'))
		{
			if(typeof id=='undefined')
			{
				id = 0;
			}
			new Ajax.Updater('refrall', './sys/cnt.php?a=refrall&i='+id, { method: 'get' });
			return false;
		}		
	},
	
	// old skool javascript
	nw : function(url)
	{
		window.open(url);
		return false;
	}
	
};

document.observe("dom:loaded", function() { controller.initialize(); });

// window.onload = controller.initialize;

