/*
 * homepage images control
 */
var buttonNames = new Array('01','02','03');
var hpButtons = new Array(), hpButtons_Over = new Array();
var hpImages = new Array();
var textDivs = new Array();
var hpLinks = new Array(), hpLinks_Over = new Array();
var hpMainImage;
var defaultImage = new Image();
var delay = 8000;
var t;

// init
function initHomepage() {
	for (i = 0; i<buttonNames.length; i++) {	
		// load text divs
		textDivs[i] = document.getElementById('hpText_' + buttonNames[i]);
		
		// preload buttons
		hpButtons[i] = new Image();
		hpButtons[i].src = '/images/layout/' + (i + 1) + '.gif';
		hpButtons_Over[i] = new Image();
		hpButtons_Over[i].src = '/images/layout/' + (i + 1) + 'Roll.gif';
		
		// preload images
		hpImages[i] = new Image();
		hpImages[i].src = "/images/layout/homepage_" + buttonNames[i] + ".jpg";
	}	
	
	// default image and text
	hpMainImage = document.getElementById('HpMainImage');
	defaultImage.src = hpMainImage.src;

	// preload links
	preloadLinks();
}

// preload links
function preloadLinks() {
    hpLinks[0] = new Image();
    hpLinks[0].src = '/images/layout/learnMore2.gif';
    hpLinks[1] = new Image();
//    hpLinks[1].src = '/images/layout/watchDemo2.gif';
    hpLinks[1].src = '/images/layout/DownloadTrial.gif';
    
    hpLinks[2] = new Image();
    hpLinks[2].src = '/images/layout/viewwebinar2.gif';	
	hpLinks_Over[0] = new Image();
	hpLinks_Over[0].src = '/images/layout/learnMoreRoll2.gif';
	hpLinks_Over[1] = new Image();
//	hpLinks_Over[1].src = '/images/layout/watchDemoRoll2.gif';
	hpLinks_Over[1].src = '/images/layout/DownloadTrialRoll.gif';

	hpLinks_Over[2] = new Image();
	hpLinks_Over[2].src = '/images/layout/viewwebinarRoll2.gif';
}

// link over
function hpLinkOver(img, idx) {
    img.src = hpLinks_Over[idx].src;
}

// link out
function hpLinkOut(img, idx) {
    img.src = hpLinks[idx].src;
}

// image over
function sImageOver(idx, stopSlide) {
    // start or stop slide?
    if (stopSlide)
        clearTimeout(t);
        
    var img = document.getElementById('hpButton' + idx);	
	
	if (!img || !hpButtons_Over[idx]) return;
	
	img.src = hpButtons_Over[idx].src;
	hpMainImage.src = hpImages[idx].src;
	for (i = 0; i < 3; i++)	    
	    textDivs[i].className = 'HomepageText';
	textDivs[idx].className = 'HomepageText HomepageText_On';
}

// image out
function sImageOut(idx, startSlide) {
    // start or stop slide?
    if (startSlide)
        t = setTimeout(startSlideshow, delay);
        
    var img = document.getElementById('hpButton' + idx);
	
	if (!img || !hpButtons[idx]) return;
	
    img.src = hpButtons[idx].src;
    hpMainImage.src = defaultImage.src;
    textDivs[idx].className = 'HomepageText';
    textDivs[0].className = 'HomepageText HomepageText_On';
}

// funtion startSlideshow
var currentButton = 0;
function startSlideshow() {
    sImageOut(currentButton);
    
    currentButton++;
    if (currentButton == 3)
        currentButton = 0;

    sImageOver(currentButton);    
    t=setTimeout(startSlideshow, delay);
}

// add it to onload
addLoadEvent(function() { t=setTimeout(startSlideshow, delay) });

/*
 * showFlash(url)
 */
function showFlash(url, width, height) {
	document.write
	('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" '+
		'WIDTH='+width+' HEIGHT='+height+' VIEWASTEXT> <PARAM NAME=movie VALUE="'+url+'"> <PARAM NAME=menu VALUE=false> <PARAM NAME=quality VALUE=best> <PARAM NAME=bgcolor VALUE=#FFFFFF> '+
		'<EMBED src="'+url+'" menu=false quality=best bgcolor=#FFFFFF  WIDTH='+width+' HEIGHT='+height+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED> </OBJECT>');
}

// Add function to the window.onload event
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

// opens a popup window in the center of the screen
//
function OpenCenteredPopUp(sFile, sWindowName, iWidth, iHeight)
{
	var maxY = screen.availHeight;
	var maxX = screen.availWidth;
	var x = (maxX - iWidth) / 2;
	var y = (maxY - iHeight) / 2;
    var w = window.open(sFile, sWindowName, 'status=no,scrollbars=no,width='+iWidth+',height='+iHeight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
    if (w != null)
	    w.focus();

	return w;
}
