// uses jquery.cycle.js

//this variable gets assigned in the eventrotator.ascx control
var eventimages;

$(window).load(
    function(){
        if ($('ul#quoterotator li').length == 1)
            $('ul#quoterotator li').show();
        else
            $('ul#quoterotator').cycle({ speed: 500,timeout: 7000}); //cycle doesn't do anything if less than 2 items
		$('ul#imagerotator').cycle({ speed: 500,timeout: 4000});
		if(eventimages) loadimage(0,$(eventimages).length); //images is the name of the array in EventRotator.ascx
    }
);



function loadimage(index, max)
{
    if (index < max)
    {
        var n = $(eventimages)[index];
        var thiselement = $(".mod-eventrotator li").slice(index+1,index+2);
				
        if (n.link != "") {
            $("<a></a>").attr({"href": n.link, "target": n.target}).html($("<img/>").attr({"src": n.src, "alt": n.alt, "title": n.title})).appendTo(thiselement);
            setTimeout("checkcomplete(" + index + "," + max + ")", 1000);
        }
        else {
            $("<img/>").attr({"src": n.src, "alt": n.alt, "title": n.title}).appendTo(thiselement);
            setTimeout("checkcomplete(" + index + "," + max + ")", 1000);
        }  
    }
}

function checkcomplete(index, max)
{
    var thiselement = $(".mod-eventrotator li").slice(index+1,index+2);
    
    if(thiselement.find('img').length > 0 && thiselement.find('img')[0].complete == undefined)
		loadimage(index+1,max);
    else if (thiselement.find('img').length > 0 && thiselement.find('img')[0].complete)
        loadimage(index+1,max);
    else
        setTimeout("checkcomplete(" + index + "," + max + ")", 1000);
        
}

