/**
 * @author pedromoraes@gmail.com
 */
var visibleList = "clients";
$(document).ready(function() {
	$("#bt_clients").click(function(){
		if ( visibleList == "clients" ) return false;
		else
		{
			visibleList = "clients";
			$(".clients_page, #client_nav").show();
			$(".releases_page, #releases_nav").hide();
			$(this).attr("class", "on");
			$("#bt_releases").attr("class", "off");
			setPage( 1 );
		}
		return false;
	});
	$("#bt_releases").click(function(){
		if ( visibleList == "releases" ) return false;
		else
		{
			visibleList = "releases";
			$(".releases_page, #releases_nav").show();
			$(".clients_page, #client_nav").hide();
			$(this).attr("class", "on");
			$("#bt_clients").attr("class", "off");
			setPage( 1 );
		}
		return false;
	});
	$(".release a").click(function(){
		id = $(this).attr("id").substr(1);
		$.history.load(id);
		return false;
	});
	$("#client_nav a, #releases_nav a").click(function(){
		var p = parseInt($(this).attr("id").substr(2));
		setPage( p );
		return false;
	});
	
	function openRelease( id ) {
		$(".internal_content .text").html( $("#release_"+id).html() );
		$(".internal_content .title").html( $('#r'+id).html() );
		return false;
	}
	
	var callback = function(h) {
		if ( h && h != '#' )
			openRelease(h);
	}
	
    $.history.init(callback);
    $("a[rel=history]").click(function(){
        $.history.load(this.href.replace(/^.*#/, ''));
        return false;
    });
	
	
	lock($(".page #1"));
});

function setPage( p ) {
	if ( visibleList == "clients" )
	{
		unlock($("#client_nav a"));
		$(".clients_page").hide();
		$("#clients_" + p).show();
		lock($("#cp" + p));
	}
	else
	{
		unlock($("#releases_nav a"));
		$(".releases_page").hide();
		$("#releases_" + p).show();
		$.history.load(p);
		lock($("#rp" + p));
	}
}

function unlock( link ) {
	link
	.css("cursor","pointer")
	.css("color", "#ffffff")
	.css("background-color", "#232323");
}
function lock( link ) {
	link
	.css("cursor","normal")
	.css("color", "#232323")
	.css("background-color", "#f9a451");
}
function setContent( title, text ) {
	
}
