function getURLparam(name) { var regexS = "[\\?&]"+name+"=([^&#]*)"; var regex = new RegExp( regexS ); var tmpURL = window.location.href; var results = regex.exec( tmpURL ); if( results == null ) return ""; else return results[1]; }

// find our starting point
var iStartIndex = (getURLparam('idx')) ? getURLparam('idx') : 1,
    iScroll = 3;

// determine if we should scroll the viewer
if (iStartIndex > iScroll) {
    switch (iStartIndex % iScroll) {
        case 0:
            iStartIndex = iStartIndex - 2;
            break;
        case 2:
            iStartIndex = iStartIndex - 1;
            break;        
    }
} else {
    iStartIndex = 1;
}

$(function () {
    $('#mycarousel').jcarousel({
        vertical: true,
        scroll: iScroll,
        start: iStartIndex
    });

    // append our index values to url
    $('#mycarousel li a').click(function () {
        $(this).attr('href', $(this).attr('href') + '?idx=' + $(this).parent().attr('jcarouselindex'));
    });    
});
