﻿/* =========================================================

// jquery.innerfade.js

// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

*
*  <ul id="news"> 
*      <li>content 1</li>
*      <li>content 2</li>
*      <li>content 3</li>
*  </ul>
*  
*  $('#news').innerfade({ 
*	  animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'), 
*	  speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'), 
*	  timeout: Time between the fades in milliseconds (Default: '2000'), 
*	  type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'), 
* 		containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
*	  runningclass: CSS-Class which the container get’s applied (Default: 'innerfade'),
*	  children: optional children selector (Default: null)
*  }); 
*

// ========================================================= */


(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
            'animationtype': 'fade',
            'speed': 'normal',
            'type': 'sequence',
            'timeout': 2000,
            'containerheight': 'auto',
            'runningclass': 'innerfade',
            'children': null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.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();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
                var last = Math.floor(Math.random() * (elements.length));
                setTimeout(function() {
                    do {
                        current = Math.floor(Math.random() * (elements.length));
                    } while (last == current);
                    $.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
            } else if (settings.type == 'random_start') {
                settings.type = 'sequence';
                var current = Math.floor(Math.random() * (elements.length));
                setTimeout(function() {
                    $.innerfade.next(elements, settings, (current + 1) % elements.length, current);
                }, settings.timeout);
                $(elements[current]).show();
            } else {
                alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
            }
        }
    };

    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
                removeFilter($(this)[0]);
            });
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
    if (element.style.removeAttribute) {
        element.style.removeAttribute('filter');
    }
}
/*!
* liScroll 1.0
* Examples and documentation at: 
* http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
* 2007-2010 Gian Carlo Mingati
* Version: 1.0.2 (30-MARCH-2009)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires:
* jQuery v1.2.x or later
* 
*/


jQuery.fn.liScroll = function(settings) {
    settings = jQuery.extend({
        travelocity: 0.07
    }, settings);
    return this.each(function() {
        var $strip = jQuery(this);
        $strip.addClass("newsticker")
        var stripWidth = 0;
        var $mask = $strip.wrap("<div class='mask'></div>");
        var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
        var containerWidth = $strip.parent().parent().width(); //a.k.a. 'mask' width 	
        $strip.find("li").each(function(i) {
            stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
        });
        $strip.width(stripWidth);
        var totalTravel = stripWidth + containerWidth;
        var defTiming = totalTravel / settings.travelocity; // thanks to Scott Waye		
        function scrollnews(spazio, tempo) {
            $strip.animate({ left: '-=' + spazio }, tempo, "linear", function() { $strip.css("left", containerWidth); scrollnews(totalTravel, defTiming); });
        }
        scrollnews(totalTravel, defTiming);
        $strip.hover(function() {
            jQuery(this).stop();
        },
				function() {
				    var offset = jQuery(this).offset();
				    var residualSpace = offset.left + stripWidth;
				    var residualTime = residualSpace / settings.travelocity;
				    scrollnews(residualSpace, residualTime);
				});
    });
};

/*
* simplyScroll 1.0.4 - a scroll-tastic jQuery plugin
*
* http://logicbox.net/jquery/simplyscroll
* http://logicbox.net/blog/simplyscroll-jquery-plugin
* http://plugins.jquery.com/project/simplyScroll
*
* Copyright (c) 2009 Will Kelly - http://logicbox.net
*
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Last revised: 03/07/2009 21:13
*
*/

