var timer;
var maxNoPanel = 15;
var currentpanel = 1;
function TriggerEvent () {
    $('#slide_right').trigger('click');

    StartSlideShow();
}

function StartSlideShow () {
    clearTimeout(timer);
    timer = setTimeout("TriggerEvent()", 9000);
}

$(document).ready(function () {
	
    var $panels = $('#slider .scrollContainer > div');
    var $container = $('#slider .scrollContainer');

    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = true;

    // float the panels left if we're going horizontal
    if (horizontal) {
		if($panels.length){
        	// calculate a new width for the container (so it holds all panels)
        	$container.css('width', $panels[0].offsetWidth * $panels.length);
		}
    }

    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = $('#slider .scroll').css('overflow', 'hidden');

    // apply our left + right buttons
    $scroll
        //.before('<img id="slide_left" class="scrollButtons left" src="images/scroll_left.png" />')
        .after('<img id="slide_right" class="scrollButtons right" src="images/scroll_right.png" />');

    $('#slide_right').click(function () {
        currentpanel ++;
        
        if(currentpanel > (maxNoPanel+1)) {
            $('.scrollContainer').css('margin-left', '0px');
            currentpanel = 2;
        }
        var animateby = parseInt($('.scrollContainer').css('margin-left'), 10) - $('.panel').width();
        $('.scrollContainer').animate({
            marginLeft: animateby
        }, 'normal', 'swing');
    });
    
    StartSlideShow();
});
