/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
* inspired from 2007-2010 Gian Carlo Mingati
* <http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/jquery.li-scroller.1.0.js>
*/
jQuery.fn.banner = function (settings) {
    settings = $.extend({
        travelocity: 0.05
    }, settings);
    var strip = $(this);
    var msg = $('li', strip);
    var container = strip.wrap("<div class='banner-container'><div class='banner-mask'></div></div>").parent().parent();
    var containerWidth = container.width();
    var msgWidth = msg.outerWidth(true);
    var stripWidth = msgWidth;
    for(var i = 0; i < 7; i++) {
        msg.clone().css("padding-left", "320px").appendTo(strip);
        stripWidth += msgWidth + 320;
    }
    /*strip.find("li").each(function (i) {
        stripWidth += $(this, i).outerWidth(true); // thanks to Michael Haszprunar
    });*/
    strip.width(stripWidth);
    strip.css("left", containerWidth);

    var totalTravel = stripWidth + containerWidth;
    var defTiming = totalTravel / settings.travelocity; // thanks to Scott Waye

    function scrollBanner(spazio, tempo) {
        strip.animate({ left: '-=' + spazio }, tempo, "linear", function () { strip.css("left", containerWidth); scrollBanner(totalTravel, defTiming); });
    }
    strip.hover(function () { $(this).stop(); }, function () {
        var residualSpace = $(this).offset().left + stripWidth;
        var residualTime = residualSpace / settings.travelocity;
        scrollBanner(residualSpace, residualTime);
    });
    scrollBanner(totalTravel, defTiming);
}


function register(id) {
    $(id + ' .holder').hover(
        function() {
            $(id + ' a').animate({
                    color: 'white'
            }, { queue: false, duration: 'slow' });
            $(id + ' .block').animate({
                    opacity: 1.0,
                    width: '92px',
                    height: '54px'
            }, { duration: 'slow' });
        },
        function() {
            $(id + ' a').animate({
                    color: '#3E3E3E'
            }, { queue: false, duration: 'slow' });
            $(id + ' .block').animate({
                    opacity: 0.0,
                    width: '0px',
                    height: '0px'
            }, { duration: 'slow' });
        }
    );
}

$(document).ready(function() {
    register('#edmcontent');
    register('#demo');
    register('#register');
    register('#seeAlso');
    $('#banner').banner();
});