(function($) {
    $.fn.simplyScroll = function(o) { return this.each(function() { new $.simplyScroll(this, o); }); }; var defaults = { className: 'simply-scroll', frameRate: 24, speed: 1, horizontal: true, autoMode: 'off', pauseOnHover: true, startOnLoad: false, localJsonSource: '', flickrFeed: '', jsonImgWidth: 240, jsonImgHeight: 180 }; $.simplyScroll = function(el, o) {
        var self = this; this.o = $.extend({}, defaults, o || {}); this.auto = this.o.autoMode !== "off" ? true : false; this.$list = $(el); this.$list.addClass('simply-scroll-list').wrap('<div class="simply-scroll-clip"></div>').parent().wrap('<div class="' + this.o.className + ' simply-scroll-container"></div>'); if (!this.o.auto) { this.$list.parent().parent().prepend('<div class="simply-scroll-forward"></div>').prepend('<div class="simply-scroll-back"></div>'); }
        if (this.o.flickrFeed) { $.getJSON(this.o.flickrFeed + "&format=json&jsoncallback=?", function(data) { json = []; $.each(data.items, function(i, item) { json.push({ "src": item.media.m, "title": item.title, "link": item.link }); }); self.renderData(json); }); } else if (this.o.localJsonSource) { $.getJSON(this.o.localJsonSource, function(json) { self.renderData(json); }); } else { if (!this.o.startOnLoad) { this.init(); } else { $(window).load(function() { self.init(); }); } } 
    }; $.simplyScroll.fn = $.simplyScroll.prototype = {}; $.simplyScroll.fn.extend = $.simplyScroll.extend = $.extend; $.simplyScroll.fn.extend({ init: function() {
        this.$items = this.$list.children(); this.$clip = this.$list.parent(); this.$container = this.$clip.parent(); if (!this.o.horizontal) { this.itemMax = this.$items[0].offsetHeight; this.clipMax = this.$clip.height(); this.dimension = 'height'; this.moveBackClass = 'simply-scroll-btn-up'; this.moveForwardClass = 'simply-scroll-btn-down'; } else { this.itemMax = this.$items[0].offsetWidth; this.clipMax = this.$clip.width(); this.dimension = 'width'; this.moveBackClass = 'simply-scroll-btn-left'; this.moveForwardClass = 'simply-scroll-btn-right'; }
        this.posMin = 0; this.posMax = this.$items.length * this.itemMax; this.$list.css(this.dimension, this.posMax + 'px'); if (this.o.autoMode == 'loop') { var addItems = Math.ceil(this.clipMax / this.itemMax); this.$items.slice(0, addItems).clone(true).appendTo(this.$list); this.posMax += (this.clipMax - this.o.speed); this.$list.css(this.dimension, this.posMax + (this.itemMax * addItems) + 'px'); }
        this.interval = null; this.intervalDelay = Math.floor(1000 / this.o.frameRate); while (this.itemMax % this.o.speed !== 0) { this.o.speed--; if (this.o.speed === 0) { this.o.speed = 1; break; } }
        var self = this; this.trigger = null; this.funcMoveBack = function() { self.trigger = this; self.moveBack(); }; this.funcMoveForward = function() { self.trigger = this; self.moveForward(); }; this.funcMoveStop = function() { self.moveStop(); }; this.funcMoveResume = function() { self.moveResume(); }; if (this.auto) {
            if (this.o.pauseOnHover) { this.$clip.hover(this.funcMoveStop, this.funcMoveResume); }
            this.moveForward();
        } else { this.$btnBack = $('.simply-scroll-back', this.$container).addClass('simply-scroll-btn' + ' ' + this.moveBackClass + ' ' + 'disabled').hover(this.funcMoveBack, this.funcMoveStop); this.$btnForward = $('.simply-scroll-forward', this.$container).addClass('simply-scroll-btn' + ' ' + this.moveForwardClass).hover(this.funcMoveForward, this.funcMoveStop); } 
    }, moveForward: function() {
        var self = this; this.movement = 'forward'; if (this.trigger !== null) { this.$btnBack.removeClass('disabled'); }
        self.interval = setInterval(function() { if (!self.o.horizontal && self.$clip[0].scrollTop < (self.posMax - self.clipMax)) { self.$clip[0].scrollTop += self.o.speed; } else if (self.o.horizontal && self.$clip[0].scrollLeft < (self.posMax - self.clipMax)) { self.$clip[0].scrollLeft += self.o.speed; } else if (self.o.autoMode == 'loop') { self.resetPos(); } else { self.moveStop(self.movement); } }, self.intervalDelay);
    }, moveBack: function() {
        var self = this; this.movement = 'back'; if (this.trigger !== null) { this.$btnForward.removeClass('disabled'); }
        self.interval = setInterval(function() { if (!self.o.horizontal && self.$clip[0].scrollTop > 0) { self.$clip[0].scrollTop -= self.o.speed; } else if (self.o.horizontal && self.$clip[0].scrollLeft > 0) { self.$clip[0].scrollLeft -= self.o.speed; } else if (self.o.autoMode == 'loop') { self.resetPos(); } else { self.moveStop(self.movement); } }, self.intervalDelay);
    }, moveStop: function(moveDir) {
        clearInterval(this.interval); if (this.trigger !== null) {
            if (typeof moveDir != "undefined") { $(this.trigger).addClass('disabled'); }
            this.trigger = null;
        }
        if (this.auto) { if (this.o.autoMode == 'bounce') { moveDir == 'forward' ? this.moveBack() : this.moveForward(); } } 
    }, moveResume: function() { this.movement == 'forward' ? this.moveForward() : this.moveBack(); }, resetPos: function() { if (!this.o.horizontal) { this.$clip[0].scrollTop = 0; } else { this.$clip[0].scrollLeft = 0; } }, renderData: function(json) { if (json.length > 0) { var self = this; $.each(json, function(i, item) { $("<img/>").attr({ src: item.src, title: item.title, alt: item.title, width: self.o.jsonImgWidth, height: self.o.jsonImgHeight }).appendTo(self.$list); }); this.init(); } } 
    });
})(jQuery);
