//IE7 Cleartype fade in/out fixes
(function($) {
    $.fn.customFadeIn = function(speed, callback) {
        $(this).fadeIn(speed, function() {
            if (jQuery.browser.msie) {
                $(this).each(function() {
                    $(this).get(0).style.removeAttribute('filter');
                })
            }
            if (callback != undefined)
                callback();
        });
    };
    $.fn.customFadeOut = function(speed, callback) {
        $(this).fadeOut(speed, function() {
            if (jQuery.browser.msie) {
                $(this).each(function() {
                    $(this).get(0).style.removeAttribute('filter');
                })
            }
            if (callback != undefined)
                callback();
        });
    };
})(jQuery);

function Slideshow(slideContainer, slideItemBaseId, slideItemClass, slideInterval) {
    //"public" props
    var SlideContainer, SlideItemBaseId, SlideInterval, SlideItemClass;
    var itemCount, currentItem, oldItem, timerObject;
    var me = this; //fix for this scope issues

    SlideContainer = slideContainer;
    SlideItemBaseId = slideItemBaseId;
    SlideInterval = slideInterval;
    SlideItemClass = slideItemClass;

    //"private" props
    itemCount = 0;
    currentItem = 0;
    oldItem = 0;
    timerObject;

    //"private" methods
    //callback function
    me.itemRotate = function() {
        currentItem = (oldItem + 1) % itemCount;
        $("#" + SlideContainer + " ." + SlideItemClass + ":eq(" + oldItem + ")").customFadeOut("slow", function() {
            $("#" + SlideContainer + " ." + SlideItemClass + ":eq(" + currentItem + ")").customFadeIn("slow");
        });
        oldItem = currentItem;
    };
    
    //"public" methods
    me.Start = function() {
        //set item count
        itemCount = $("#" + SlideContainer).children().size();

        //make sure all items are hidden
        $("#" + SlideContainer + " ." + SlideItemClass).each(function(i) {
            $(this).css('visibility', 'visible');
            $(this).css('display', 'inline');
        });

        $("#" + SlideContainer + " ." + SlideItemClass).each(function(i) {
            $(this).hide();
        });

        //fade in the first item
        $("#" + SlideContainer + " ." + SlideItemClass + ":eq(" + currentItem + ")").customFadeIn("slow");

        //setup on hover start and stop of the slideshow
//        $("#" + SlideContainer).hover(function() {
//                me.Stop();
//		    }, function() {
//		        timerObject = setInterval(me.itemRotate, SlideInterval); //time in milliseconds
//		        me.itemRotate();
//		    });

        //setup timer callback
        timerObject = setInterval(me.itemRotate, SlideInterval);
    };

    me.Stop = function() {
        clearInterval(timerObject);
    };

    

    
   
    
} 

