function play(div_id, media_id, still, video, titulo, texto, url) {
	var so = new SWFObject("/js/mediaplayer/player.swf","mpl", "350", "233", "9");
	so.addParam("allowscriptaccess", "always");
	so.addParam("allowfullscreen", "true");
	so.addParam("autoplay", "false");
	so.addParam("flashvars", "&image=" + still + "&file=" + video + "&controlbar=over");
	so.write(div_id);
	$(".videoFeature a.selected").removeClass("selected");
	$("#videoThumb_" + media_id).addClass("selected");
	
	if (url != '')
	{
		titulo = '<a href="http://' + url + '" alt="' + titulo + '"><span>' + titulo + '</span></a>';
	}
	
	$("#videoTitle").html("<span>" + titulo + "</span>");
	$("#videoDescription").html("<span>" + texto + "</span>");
	//$("#videoTitle").attr("href", "midia/" + media_id);
	showRank(media_id);
};

function checkRadios(form) {
	var el = form.elements;
	for ( var i = 0; i < el.length; ++i) {
		if (el[i].type == "radio") {
			var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
			var itemchecked = false;
			for ( var j = 0; j < radiogroup.length; ++j) {
				if (radiogroup[j].checked) {
					return radiogroup[j].value;
					itemchecked = true;
					break;
				}
			}
			if (!itemchecked) {
				if (el[i].focus)
					el[i].focus();
				return false;
			}
		}
	}
	return true;
}

function vote(form) {
	var err = 0;
	var v = checkRadios(form);
	if (v <= 0) {
		err = 1;
		alert("Escolha uma das opções");
	} else {
		voteVal = v;
		$.post("ajax/ajax.php", {
			form_action :"addVote",
			vote :voteVal
		}, function(data) {
			eval(data);
		});
	}
}

function pollGetResults(divId) {
	$.post("ajax/ajax.php", {
		form_action :"displayPollResults",
		poll_id :divId
	}, function(data) {
		$('#enquete_content').html(data);
	});
}

function setRanking(type, id, rank){
	$.post("/ajax/ajax.php", { form_action: 'setRanking', type: type, id: id, rank: rank },
	function(data){
		rankStarShow(1,data.rank);
		$('#rankingInicialState').attr({value: data.rank});
		$('#rankingMediaId').attr({value: data.media_id});
		$('.midiaLink').attr({href: 'midia/'+data.media_id});
		$('#comments').html({value: data.comments});
		$('#views').html({value: data.views});
	}, "json");
}

function getRanking(rid, type, id){
	showRank(id);
}

function showRank(id) {
	setRanking('media', id, 0);
	$(".icoEstrela").pngFix();
}

function rankStarShow(id,star) {
	for (x=1; x <= 5; x++) {
		if (x <= star)
			$("#star"+x).css("background-image","url(images/icoRatingStarFull.png)");
		else
			$("#star"+x).css("background-image","url(images/icoRatingStarEmpty.png)");
	}
};

function displayRanking(rank) {
	for (x=1; x <= 5; x++) {
		if (x <= rank)
			document.write('<img src="images/icoRatingStarFull.png" class="icoEstrela" id="star'+x+'" />');
		else
			document.write('<img src="images/icoRatingStarEmpty.png" class="icoEstrela" id="star'+x+'" />');			
	}
}



/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
 
function mycarousel_initCallback(carousel) {
	carousel.options.scroll = jQuery.jcarousel.intval(7);

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

