var win1;

function newWin(url, w, h)
{
    if (win1 && win1.open || win1 && !win1.closed)
    {
        win1.close()
    }
    win1 = window.open(url, "win1", "width=" + w + ",height=" + h + ",toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=yes")
}

//image rotator
function init_pic_rotator()
{
    pic_rotate();
    setInterval('pic_rotate()', 6000);
}

function pic_rotate()
{
    var already_running = $('div.pic_rotator div.show');

    //Get the first random image
    if (already_running.length == 0)
    {
        var divs = $('div.pic_rotator').children();
        var rndNum = Math.floor(Math.random() * divs.length);
        var current = $(divs[rndNum]);
        current.addClass('show')
            .fadeIn(500);
        return;
    }
    else
    {
        current = already_running;
    }

    //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.pic_rotator div:first') : current.next()) : $('div.pic_rotator div:first');

    //Fade in next image
    next.addClass('show')
        .fadeIn(2000);

    //Hide the current image
    current.removeClass('show')
        .fadeOut(2000);
}

$(document).ready(function()
{
    init_pic_rotator();
});
