﻿$(document).ready(function () {
    menumagic();
    prepToolTips();
    buttons('.button');
    deobfuscate('a.obfus');

    ValidateInitialize('.validate');
    $('.validatetrigger').bind('click', function (event) {
        var all = doValidateAll($('.validate'), $('#error'));
        if (!all) { event.preventDefault(); $('.mandatory').css('color', '#c00') }
    });

    $('.sub').corner('3px');
    $('.itemizedlist li:even').addClass('even');
    $('.itemizedlist li:odd').addClass('odd').each(function () {
        $(this).css('background-position', $(this).css('background-position').replace(/(-)?\d+[pxem%]+/i, '35px '));
    });
    $('.itemizedlist li:eq(0), .itemizedlist li:eq(1)').addClass('li1');
    FilledInput($('input.init, textarea.init, select.init'));

    $('.playoverlay').bind('click', function () {
        if (undefined != flashobj) {
            $(this).siblings('.vid').append(flashobj);
            $(this).fadeOut(333).siblings('.vid').fadeIn(333);
        }
    });

    $('.header h1, .header h2').bind('click', function () {
        window.location.href = '/';
    }).css('cursor', 'pointer');
});

if (typeof String.prototype.ElfCheck !== 'function') {
    //validates dutch bank account numbers (except ING) usign the 11-check.
    String.prototype.ElfCheck = function () {
        var arr = this.replace(/\D/g, '').split('');
        var result = 0;
        if (arr.length == 9) { arr.splice(0, 0, 0) }
        for (var z = 0; z < arr.length; z++) {
            result += (arr[z] * (z * 1 + 1));
        }
        result = (result / 11);
        return (Math.floor(result) == result);
    };
}

if (typeof String.prototype.padZero !== 'function') {
    //pads the number to the specified length/
    //useful for dates etc. where a fixed length is required: 02 vs 2.
    String.prototype.padZero = function (length) {
        if (undefined == length || isNaN(length)) { return this; }
        var returnvar = this.toString();
        while (returnvar.length < length) {
            returnvar = '0' + returnvar;
        }
        return returnvar;
    };
}

if (typeof Date.prototype.isValid !== 'function') {
    //checks if date is valid.
    Date.prototype.isValid = function () {
        var d = this.getDate();
        var m = this.getMonth();
        var y = this.getFullYear();
        if (d > 30) {
            if (m == 2 || m == 4 || m == 6 || m == 9 || m == 11) {
                return false;
            } else if (d < 32) {
                return true;
            }
        } else if (m == 2 && d == 29) {
            if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
                return true;
            }
        } else if (m == 2 && d > 29) {
            return false;
        } else {
            return true;
        }
        return false;
    };
}

function ArrayDiff(array1, array2) {
    //This function takes an array as argument
    //goal:     return the differences between the two arrays.
    //note:     make sure array is unique.
    //remarks:  alters original arrays. To prvent this, call this function with array.slice();
    if (!array1 || undefined == array1) {
        return array2;
    } else if (!array2 || undefined == array2) {
        return array1;
    }
    var result = [];
    var b = false; //boolean indicator: turns true if a match is found.
    if (array1.length < array2.length) {
        var temp = array1;
        array1 = array2;
        array2 = temp;
    }
    var i = 0;
    while (i < array1.length) {
        b = false;
        var j = 0;
        while (j < array2.length) {
            if (array1[i] == array2[j]) {
                array2.splice(j, 1); //remove the item from array2.
                b = true;
                break;
            } else {
                b = false;
            }
            j++;
        }
        if (!b) {
            result.push(array1[i]);
        }
        i++;
    }
    return result.concat(array2);
}

if (typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function () {
        return this.replace(/^\s+|\s+$/, '');
    };
}


//maakt een array uniek, dubbele waardes worden weggegooid
function ArrayUnique(ar1) {
    var a = [];
    var l = ar1.length;
    for (var i = 0; i < l; i++) {
        for (var j = i + 1; j < l; j++) {
            // If this[i] is found later in the array
            if (ar1[i] === ar1[j]) {
                j = i + 1;
                i = i + 1;
            }
        }
        a.push(ar1[i]);
    }
    return a;
};

