var console;
var d = function($var) {
    if (null == console) {
        alert($var);
    } else {
        console.log($var);
    }
};

/**
 * Text scrolling
 */
var Slider = (function () {
	var $text,
		height,
		margin,
		lineHeight,
		textHeight,
		blockIsInserted = false;

	function checkSize() {
		if (((margin + textHeight) <= (textHeight / 2)) && (blockIsInserted == false)) {
			var $html = $('<div class="inside" />').append($text.html());
			$text.parent().append($html);
			blockIsInserted = true;
		} else if (((margin + textHeight) == 0) && (blockIsInserted = true)) {
			$text = $text.parent().find('.inside:last');
			blockIsInserted = false;
			margin = 0;
			setTimeout(function () {
				$text.parent().find('.inside:not(:last)').remove();
			}, 1500);
		}
	}

	return {
		init: function () {
			$text = $('#welcome-text').find('.inside');
			height = $text.height();
			margin = 0;
			lineHeight = parseInt($text.css('line-height'), 10) || 15;
			textHeight = $text.height();
			wrapHeight = $('#welcome-text').height();
		},

		run: function () {
			margin -= lineHeight;
			$text.animate({'margin-top': margin}, 600);

			checkSize();
		}
	};
})();

// DOM is ready
$(function () {
    // drop-down menu
    $('.root>li').mouseover(function () {
        var $this = $(this);

        $('ul.inner').hide();
        $this.find('ul:first').show();
        $this.find('a:first').addClass('active');
    }).mouseout(function() {
        $('ul.inner').hide();
        $(this).find('a:first').removeClass('active');
    });

    // tabs
    $('#cargo-tabs, #cargo-locations').find('a').click(function () {
        $(this).parents('ul:first').find('li').each(function () {
            $(this).removeClass('cargo-act');
        });

        $(this).parents('ul:first').find('a').each(function () {
            $(this.hash).hide();
        });

        $(this.hash).show();
        $(this).parent().addClass('cargo-act');
        return false;
    });

	Slider.init();
	setInterval("Slider.run()", 3000);


    if ($.fn.lightBox) {
        $('a.lightbox').lightBox();
    }
});

