var presentationCycle2 = {
    
    /*
     * Presentation Cycle - a jQuery Cycle extension
     * Author:  Gaya Kessler
     * URL:     http://www.gayadesign.com
     * Date:	03-11-09
     */
    
    //slide options
    slideTimeout: 15000,
    containerId: "presentation_container2",
    
    //cycle options
    cycleFx: 'scrollLeft',
    cycleSpeed: 300,  
    
    //progressbar options
    barHeight: 14,
    barDisplacement: 20,
    barImgLeft: "images/pc_item_left.gif",
    barImgRight: "images/pc_item_right.gif",
    barImgCenter: "images/pc_item_center.gif",
    barImgBarEmpty: "images/pc_bar_empty.gif",
    barImgBarFull: "images/pc_bar_full.gif",
    
    //variables this script need
    itemCount: 0,
    currentItem: 0,
    itemBarWidth: 0,
    barContainer: "",
    barContainerActive: "",
    barContainerOverflow: "",
    disableAnimation: false,
    
    init: function() {
        
        presentationCycle2.itemCount = $('#' + presentationCycle2.containerId).children().length;

        presentationCycle2.barContainer = $("<div></div>");
        $(presentationCycle2.barContainer).addClass("pc_bar_container2");
        
        var subtrackSpace = (presentationCycle2.itemCount * presentationCycle2.barHeight);
        var totalWidth = $('#' + presentationCycle2.containerId).innerWidth() - presentationCycle2.barDisplacement;
        var fillWidth = Math.floor((totalWidth - subtrackSpace) / (presentationCycle2.itemCount - 1));
        presentationCycle2.itemBarWidth = fillWidth;
        
        for (var i = 0; i < presentationCycle2.itemCount; i++) {
            var item = $("<div>&nbsp;</div>").appendTo(presentationCycle2.barContainer);
            var extra_bar = true;
            if (i == 0) {
                $(item).addClass("left");
                $(item).css({
                    backgroundImage: "url(" + presentationCycle2.barImgLeft + ")",
                    height: presentationCycle2.barHeight + "px",
                    width: presentationCycle2.barHeight + "px"
                });
            } else if (i == (presentationCycle2.itemCount - 1)) {
                $(item).addClass("right");
                $(item).css({
                    backgroundImage: "url(" + presentationCycle2.barImgRight + ")",
                    height: presentationCycle2.barHeight + "px",
                    width: presentationCycle2.barHeight + "px"
                });
                extra_bar = false;
            } else {
                $(item).addClass("center");
                $(item).css({
                    backgroundImage: "url(" + presentationCycle2.barImgCenter + ")",
                    height: presentationCycle2.barHeight + "px",
                    width: presentationCycle2.barHeight + "px"
                });
            }
            $(item).attr('itemNr', (i + 1));
            $(item).css('cursor', 'pointer');
            $(item).click(function() {
               presentationCycle2.gotoSlide($(this).attr('itemNr'));
            });
            
            if (extra_bar == true) {
                var item = $("<div>&nbsp;</div>").appendTo(presentationCycle2.barContainer);
                $(item).addClass("bar");
                 $(item).css({
                    backgroundImage: "url(" + presentationCycle2.barImgBarEmpty + ")",
                    height: presentationCycle2.barHeight + "px",
                    width: fillWidth + "px"
                });
            }
        }
        
        var overflow = $("<div></div>");
        $(overflow).addClass("pc_bar_container_overflow");
        $(overflow).css({
            overflow: "hidden",
            width: totalWidth + "px"
        });
        var underflow = $("<div></div>");
        $(underflow).addClass("pc_bar_container_underflow").appendTo(overflow);
        
        presentationCycle2.barContainerActive = $(presentationCycle2.barContainer).clone().appendTo(underflow);
        $(presentationCycle2.barContainerActive).removeClass("pc_bar_container2");
        $(presentationCycle2.barContainerActive).children().each(function () {
            $(this).css({
                backgroundPosition: "right"
            });
            if ($(this).css("background-image").match(presentationCycle2.barImgBarEmpty)) {
                var newImg = $(this).css("background-image").replace(presentationCycle2.barImgBarEmpty, presentationCycle2.barImgBarFull);
                $(this).css("background-image", newImg);
            }
        });
        $(overflow).css({
            width: presentationCycle2.barHeight + "px",
            height: presentationCycle2.barHeight + "px"
        });
        
        presentationCycle2.barContainerOverflow = overflow;
        
        $('#' + presentationCycle2.containerId).cycle({
    		fx: presentationCycle2.cycleFx,
            speed: presentationCycle2.cycleSpeed,
            timeout: presentationCycle2.slideTimeout,
            before: function(currSlideElement, nextSlideElement) { presentationCycle2.beforeSlide(currSlideElement, nextSlideElement); }
    	});
        
        presentationCycle2.barContainer.appendTo($('#' + presentationCycle2.containerId));
        overflow.appendTo($('#' + presentationCycle2.containerId));
        
        var i = 0;
        $(".pc_bar_container_overflow .left, .pc_bar_container_overflow .center, .pc_bar_container_overflow .right").each(function () {
            $(this).attr('itemNr', (i + 1));
            $(this).css('cursor', 'pointer');
            $(this).click(function() {
                presentationCycle2.gotoSlide($(this).attr('itemNr'));
            });
            i++;
        });
    },
    
    beforeSlide: function(currSlideElement, nextSlideElement) {
        if (presentationCycle2.currentItem == 0) {
            presentationCycle2.currentItem = 1;
        } else {
            presentationCycle2.currentItem = (presentationCycle2.itemCount - ($(nextSlideElement).nextAll().length)) + 2;
        }
        presentationCycle2.animateProcess();
    },
    
    animateProcess: function() {
        var startWidth = (presentationCycle2.itemBarWidth * (presentationCycle2.currentItem - 1)) + (presentationCycle2.barHeight * presentationCycle2.currentItem);
        if (presentationCycle2.currentItem != presentationCycle2.itemCount) {
            var newWidth = (presentationCycle2.itemBarWidth * (presentationCycle2.currentItem)) + (presentationCycle2.barHeight * (presentationCycle2.currentItem + 1));   
        } else {
            var newWidth = presentationCycle2.barHeight;
        }
        
        $(presentationCycle2.barContainerOverflow).css({
            width: startWidth + "px"
        });
        if (presentationCycle2.disableAnimation == false) {
            $(presentationCycle2.barContainerOverflow).stop().animate({
                width: newWidth + "px"
            }, (presentationCycle2.slideTimeout - 100));   
        }
    },
    
    gotoSlide: function(itemNr) {
        $(presentationCycle2.barContainerOverflow).stop();
        presentationCycle2.disableAnimation = true;
        $('#' + presentationCycle2.containerId).cycle((itemNr - 1));
        $('#' + presentationCycle2.containerId).cycle('pause');
    }
    
}
