Cufon.replace('h1, .subHdr, .sidebarHdr', { fontFamily: 'Gotham' });

var full_text = '';
var short_text = '';
var showing_full = false;

var vote_text = '';
var vote_class = '';

$(document).ready(function() {

	full_text = $("#videoDescriptionFull").html();
	short_text = $("#videoDescription").html();

	$("a#showMore").click(function() {
		if( !showing_full ) {
			$(this).text("Show Less...");
			$("#videoDescription").html(full_text);
			showing_full = true;
		} else {
			$(this).text("Show More...");
			$("#videoDescription").html(short_text);
			showing_full = false;
		}
		return false;
	});

	vote_text = $("#videoVoteCount").text();
	vote_class = $("#videoVoteStars").attr("class");

	if( $("#videoVote").hasClass("enabled") ) {
		$(".videoStar").hover(vote_over, vote_out);

		$(".videoStar").click(vote);
	}

});

function vote() {
	vote_disable();
	var vote = $(this).attr("vote");
	var text = $(this).text();
	$("#videoVoteCount").text("Casting vote...");

	var url = site_url + '/videos/vote.json?' +
		'&i=' + escape($("#videoID").val()) +
		'&r=' + escape(vote);
	
	//$("#debug").load(url);
	//$("#debug").html("0: " + url);
	$.getJSON(url, function(data) {
		//$("#debug").html("1: " + url);
		if( data.status == "OK" ) {
			//$("#debug").html("2: " + data.question_id);
			$("#videoVoteCount").text(data.message);
		} else {
			$("#videoVoteCount").text(data.message);
			//vote_enable();
		}

	});
	
}

function vote_over() {
	var vote = $(this).attr("vote");
	var text = $(this).text();
	$(this).parent("#videoVoteStars").removeClass(vote_class).addClass("voteImage" + vote);
	$("#videoVoteCount").text(text);
}

function vote_out() {
	var vote = $(this).attr("vote");
	$(this).parent("#videoVoteStars").removeClass("voteImage" + vote).addClass(vote_class);
	$("#videoVoteCount").text(vote_text);
}

function vote_disable() {
	$("#videoVote").removeClass("enabled");
	$(".videoStar").unbind("click").unbind("hover");
}
function vote_enable() {
	$("#videoVote").addClass("enabled");
	$(".videoStar").click(vote).hover(vote_over, vote_out);
}

