/* =========================================================

// jquery.innerfade.js
// created by Christopher Schleiden
// heavily modified version of  Torsten Baldes' plugin
// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

// ========================================================= */


(function($) {
    var settings;

    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        settings = {
        	'animationtype':    'fade',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          10000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null,
            'playCtrl':         null,
            'prevCtrl':         null,
            'nextCtrl':         null,
            paused:             false
        };
        if (options)
            $.extend(settings, options);
        // listeners
        $(settings.playCtrl).click(function(){
            settings.paused = !settings.paused;
            if( settings.paused )
            {
                clearTimeout( settings.timer );
                this.src = '/images/icons/control_play.png';
            }
            else 
            {
                settings.timer = setTimeout(function() {
                    $.innerfade.next();
                }, settings.timeout);
                this.src = '/images/icons/control_pause.png';
            }
        });
        $(settings.prevCtrl).click(function(){
            if( settings.paused )
                $.innerfade.next();
        });
        $(settings.nextCtrl).click(function(){
            if( settings.paused )
                $.innerfade.next(-1);
        });
       
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        settings.elements = elements;
        settings.current = 0;
        settings.last = 0;
        elements.each(function(n){ this.index = n; });

        if (elements.length >= 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };

            settings.timer = setTimeout(function() {
                $.innerfade.next();
            }, settings.timeout);
            $(elements[0]).show();
		}
    };

    $.innerfade.next = function( inc ) {        
        if( inc == null )  
            inc = 1;
    
        if ((settings.current + inc) >= settings.elements.length) {
            settings.current = 0;
            settings.last = settings.elements.length - 1;
        } else if( (settings.current + inc) < 0) {
            settings.current = settings.elements.length - 1;
            settings.last = 0;
        } else {
            settings.last = settings.current;
            settings.current = settings.current + inc;
        }

        $(settings.elements[settings.last]).fadeOut(settings.speed);
        $(settings.elements[settings.current]).fadeIn(settings.speed, function() {
			removeFilter($(this)[0]);
		});
    
        if( !settings.paused ) {
            settings.timer = setTimeout((function() {
                $.innerfade.next();
            }), settings.timeout);
        }
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
    if(element.style)
    {
	    if(element.style.removeAttribute){
		    element.style.removeAttribute('filter');
	    }
    }
}

