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

// Based on:
//	Innerfade <Torsten Baldes | http://medienfreunde.com>
// Author: Pascal Kriete

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


(function($) {
	
	var elements, last = 0,
		settings = {
        'speed':            'normal',
        'containerheight':  'auto',
        'runningclass':     'innerfade'
    };

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

    $.innerfade = function(container, callback) {

		elements = $(container).children();
        
        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();
            };
		}
		
		$.innerfade.next(0);
		callback.call(this, elements, settings);
    };

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


	$.cycleGallery = function(thumbs, large, opts) {
		
		thumbs = $(thumbs);
		large = $(large);
		
		options = {
			'event': 'click'
		};
		
		if (opts) {
			$.extend(options, opts);
		}
		
		large.innerfade(function(elements, settings) {
			var that = this;

			thumbs.each(function(i, el) {
				$(this).bind(options.event, function() {
					$.innerfade.next(i);
				});
			});
		});
	}

})(jQuery);

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

