function createLink(params) {
	return getBaseUrl() + '/' + params.controller + '/' + params.action;
}

function HeroAnimation() {
	
	var container;
	
	var pages = 0;
	
	var currentPage = -1;
	
	var timer;
	
	this .init = function (container, duration) {
		this .container = $('#' + container);
		
		pages = $('.page', this .container) .size();
		
		if ($('.pageSelector', this .container) .size() != pages) {
			//alert('Number of page selectors does not match number of pages! HeroAnimation might behave in unexpected ways!');
		}
		
		setupEventHandlers();
		
		switchToPage(0, true);
		
		timer = $.timer(duration, function(timer) {
			var newPage = (currentPage + 1) % pages;
			switchToPage(newPage);
		});
	}
	
	function setupEventHandlers() {
		
		$('.page', container) .each(function (i) {
			$(this).css('position', 'absolute');
		});
		
		$('.pageSelector', container) .each(function (i) {
			var num = i;
			$(this) .click(function (e) {
				timer.stop();
				switchToPage(num);
				return false;
			});
		});
	}
	
	function switchToPage(num, theFirstTime) {
        if (theFirstTime == null)
            theFirstTime = false;
        if (num == currentPage) {
			return;
		}
		
		// Get the new page, place it under the current page and make it visible. Then fade out the current page.
		
		$('.pageSelector:eq(' + currentPage + ')', container).removeClass('active');
		$('.pageSelector:eq(' + num + ')', container).addClass('active');
		
		var old = $('.page:eq(' + currentPage + ')', container);
		old.css('z-index', '100');
		
		currentPage = num;
		
		var toShow = $('.page:eq(' + num + ')', container);
		toShow.css('z-index', '99');
		toShow.show();
		if (!theFirstTime)
            old.fadeOut(500);
	}
}

/*
 * Set up event handlers for the login box if applicable.
 */
$(function() {

	var openLoginBox = $('.openLoginBox');
	if (openLoginBox != null) {
		openLoginBox.click(function(e) {
			$('.loginBox').fadeIn(500, function() {
				$('#username').focus();
			});
			return false;
		});
	}
	
	var loginBox = $('.loginBox');
	if (loginBox != null) {
		var closeButton = $('.closeButton', loginBox);
		closeButton.click(function(e) {
			loginBox.hide();
		});
		
		var loginButton = $('#loginButton', loginBox);
		loginButton.click(function(e) {
		
		});
	}
});


function fbs_click() {
	u=window.location;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
}

function twitter() {
	var u=window.location;
	var t=document.title;
	window.open('http://www.twitter.com/home?status=' + u,'sharer','toolbar=0,status=0,width=800,height=600');return false;
}

function digg() {
	var u=window.location;
	var t=document.title;
	window.open('http://digg.com/submit?url=example.com&amp;title=${newsItemInstance.title}&amp;bodytext=${newsItemInstance.teaser}&amp;topic=TOPIC' + u,'sharer','toolbar=0,status=0,width=800,height=600');return false;
}
