function MM_InitImage() {
    //var $j = jQuery.noConflict();
    var elem = document.getElementById("HomeAnimation");
    var elem_imgs = elem.getElementsByTagName("a");
    //for (var i = 0; i < elem_imgs.length; i++) {
    //elem_imgs[0].setAttribute('onClick', 'redirectPage1()');
    //elem_imgs[1].setAttribute('onClick', 'redirectPage2()');
    //elem_imgs[2].setAttribute('onClick', 'redirectPage3()');
    //elem_imgs[3].setAttribute('onClick', 'redirectPage4()'); 
    //}
    var randomnumber = (Math.floor(Math.random() * elem_imgs.length) + 1);
    $('div#HomeAnimation a').css({ opacity: 0.0 });
    $('div#HomeAnimation a:first').addClass('show');
    $('div#HomeAnimation a:first').css({ opacity: 1.0 });
    setInterval('rotate()', 4000);
}

function redirectPage1() {
    location.href = "http://202.169.196.26/roger/WhyInvestinForestry/WhyInvestinForestry.aspx";
}

function redirectPage2() {
    location.href = "http://202.169.196.26/roger/CarbonForestry/CarbonForestryinNewZealandAnoverview.aspx";
}

function redirectPage3() {
    location.href = "http://202.169.196.26/roger/InvestmentOptions/InvestmentOpportunities.aspx";
}

function redirectPage4() {
    location.href = "http://202.169.196.26/roger/InvestmentOptions/OverseasInvestors.aspx"
}

function rotate() {
    //Get the first image
    var current = ($('div#HomeAnimation a.show') ? $('div#HomeAnimation a.show') : $('div#HomeAnimation a:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#HomeAnimation a:first') : current.next()) : $('div#HomeAnimation a:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 3000);

    //Hide the current image
    current.animate({ opacity: 0.0 }, 3000)
	.removeClass('show');

};
