function startTime()	{
	var JSclock = document.getElementById('JSclock');
	if (JSclock) {
		var today=new Date();
		var h=today.getHours();
		var m=today.getMinutes();
		var s=today.getSeconds();
		// add a zero in front of numbers<10
		m=checkTime(m);
		s=checkTime(s);
		JSclock.innerHTML=h+":"+m+":"+s;
		t=setTimeout('startTime()',500);
	}
}

function checkTime(i)	{
	if (i<10) i="0" + i;
	return i;
}

function IEover (elem, add) {
	if (add) { elem.className += ' IEover';}
	else { elem.className = elem.className.replace(/ IEover/g, "");}
}

var MyMooFlows = new Array();
var MMFid = 0;
var HoverOn = false;
var closeFlashIntro;

window.addEvent("domready", function () {
	startTime();

	if( Browser.Engine.trident4) {
		$$('li, div.presentation').each(function(liItem)  {
			liItem.addEvent("mouseover", function(){IEover(this, true)} )
			liItem.addEvent("mouseout", function(){IEover(this, false)} )
		})
	}

	
	var mf_div = $('MooFlow');
	if (mf_div) {
			/* MooFlow instance with the complete UI and Viewer */
			MyMooFlows[0] = new MooFlow(mf_div, {
				offsetY: -100,
				heightRatio: 0.2,
				useSlider: true,
				useAutoPlay: true,
				useCaption: true,
				useResize: true,
				useMouseWheel: true,
				useKeyInput: true,
				bgColor: '#1f1f1f',
				onClickView: function(){
					MMFid=0;
					Slimbox.open(this.master['slimbox'], this.index, {MooFlow: this});
				}
			});
	}

	var mp_div = $('MooPres');
	if (mp_div) {
			/* MooFlow instance with the complete UI and Viewer */
			MyMooFlows[1] = new MooFlow(mp_div, {
				offsetY: -100,
				heightRatio: 0.2,
				useSlider: true,
				useAutoPlay: true,
				useCaption: true,
				useResize: true,
				useMouseWheel: true,
				useKeyInput: true,
				bgColor: '#1f1f1f',
				onClickView: function(){
					MMFid=1;
					Slimbox.open(this.master['slimbox'], this.index, {MooFlow: this});
				}
			});
	}
	
	(function (){
		var CustScroll = $('CustScroll');
		var list = $('news_list');
		var bttns = $('news_scrolling');
		if (!CustScroll || !list || !bttns) return false;
		var TimeInt, step;
		//list.setStyle('bottom','45px');
		list.setStyle('overflow','hidden');
		bttns.setStyle('display','block');
		CustScroll.addEvent('mousewheel', function(ev){
			var newY = list.getScroll().y + ev.wheel*-100;
			list.scrollTo(0, newY);
			ev.preventDefault();
		});
		$('ScrolUp').addEvents({
			'mousedown': function(ev){
				step = -5;
				SmoothScroll();
				ev.preventDefault();
			},
			'mouseup': function(ev){	
				clearTimeout(TimeInt);
			}
		});
		$('ScrolDown').addEvents({
			'mousedown' : function(ev){
				step = 5;
				SmoothScroll();
				ev.preventDefault();
			},
			'mouseup': function(ev){	
				clearTimeout(TimeInt);
			}
		});
		function SmoothScroll(){
			var newY = list.getScroll().y + step;
			list.scrollTo(0, newY);
			TimeInt = SmoothScroll.delay(10);
		}
	})();
	
	(function (){
		var featbox = $('featbox');
		if (!featbox) return false;
		
		if (Browser.Plugins.Flash.version) {	// user has flash
			featbox.set('opacity',0);
		} else {
			delayInt = loopFbox.delay(2000);
		};

		closeFlashIntro = function() {
			(function () {
				new Fx.Morph(featbox, {
					  duration: 1000
					, transition: Fx.Transitions.Quart.easeOut
				}).start({
					'opacity':[0,1]
					, 'top':[-400,0]
				});
			}).delay(1500);
			$('FlashIntro').destroy();
			delayInt = loopFbox.delay(4000);
		}

		var boxes = $$('#featbox .feat');
		var tles=[]; // togglies
		var curBox=0, delayInt;
		var BoxCount = boxes.length-1;
		var LoopDelay = 5000;

		featbox.addEvents({
		/**
			'mousewheel': function(ev){
				var newBox = curBox - ev.wheel;
				if (newBox < 0 ) newBox = BoxCount;
				if (newBox > BoxCount ) newBox = 0;
				SelectBox(newBox);
				ev.preventDefault();
			},
		/**/
			'mouseover': function(ev){
				clearTimeout(delayInt);
			},
			'mouseleave': function(ev){
				delayInt = loopFbox.delay(LoopDelay);
			}
		});

		boxes.each(function(el, num){
			var chld = el.getChildren();
			tles[num]=chld[0];
			if (!tles[num]) return false;
			if (num>0) tles[num].setStyle('left','800px');
			else tles[num].setStyle('left','0px');
			el.addEvent('click', function(ev){
				SelectBox(num);
			});
		});
		
		var myFx = new Fx.Elements(tles, {
			  duration: 1500
			, transition: Fx.Transitions.Quart.easeOut
		});
		var NewPos = {}
		
		function SelectBox(numSel){
			if (numSel == curBox) return false; // Do nothing
			var direction = (numSel > curBox) ? 1 : -1;
			if (numSel == 0 && curBox == BoxCount) direction =  1;
			if (numSel == BoxCount && curBox == 0) direction = -1;
			tles.each(function(el, num){
				if (num==numSel) {
					NewPos[num] = {'left':0};
					boxes[num].addClass('toggler_on');
					el.setStyle('z-index',7);
				} else if (num == curBox) {
					NewPos[num] = {'left':-direction*800};
					boxes[num].removeClass('toggler_on');
					el.setStyle('z-index',6);
				} else {
					NewPos[num] = {'left':direction*800};
					boxes[num].removeClass('toggler_on');
					el.setStyle('z-index',5);
				}
			});
			myFx.cancel();
			myFx.start(NewPos);
			curBox = numSel;
			return true;
		}
		
		$('PrevFeat').addEvent('click', function(ev){
			var newBox = (curBox>=1 ) ? curBox-1 : BoxCount ;
			SelectBox(newBox);
			clearTimeout(delayInt);
			delayInt = loopFbox.delay(LoopDelay);
			ev.preventDefault();
		});
		$('NextFeat').addEvent('click', function(ev){
			var newBox = (curBox<BoxCount ) ? curBox+1 : 0 ;
			SelectBox(newBox);
			clearTimeout(delayInt);
			delayInt = loopFbox.delay(LoopDelay);
			ev.preventDefault();
		});

		function loopFbox (){
			var newBox = (curBox<BoxCount ) ? curBox+1 : 0 ;
			clearTimeout(delayInt);
			SelectBox(newBox);
			delayInt = loopFbox.delay(LoopDelay);
		}
		//delayInt = loopFbox.delay(2000);
		
	})();
	
});