var home = {
	init: function () {
		home.inittabNewsNav();
		home.initPictureBox();
		//home.initSpy('spyContainer','/home/test',15);
		//home.initCrossFade('fader');
	},
	initSpy: function(id,url,sec){
		if ($(id) != null) {
			new PeriodicalExecuter( function() { 
				new Ajax.Updater(id,url, {
					onLoading: function(request){ Effect.Fade(id, { duration:1, from:1.0, to:0.0 });},
					onComplete:function(request){ Effect.Appear(id, { duration:1, from:0.0, to:1.0 });},
					asynchronous: true, 
					evalScripts: true, 
					requestHeaders:['X-Update', id]
					})
				}, 
			sec);
		}
	},
	initCrossFade: function (id) {
		if ($(id) != null) {
			var divs = new Array();
			if ($(id) != null){
				$A($(id).getElementsByTagName('div')).each(function (obj,i) {
					//alert(obj.id+' - '+i);
					divs[i] = obj.id;
				});
			}
			var wait = 5;	// in seconds
			var i = 0;
			new PeriodicalExecuter( function() {
				Effect.Fade(divs[i], { duration:1, from:1.0, to:0.0 });
				i++;
				if (i == 3) i = 0;
				Effect.Appear(divs[i], { duration:1, from:0.0, to:1.0 });
			},wait);
		}
	},
	inittabNewsNav: function () {
		if ($('tabNewsNav') != null) {
			$A($('tabNewsNav').getElementsByTagName('A')).each(function (elm) {
				Event.observe(elm.id,'click',function(){raiseTab(elm.id);});
			});
		}
	},
	initPictureBox: function () {
		if ($('pictureNewsList') != null){
			Crossfade.setup({ autoLoad:false, autoStart:false, interval : 10 });
			var cf1 = new Crossfade('pictureNewsList');
		}
	}
}

Event.observe(window, 'load', home.init);

function raiseTab(id) {
	$('tabNewsLoader').show(); 
	new Ajax.Updater('tabNewsContent','/home/'+id,{ 
		onSuccess: function () { 
			$A($('tabNewsNav').getElementsByTagName('A')).each(function (elm) {
				if(elm.id == id) {
					elm.addClassName("active");
				} else {
					elm.removeClassName("active");
				}
			});
		},
		onComplete: function () { 
			$('tabNewsLoader').hide(); 
		}
	});
}
