var selectClosestCompany = function (){
    jQuery.getJSON('/company/setCookie', {
        companyId: arguments[0]
        }, function(data){
        if(data.status == "success"){
            if (jQuery('#dialog-modal-map, #dialog-modal-map-container').is(':visible'))
            {
                jQuery('#company-asset').data('company-selected', true);
                jQuery('#company-asset img').attr('src', data.medium);
                jQuery('#header-company .company-link').attr('href', data.company);
                jQuery('#company-city a').html(data.city);
                jQuery('#company-link').show();
                jQuery('#dialog-modal-map, #dialog-modal-map-container').hide();
            }
            else
            {
                document.location = data.company;
            }
        }
        else
        {
            alert(data.mesg);
        }
    });
};

jQuery(document).ready(function() {
    if (jQuery('#company-infos-text li').length > 0)
    {
        jQuery('#company-infos-text').marquee();
    }
});

jQuery.fn.marquee = function(settings) {
    settings = jQuery.extend({
        travelocity: 0.07
    }, settings);		
    return this.each(function(){
        var scrollnews = function (maxWidth, scrollTime){
            $strip.animate({left: '-='+ maxWidth}, scrollTime, "linear", function(){
                $strip.css("left", containerWidth);
                scrollnews(maxWidth, scrollTime);
            });
        }
        var $mask = jQuery(this);
        var $strip = jQuery('ul:first', this);
        var $els = jQuery('li', this);

        var stripWidth = 0;
        var containerWidth = $mask.width();
        
        $els.each(function(){
            stripWidth += jQuery(this).outerWidth(true);
        });
        //bug
        stripWidth = stripWidth*1.5;
        $strip.width(stripWidth);

        var totalTravel = stripWidth+containerWidth;
        var defTiming = totalTravel/settings.travelocity;
	
        scrollnews(totalTravel, defTiming);

        $strip.hover(
            function(){
                jQuery(this).stop();
            },
            function(){
                var offset = jQuery(this).position();
                var residualSpace = offset.left + stripWidth;
                var residualTime = residualSpace/settings.travelocity;
                scrollnews(residualSpace, residualTime);
            }
        );
    });
};

