// JavaScript Document

var i2_arrLogos = new Array();		// The array that holds our logos
var i2_logoCycle = 30;				// The delay between logo cycles in seconds
var i2_logoLoop = true;				// Do we loop the logos?
var i2_logoStartDelay = false;		// Delay the starting of the logo cycle?

function i2dt2n(oDate, bShort) {
	if (bShort) {
		return (10000 + (oDate.getMonth() + 1) * 100) + oDate.getDate();
	}
	return (oDate.getFullYear() * 10000) + ((oDate.getMonth() + 1) * 100) + oDate.getDate();
}

function i2logo_init() {
	var d = i2dt2n(new Date());
	var d2 = i2dt2n(new Date(),true);

	if (d2 >= 11201 && d2 <= 11231) {
		// Christmas
		i2_arrLogos.push('http://www.i2media.com.my/images/xmas/logo-1.gif',
						 'http://www.i2media.com.my/images/xmas/logo-2.gif',
						 'http://www.i2media.com.my/images/xmas/logo-3.gif');
	} else if (d >= 20080121 && d <= 20080221) {
		// Chinese New Year '07 - active for 1 month before the actual event up to 14 days after
		i2_arrLogos.push('http://www.i2media.com.my/images/cny/logo-1.gif');
	} else if (d >= 20070913 && d <= 20071014) {
	// Hari Raya Puasa '07 - active for 1 month before the actual event up to the 2nd day
	}
}

function i2logo() {
	if (document.getElementById && i2_arrLogos.length > 0) {
		var o = document.getElementById('logoimg');
		var p = document.getElementById('logo');
		if (o && p) {
			if (o.nowShowing) {
				o.src = o.nowShowing;
			}
			if (i2_arrLogos.length > 1) {
				ns = o.nowShowing;
				while (ns == o.nowShowing) {
					ns = i2_arrLogos[Math.floor(Math.random() * i2_arrLogos.length)];
				}
			} else {
				ns = i2_arrLogos[0];
			}
			o.nowShowing = ns;
			p.style.backgroundImage = 'url(' + o.nowShowing + ')';
			fadeOut('logoimg', 100);
		}
	}	
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";

	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function getOpacity(obj) {
	return obj.style.opacity;
}

function fadeOut(objId,opacity) {
	if (document.getElementById) {
		o = document.getElementById(objId);
		if (opacity >= 0) {
			setOpacity(o, opacity);
			opacity -= 10;
			window.setTimeout("fadeOut('" + objId + "', " + opacity + ")", 100);
		} else {
			if (o.nowShowing) {
				o.src = o.nowShowing;
				setOpacity(o, 100);
			}
			if (i2_logoLoop) {
				window.setTimeout("i2logo()", 1000 * i2_logoCycle);
			}
		}
	}
}

function i2init() {
	// Initialize our modules, variables, etc
	i2logo_init();
	
	// Other things we need to kick start
	if (i2_logoStartDelay) {
		window.setTimeout("i2logo()", 1000 * i2_logoCycle);
	} else {
		i2logo();
	}
}

// Fire off the init routines after the browser finishes loading
window.onload = function() { i2init() }
