﻿//Cross Fade
//Christopher Edwards
//based on the work of Torsten Baldes http://medienfreunde.com/lab/innerfade/
//Licensed GPL

//*
//*  <ul id="news"> 
//*      <li>content 1</li>
//*      <li>content 2</li>
//*      <li>content 3</li>
//*  </ul>
//*  
//*  $('#news').crossfade({ 
//*	  speed: Fading-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'), 
//* 	  containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
//*	  runningclass: CSS-Class which the container get’s applied (Default: 'crossfade'),
//*  }); 
//*
//*
//*  $('#news').showimage(imageindex);
//*

var current = 0;
var elements;
var settings;

(function ($) {

    $.fn.crossfade = function (options) {
        return this.each(function () {
            $.crossfade(this, options)
        })
    }

    $.crossfade = function (container, options) {
        settings = {
            'speed': 'normal',
            'containerheight': 'auto',
            'runningclass': 'crossfade'
        }
        if (options)
            $.extend(settings, options);
        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();
            }
            $(elements[current]).show();
        }
    }

})(jQuery);