String.prototype.rot13 = function () {
    return this.replace(/[a-zA-Z]/g, function (c) {
        return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
    });
};

String.prototype.instrRegex = function (regex, flags) {
    var re = new RegExp(regex, flags);
    return re.exec(this).join('');
}
String.prototype.instrRegex = function (regex, flags) {
    var re = new RegExp(regex, flags);
    return re.exec(this).join('');
}

String.prototype.ltrim = function (chars) {
    chars = (chars) ? chars : "\\s";
    return this.replace(new RegExp("^[" + chars + "]+"), '');
}

String.prototype.rtrim = function (chars) {
    chars = (chars) ? chars : "\\s";
    return this.replace(new RegExp("[" + chars + "]+$"), '');
}

String.prototype.trim = function (chars) {
    return this.rtrim(chars).ltrim(chars);
}

String.prototype.rwordtrim = function () {
    return this.replace(/\W+\w+$/i, '');
}

function deobfuscate(selector) {
    $(selector).each(function () {
        if ($(this).attr('href').indexOf('@') == -1) {
            var protocol = $(this).attr('href').instrRegex('^.+:', 'gi');
            $(this).attr('href', protocol + $(this).attr('href').replace('$$$', '@').replace(/^.+:/gi, '').rot13());
            if ($(this).text().indexOf('$$$') != -1) {
                $(this).text($(this).text().replace('$$$', '@').rot13());
            }
        }
    });
}

function menumagic() {
    $('ul.topmenu > li').hoverIntent({
        over: function () { if ($(this).is('.current')) { $(this).removeClass('current').addClass('current__') } $(this).addClass('active').find('.sub').animate({ 'height': 'toggle', 'opacity': 1 }, 'fast'); },
        out: function () { if ($(this).is('.current__')) { $(this).removeClass('current__').addClass('current') } $(this).removeClass('active').find('.sub').animate({ 'height': 'toggle', 'opacity': 0 }, 'fast'); },
        timeout: 150,
        sensitivity: 7,
        interval: 40
    });
    $('ul.topmenu').hoverIntent({
        over: function () { $('.shroud').clearQueue().fadeIn('fast'); },
        out: function () { $('.shroud').clearQueue().fadeOut('fast'); },
        timeout: 150,
        sensitivity: 7,
        interval: 40
    });
    $('ul.topmenu .featuredsubmenu li').bind('click', function () {
        window.location.href = $(this).find('a').attr('href');
    }).css('cursor', 'pointer');
}

function prepToolTips() {
    $('span.tt span.ttcontent').corner('7px');
    $('span.tt').bind('mouseenter', function () {
        $(this).find('.ttcontent').animate({ opacity: 1, height: 'auto' }, 300);
    }).bind('mouseleave', function () {
        $(this).find('.ttcontent').animate({ opacity: 'toggle', height: 'toggle' }, 300);
    });
}


function FilledInput(element) {
    if (element && $(element).length > 0) {
        element = $(element)
    } else {
        return false;
    }

    element.filter('input[type=text], input[type=submit], textarea').bind('focus blur', function () {
        if ($(this).hasClass('init')) {
            $(this).removeClass('init').data('origval', $(this).val()).val('');
        } else if ($(this).val().length < 1) {
            $(this).addClass('init').val($(this).data('origval'));
        }
    });
    element.filter('select').bind('focus blur change', function () {
        if ($(this).find(':selected').val() == '-1') {
            $(this).addClass('init');
        } else {
            $(this).removeClass('init');
        }
    });
}

function buttons(element) {
    var element = (element) ? element : 'a.button';
    $(element).each(function () {
        var txt = $(this).text();
        $(this).html('<strong class="btn1">' + txt + '</strong><strong class="btn2">' + txt + '</strong>');
    });
}

