$(document).ready(function(){

	//Open all links with rel="external" in new window
	$('a[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
    });
	
	getTwitters('tweet', { 
		id: 'cinemagic', 
		count: 1, 
		enableLinks: true, 
		ignoreReplies: true, 
		clearContents: true,
		template: '%text% <a href="http://twitter.com/%user_screen_name%/statuses/%id%/">%time%</a>'
	});
	
});

var mylib =
{
    news_ticker:
	{
	    init: function () {
	        $("#news-ticker p.loading").fadeOut(9000);
	        var i = 1;
	        $("#news-items li").each(function () {
	            $(this).attr("id", "item" + i);
	            i++;
	        });

	        var newsList = $("#news-items li"),
		    totalItems = $("#news-items li").length;
	        newsList.first().addClass("current-news");
	        var currentItem = $(".current-news").attr("id"),
		    itemNum = parseInt(currentItem.slice(4));
	        $("#news-items li").hide();

	        var newsTicker = function () {
	            var stringLength = parseInt($("#item" + itemNum).text().length);
	            var duration = stringLength * 55;
	            $("#item" + itemNum).removeClass("current-news");
	            $("#item" + itemNum).fadeOut(350);
	            if (itemNum >= totalItems) {
	                itemNum = 1;
	            }
	            else {
	                itemNum++
	            }
	            $("#item" + itemNum).addClass("current-news").show();
	            var liWidth = $("#item" + itemNum).css("width");
	            $(".hide").show().animate({ "left": liWidth }, duration).fadeOut().animate({ "left": "0" }, 0);
	        }
	        if (totalItems > 1) {
	            window.setInterval(newsTicker, 9000);
	        }
	        else {
	            window.setTimeout(newsTicker, 9000);
	        }
	    }
	}
}
