var shows = {};

function startShow(showName, parent, path, width, height, count) {
    shows[showName] = {};
    shw = shows[showName];
    shw.name = showName;
    shw.pnt = $("#" + parent);
    shw.pth = path;
    shw.wth = width;
    shw.hgt = height;
    shw.init = ((shw.pnt.width()-width)/2)-width;
    shw.cnt = count;
    shw.stp = 0;
    
    var sHTML = createShowHTML(shw);
    shw.pnt.html(sHTML);

    shw.shw = $("#" + showName);
    shw.shw.css("left",shw.init + "px");
    shw.tmr = setInterval('animShowStep(shows["' + showName + '"])',SLIDEDURATION*4);
}

function createShowHTML(shw) {
    var sShow = '<div id="' + shw.name + '" style="position:absolute; width:' + (shw.wth * shw.cnt) + 'px;">';
    for (var i = 0; i < shw.cnt; i++){
        sShow += '<img style="position:absolute; left:' + (i * shw.wth) + 'px; top:0px;" src="' + shw.pth + i + '.jpg" ';
        sShow += 'width="' + shw.wth + '" height="' + shw.hgt + '" alt="" />';
    }
    for (var i = 0; i < 3; i++){
        sShow += '<img style="position:absolute; left:' + ((i + shw.cnt) * shw.wth) + 'px; top:0px;" src="' + shw.pth + i + '.jpg" ';
        sShow += 'width="' + shw.wth + '" height="' + shw.hgt + '" alt="" />';
    }
    
    sShow += '</div>';
    return sShow;
}

function animShowStep(shw){
    if (shw.stp == shw.cnt) {
        shw.stp = 0;
        shw.shw.css("left",shw.init + "px");
    }
    shw.stp++;
    var iNewLeft = shw.init;
    iNewLeft -= shw.wth * shw.stp;
    shw.shw.animate({left:iNewLeft + "px"},SLIDEDURATION);
}

function cancelShow(showName){
    clearInterval(shows[showName].tmr);
}
