/*
	eclipse-creative.com
	20090514 tomc
*/
/*
	CLOCK FEATURE
*/
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var updateClock = function(){
	var d = new Date(),
		daym = d.getDate(),
		y = d.getYear();
		
	if (daym<10)
		daym="0"+daym;
		
	if( y < 1900 )
		y += 1900;
	
	var dstr = days[d.getDay()] + ', ' + daym +' ' +  months[d.getMonth()] + ' , '  + y;
	
	var Digital=new Date();
	var hours=Digital.getHours();
	var minutes=Digital.getMinutes();
	var seconds=Digital.getSeconds();
	var dn="PM";
	if (hours<12) dn="AM";
	if (hours>12) hours=hours-12;
	if (hours==0) hours=12;
	if (minutes<=9)	minutes="0"+minutes;
	if (seconds<=9)	seconds="0"+seconds;
	var ctime=hours+":"+minutes+":"+seconds+" "+dn;

	$$("span.clock").each(function(clockEl){
		clockEl.setProperty('html', dstr + ' ' + ctime);
	});
};

/*
	ENTRY
*/
window.addEvent( 'domready', function(){
	
	/*
		MENU TEXT ROLL
	*/
	$$( '.menu a' ).addEvents({
		mouseenter:function(){
			this.set( 'morph', { duration:300, transition: Fx.Transitions.Quad.easeIn } );
			var morphTo = '.menuactive';
			if( this.getParent().hasClass("lvl2") ) morphTo = '.sub-menuactive'
			this.morph(morphTo);
		},
		mouseout:function(){
			this.set( 'morph', { duration:1200, transition: Fx.Transitions.Quad.easeIn } );
			var morphTo = '.menuidle';
			if( this.getParent().hasClass("lvl2") ) morphTo = '.sub-menuidle'
			this.morph(morphTo);
		}
	});
	
	/*
		IMAGE ROLL GROUPS
	*/
	for( var imgsets = $$('.imgr'), i = 0; i != imgsets.length; ++i ){
		var rollgrp = imgsets[i].getElements('img.rollgrp');
		if( rollgrp.length > 1 ){
			rollgrp[1].setStyles({
				opacity:0,
				visibility:'visible'
			});
			
			rollgrp.set('morph', {duration: 200, transition: Fx.Transitions.Sine.easeIn });
			//  ADD EVENTS  //
			imgsets[i].addEvents({
				mouseenter:function(){ if(this.hasClass('cancel'))return; this.getElements('.rollgrp')[1].morph({opacity:1}); },
				mouseleave:function(){ if(this.hasClass('cancel'))return; this.getElements('.rollgrp')[1].morph({opacity:0}); }
			});
		}
	}
	
	/*
		WARWICK GROUP COMPANIES
	*/
	$$(".warwick-group-menu").each(function(menuEl){
		var listEl = menuEl.getElement(".list");
		if( !listEl ) return;
		listEl.setStyle("display","block");
		listEl.slide("hide");
		menuEl.addEvents({
			mouseenter	:function(){ listEl.slide("in");},
			mouseleave	:function(){ listEl.slide("out"); }
		});
	});
	
	
	/*
		CATEGORY MENU
	*/
	$$(".head table.menu td.lvl1").each(function(td){
		var ul = td.getElement("ul.lvl1");
		if( ul ){
			var menuParent = new Element("div",{
				styles:{
					position	: "absolute",
					width		: ( td.getSize().x <= 128 ) ? 156 : td.getSize().x		// if the td is really small..
				}
			}).inject(td, "bottom");
			ul.setStyles({
				display		: "block",
				position	: "static",
				width		: "auto"
				
			}).inject( menuParent );
			ul.slide("hide");
			td.addEvents({
				mouseenter:function(){this.getElement("ul.lvl1").slide("in");},
				mouseleave:function(){this.getElement("ul.lvl1").slide("out");}
			});
		}
	});
	
	
	/*
		START CLOCK FEATURE
	*/
	updateClock();
	var timeIntId = updateClock.periodical(1000);
});