function SearchResults(target, dataobj) {
    if (!dataobj) { return false; }
    
    this.itemspp = 12;
    this.target = (target) ? $(target) : $('.searchoverview');


    var list = dataobj.ArticleOverview;
    var TotalRecords = dataobj.TotalRecords;
    var currentsubset = dataobj.CurrentSubset;
    var subsetlength = 60;
    this.currentpage = dataobj.CurrentPage;
    var paging = this.target.find('.paging');

    this.getData = function (start, end) {
        var end = (end > TotalRecords) ? TotalRecords : end;
        var start = (start > 0) ? start : 0;
        if (list.length + (currentsubset * subsetlength) < end - 1 || ((currentsubset) * subsetlength) > start) {
            getNewResults(Math.floor((end - 1) / subsetlength), Math.floor(start / this.itemspp));
        } else {
            this.buildList(list.slice(start - (currentsubset * subsetlength), end - (currentsubset * subsetlength)));
        }
    };

    this.buildList = function (data, type) {
        if (data.length > 0) {
            for (var index = 0, len = data.length, toAppend = [], i = 0; index < len; index++) {
                toAppend[i++] = '<li data-href="';
                toAppend[i++] = data[index].IsCompany ? '/Company/' : '/Details/';
                toAppend[i++] = data[index].Title + '/';
                toAppend[i++] = data[index].ContentId + '/'; ;
                toAppend[i++] = '" data-vid="';
                toAppend[i++] = data[index].BrightCoveId;
                toAppend[i++] = '"><div class="thumb"><div class="';
                toAppend[i++] = (data[index].IsVideo) ? 'video' : 'novideo';
                toAppend[i++] = '" style="background-image: url(';
                toAppend[i++] = (this.itemspp == 1) ? '/ImageHandler.ashx?width=967&image=' : '/ImageHandler.ashx?width=163&image=';
                toAppend[i++] = data[index].ImageThumb;
                toAppend[i++] = ');"><div></div></div></div></div><div class="desc"><h3>';
                toAppend[i++] = (data[index].Title) ? ((this.itemspp != 1 && data[index].Title.replace(/\s?[|]\s?.+$/i, '').length > 26) ? data[index].Title.substr(0, 26).rwordtrim().trim('\|,.\\s') + '\u2026' : data[index].Title.replace(/\s?[|]\s?.+$/i, '')) : '';
                toAppend[i++] = '</h3>';
                if (data[index].Duration.Minutes > 0 || data[index].Duration.Seconds > 0) {
                    toAppend[i++] = ' <span class="duration">(';
                    toAppend[i++] = data[index].Duration.Minutes;
                    toAppend[i++] = ':';
                    toAppend[i++] = data[index].Duration.Seconds;
                    toAppend[i++] = ')</span>';
                }
                toAppend[i++] = '<p>';
                if (undefined == data[index].Text) {
                    toAppend[i++] = data[index].Text;
                } else if (this.itemspp == 1) {
                    toAppend[i++] = ((data[index].Text.length > 1150) ? data[index].Text.substr(0, 1150).rwordtrim().trim(',.\\s') + '\u2026' : data[index].Text);
                } else {
                    toAppend[i++] = ((data[index].Text.length > 75) ? data[index].Text.substr(0, 75).rwordtrim().trim(',.\\s') + '\u2026' : data[index].Text);
                }
                //toAppend[i++] = (this.itemspp == 1 || undefined == data[index].Text) ? data[index].Text : ((data[index].Text.length > 75) ? data[index].Text.substr(0, 75).rwordtrim().trim(',.\\s') + '\u2026' : data[index].Text);
                toAppend[i++] = '</p></div><div class="clear"></div></li>';
            }
            $(target).each(function () {
                $(this).find('ul').html(toAppend.join(''));
            });
        }
    };

    this.gotoPage = function (pagenumber) {
        if (pagenumber >= TotalRecords) { return false; }

        var pagenumber = (!isNaN(pagenumber)) ? pagenumber : 0;
        if (pagenumber == -1) {
            var end = TotalRecords;
            var pagenumber = Math.floor(TotalRecords / this.itemspp);
            var start = pagenumber * this.itemspp;
        }
        pagenumber = (pagenumber > Math.floor(TotalRecords / this.itemspp)) ? Math.floor(TotalRecords - 1 / this.itemspp) : pagenumber;

        var pagenumber = (pagenumber > -1) ? pagenumber : Math.floor(TotalRecords / this.itemspp);

        if (pagenumber > -1) {
            var start = pagenumber * this.itemspp;
            var end = start + this.itemspp;
        }

        this.currentpage = pagenumber;
        this.getData(start, end);
        paging.find('a').each(function () {
            if ($(this).text() == pagenumber) {
                $(this).addClass('active');
            }
        });
        $('.paging a').each(function () {
            if ($(this).text() == (pagenumber + 1).toString()) {
                $(this).addClass('active').siblings().removeClass('active');
                return false;
            }
        });
        $('#pageno').text(pagenumber + 1);

        //alert("huidige pagina: " + this.currentpage + "\n totaal pagina's: " + Math.floor(TotalRecords / this.itemspp) + "\ntotaal items: " + TotalRecords)
    };

    this.deliverVideo = function (vid) {
        var vid = (!isNaN(vid)) ? vid : 0;
        return dataobj.FlashMarkup.replace(/[*]{3}#BrightCoveID[*]{3}/gi, vid);
    };

}

function tabs() {
    $('span.tabtitel').bind('click', function () {
        $(this).closest('li').addClass('active').siblings('li').removeClass('active');
    });
}

function carousel(target) {
    var target = $(target);
    var ul = $(target).find('ul:eq(0)');
    var animspeed = 300;
    var stepsize = 3;
    var range = [0, 3];

    ul.find('li').bind('click', function () {
        window.location.href = $(this).find('a').filter(':first').attr('href');
    }).slice(range[0], range[1]).show();

    target.find('.scrollleft').bind('click', function (e) {
        if ((range[0] - (stepsize - 1)) < 0) {
            range[0] = ul.children('li').filter(':last').index() - (ul.children('li').filter(':last').index() % 3);
        } else {
            range[0] -= stepsize;
        }
        range[1] = range[0] + 3;
        ul.children('li').clearQueue().filter(':visible').not(':animated').animate({ width: 0, opacity: 0 }, animspeed, function () { $(this).hide() });
        ul.children('li').slice(range[0], range[1]).clearQueue().show().animate({ width: '336px', opacity: 1 }, animspeed);
        e.stopPropagation();
        e.preventDefault();
    });

    target.find('.scrollright').bind('click', function (e) {
        range[0] = (range[0] + (stepsize - 1) > ul.children('li').filter(':visible:last').index()) ? 0 : range[0] + stepsize;
        range[1] = range[0] + stepsize;
        ul.children('li').filter(':visible').clearQueue().not(':animated').animate({ width: 0, opacity: 0 }, animspeed, function () { $(this).hide() });
        ul.children('li').slice(range[0], range[1]).clearQueue().show().animate({ width: '336px', opacity: 1 }, animspeed);
        e.stopPropagation();
        e.preventDefault();
    });
}


/* VALIDATION */

function message(element, success, show, newtext, newheader) {
    if (!element) {
        return false;
    }

    element.hide();
    element.removeClass('error');
    element.removeClass('success');

    if (newtext && newheader) {
        element.find('.errorcontent').html('<h1>' + newheader + '</h1><p>' + newtext + '</p>');
    } else if (newtext && !newheader) {
        element.find('.errorcontent').html(newtext);
    }

    if (!show) {
        return false;
    }

    if (!success) {
        element.addClass('error');
    } else if (success == 1) {
        element.addClass('warning');
    } else if (success == 2) {
        element.addClass('info');
    } else if (success == 3) {
        element.addClass('success');
    } else {
        element.addClass('error');
    }

    element.find('.close').bind('click', function (event) {
        element.slideUp('slow');
        event.preventDefault();
    });

    element.fadeIn('slow');
}

function validation(testvalue, type, optional) {
    //returns true if valid
    var rege;
    if (testvalue.substr(0, 3).replace(/\s+/gi, '').length == 0 && typeof (optional) != undefined && optional == 'true') {
        return true;
    }

    if (!testvalue || testvalue == '' || undefined == testvalue || testvalue == -1) {
        if (!optional || undefined == optional || 'false' == optional) {
            return false;
        } else {
            return true;
        }
    }

    switch (type) {
        case 'email':
            //email address validation.
            rege = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
            break;
        case 'name':
            //extended
            rege = /^[a-zA-Z\u00C0-\u00FF\u011e\u011f\u0130\u0131\u015f\u015e\u0374-\u03FB\u1F00-\u1FFE. -]+$/i;
            break;
        case 'businessname':
            //extended
            rege = /^[a-zA-Z\u00C0-\u00FF\u011e\u011f\u0130\u0131\u015f\u015e\u0374-\u03FB\u1F00-\u1FFE&0-9. -]+$/i;
            break;
        case 'int_tel':
            rege = /^[+]\d{6,14}$/i;
            break;
        case 'tel':
            //dutch telnr: 10 digits starting with a zero.
            rege = /^0\d{9}$/i;
            break;
        case 'cell':
            //dutch cellular number: 06xxxxxxxx
            rege = /^06\d{8}$/i;
            break;
        case 'date':
            //full date: DD-MM-YYYY or D-M-YYYY
            rege = /^((0?[1-9]|[12][0-9]|3[01])[-](0?[1-9]|1[012])[-](?:19|20)\d{2})$/i;
            break;
        case 'dob':
            //full date: DD-MM-YYYY or D-M-YYYY
            rege = /^((0?[1-9]|[12][0-9]|3[01])[-](0?[1-9]|1[012])[-]19\d{2})$/i;
            break;
        case 'day':
            rege = /^(0?[1-9]|[12][0-9]|3[01])$/i;
            break;
        case 'month':
            rege = /^(0?[1-9]|1[012])$/i;
            break;
        case 'year':
            //19 or 20 with 2 digits following.
            rege = /^(?:19|20)\d{2}$/i;
            break;
        case 'dob_year':
            //19 with 2 digits
            rege = /^19\d{2}/i;
            break;
        case 'zip':
            //NL zipcode
            rege = /^\d{4}\s?[a-z]{2}$/i;
            break;
        case 'num':
            //nummeric only
            rege = /^\d+$/i;
            break;
        case 'CVV':
            //for use with credit card CVV validation code.
            rege = /^\d{3}$/i;
            break;
        case 'CCN':
            //for use with credit card number.
            rege = /^\d{16}$/i;
            break;
        case 'kvk':
            //KVK nummers valideren
            rege = /^\d{8}$/i;
            break;
        case 'ID':
            //for use with dutch ID
            rege = /^\w{8,12}$/i;
            break;
        case 'bankaccount':
            rege = /^\d+$/i;
            break;
        case 'password':
            rege = /^[a-zA-Z0-9]{8,}$/i;
            break;
        case 'nl_bankaccount':
            switch (testvalue.length) {
                case 9:
                case 10:
                    rege = /^\d{9,10}$/i;
                    return testvalue.ElfCheck() && rege.test(testvalue);
                    break;
                case 8:
                    return false;
                    break;
                default:
                    rege = /^\d{5,7}$/i;
                    break;
            }
            break;
        case 'multiline':
            rege = /^[-_ 0-9a-zA-Z\u00C0-\u00FF\u011e\u011f\u0130\u0131\u015f\u015e\u0374-\u03FB\u1F00-\u1FFE\u20AC.]+$/mi;
            break;
        case 'text':
            rege = /^[^<>]+$/i;
            break;
        default:
            rege = /^[-_ 0-9a-zA-Z\u00C0-\u00FF\u011e\u011f\u0130\u0131\u015f\u015e\u0374-\u03FB\u1F00-\u1FFE\u20AC.]+$/i;
            break;
    }
    return testvalue.substr(0, 3).replace(/\s+/gi, '').length != 0 && rege.test(testvalue);
}

function ValidateThis(element) {
    $(element).each(function () {
        if (validation($(this).val(), $(this).data('validation'), $(this).data('optional'))) {
            Valid($(this));
        } else {
            inValid($(this));
        }
    });
}

function ValidateInitialize(element) {
    $(element).each(function () {
        $(this).data('validation', $(this).attr('validation'));
        $(this).data('optional', $(this).attr('optional'));
        $(this).data('validationname', $(this).attr('validationname'));
        $(this).bind('change', function () {
            ValidateThis($(this));
        });
        $(this).bind('keyup', function () {
            if ($(this).is('.invalid')) {
                ValidateThis($(this));
            }
        });
        $(this).removeAttr('validation');
        $(this).removeAttr('optional');
        $(this).removeAttr('validationname');
    });
}

function ValidateAll(element) {
    var counter = 0;
    var invalids = '';
    $(element).each(function () {
        if (!$(this).val() == '' || $(this).data('optional') == 'true') {
            if (validation($(this).val(), $(this).data('validation'), $(this).data('optional'))) {
                counter++;
                Valid($(this));
            } else {
                inValid($(this));
                if ($(this).data('validation') == 'tel' && !$(this).data('optional') && $(this).val().length < 10) {
                    invalids += '<li> Een mobiel nummer dient uit 10 cijfers te bestaan.</li>';
                } else if ($(this).data('validation') == 'CCN' && !$(this).data('optional') && $(this).val().length < 13) {
                    invalids += '<li> Het creditcard nummer is niet correct.</li>';
                } else {
                    invalids += '<li>' + $(this).data('validationname') + '</li>';
                }
            }
        } else {
            invalids += '<li>' + $(this).data('validationname') + ' is leeg</li>';
            inValid($(this));
        }
    });

    if (counter == $(element).length) {
        return true;
    } //else
    return invalids;
}

function Valid(element) {
    $(element)
        .addClass('valid').removeClass('invalid')
        .parent('span').addClass('valid').removeClass('invalid')
        .parent('li').addClass('valid').removeClass('invalid');
}
function inValid(element) {
    $(element)
        .addClass('invalid').removeClass('valid')
        .parent('span').addClass('invalid').removeClass('valid')
        .parent('li').addClass('invalid').removeClass('valid');

}

function doValidateAll(checkelement, statusboxel) {
    var valid = ValidateAll(checkelement);
    if (valid === true) {
        return true;
    }
    message(statusboxel, false, true, '');
    return false;
}

function validateRadio(element) {
    var total = [];
    var select = [];
    $(element).find('input[type=radio]').bind('change', function () {
        validateRadio(element);
    });
    $(element).find('input[type=radio]').filter(':visible').each(function () {
        total.push($(this).attr('name'));
    });
    $(element).find('input[type=radio]').filter(':visible').filter(':checked').each(function () {
        select.push($(this).attr('name'));
    });
    var diff = ArrayDiff(ArrayUnique(select), ArrayUnique(total));
    //var diff = select.unique().diff(total.unique());
    Valid($(element).find('input[type=radio]').parent());
    if (diff.length > 0) {
        var x = 0;
        //$.browser.msie && $.browser.version < 9
        $('input[type=radio]').each(function (index, radiobtn) {
            if (!$(radiobtn).is('.' + $(radiobtn).attr('name').replace(/\W/gi, ''))) {
                $(radiobtn).addClass($(radiobtn).attr('name').replace(/\W/gi, ''));
            }
        });
        while (x < diff.length) {
            inValid($('.' + diff[x].replace(/\W/gi, '') + '').parent());
            x++;
        }
        return false;
    }
    return true;
}

function validateDate(element, year, modifier) {
    var yearyear = (year) ? year : 0;
    var today = new Date();
    var dates = true;

    $(element).each(function (ind, tr) {
        if ($(tr).find('input').length == 3) {
            var datetemp = '';
            $(tr).find('input').each(function (index, input) {
                datetemp += $(this).val();
            });
            var testdate = new Date(datetemp.substr(4, 4), datetemp.substr(2, 2), datetemp.substr(0, 2));
            today.setFullYear(today.getFullYear() + year);

            var tmp = (modifier == 'gte') ? today >= testdate : today <= testdate;

            if (tmp && testdate.isValid()) {
                dates = dates && true;
            } else {
                inValid($(tr).find('input'));
                dates = dates && false;
                if (year == 18 && modifier == 'gte') {
                    message($('#error'), false, true, 'Je bent nog geen 18 jaar oud.');
                } else if (year == 0 && modifier == 'lte') {
                    message($('#error'), false, true, 'Startdatum dient in de toekomst te liggen');
                }
            }
        }
    });
    return dates;
}

//liScroll 1.0
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 = 1;
        $strip.find("li").each(function (i) {
            stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar and Fabien Volpi
        });
        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.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);
				});
    });
};

