$().ready(function() {
    Adecco.limitDescriptionHeight();
    Adecco.rotationEffect();
});
Adecco = {
    limitDescriptionHeight: function() {
        var descriptionLinesNumber;
        var lineHeight;
        var descriptionFontSize;
        var maxDescriptionHeight;

        descriptionLinesNumber = $("[id$='_descriptionLinesNumber']").val();
        lineHeight = $('.RotatingVacanciesWP .vacanciesRotator .description').css('line-height');
        lineHeight = lineHeight.replace("px", "");
        descriptionFontSize = $('.RotatingVacanciesWP .vacanciesRotator .description').css('font-size');
        descriptionFontSize = descriptionFontSize.replace("px", "");
        maxDescriptionHeight = (lineHeight * (descriptionLinesNumber - 1)) + (lineHeight - descriptionFontSize);

        $('.RotatingVacanciesWP .vacanciesRotator .description').css('max-height', maxDescriptionHeight);
    },

    rotationEffect: function() {
        $(document.body).addClass('hasJs');

        if ($(document.body).hasClass('hasJs')) {
            $(function() {
                //cache the ticker
                var ticker = $('.ticker');

                //animator function  
                function animator(currentItem) {
                    //work out new anim duration  
                    var distance = currentItem.height(),
					duration = new Number($("[id$='_rotationSpeed']").val());


                    //animate the first child of the ticker  
                    currentItem.animate({ marginTop: -distance }, duration, 'linear', function() {
                        //move current item to the bottom
                        currentItem.appendTo(currentItem.parent()).css('marginTop', 0);
                        //recurse  
                        animator(currentItem.parent().children(':first'));
                    });
                };

                //start the ticker
                ticker.each(function() {
                   
                    //in case the height of content exceeds its container the scrolling effect starts
                    if ($(this).height() > $(this).parent().height()) {
                        animator($(this).children(':first'));
                        
                        //set mouseover
                        $(this).mouseover(function() {
                            //stop current animation
                            $(this).children().stop();
                        });

                        //set mouseleave
                        $(this).mouseout(function() {
                            //resume animation
                            animator($(this).children(':first'));
                        });
                    }
                });
            });
        }
    }
}