var videosPag = 0;
var favPag = 0;
var fu = 'u';
var ajax_target = "#Conteudo";
var baseLink = "";
function hoverIn(o) {
	// alert($(o).css('opacity'));
	if ($(o).css('opacity') == 0) {
		$(o).show();
		$(o).fadeTo(100, 0.8);
	} else {
		$(o).show();
	}
}
function hoverOut(o) {
	if ($(o).css('opacity') != 0) {
		$(o).fadeTo(100, 0.0, function() {
			$(o).hide();
		});
	}
}

function interfaceTabela(){
	
}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}


function addRemFav(id, tipo) {
	// $('#fav_ico_'+id)
	if (tipo == 1) {
		$.getJSON(baseLink + "Video/favorito/" + id, function(msg) {
			eval(msg['callback']);
		});

	} else {
		$.getJSON(baseLink + "Video/remfavorito/" + id, function(msg) {
			eval(msg['callback']);
		});
	}
}

function addRemFavNew(id, tipo) {
	// $('#fav_ico_'+id)
	if (tipo == 1) {
		$.getJSON(baseLink + "video/favoritoNew/" + id, function(msg) {
			eval(msg['callback']);
		});

	} else {
		$.getJSON(baseLink + "video/remfavoritoNew/" + id, function(msg) {
			eval(msg['callback']);
		});
	}
}

function ligaFavorito(id) {
	var k = document.getElementById('fav_ico_' + id);
	var l = document.getElementById('fav_lnk_' + id);
	if (k.src.indexOf('/f/img/ico_coracao_003.gif') > 0) {
		k.src = '/f/img/ico_coracao_000.gif';
		l.href = 'javascript:addRemFav(' + id + ',1)';
		//fizNotify.notice('Removido dos favorito', 'O v&iacute;deo foi removido dos seus favoritos');
	} else {
		k.src = '/f/img/ico_coracao_003.gif';
		l.href = 'javascript:addRemFav(' + id + ',0)';
		//fizNotify.notice('Adicionado aos favoritos', 'O v&iacute;deo foi adicionado aos seus favoritos');
	}
}

function ligaFavoritoNew(id) {
	alert('Video adicionado aos favoritos');
/*	var k = document.getElementById('fav_ico_' + id);
	var l = document.getElementById('fav_lnk_' + id);
	if (k.src.indexOf('/f/img/usuario/ico_favoritos_on.gif') > 0) {
		k.src = '/f/img/usuario/ico_favoritos_off.gif';
		l.href = 'javascript:addRemFavNew(' + id + ',1)';
		//fizNotify.notice('Removido dos favorito', 'O v&iacute;deo foi removido dos seus favoritos');
	} else {
		k.src = '/f/img/usuario/ico_favoritos_on.gif';
		l.href = 'javascript:addRemFavNew(' + id + ',0)';
		//fizNotify.notice('Adicionado aos favoritos', 'O v&iacute;deo foi adicionado aos seus favoritos');
	}*/
}
function desligaFavoritoNew(id) {
	alert('Video removido dos favoritos');
/*	var k = document.getElementById('fav_ico_' + id);
	var l = document.getElementById('fav_lnk_' + id);
	if (k.src.indexOf('/f/img/usuario/ico_favoritos_on.gif') > 0) {
		k.src = '/f/img/usuario/ico_favoritos_off.gif';
		l.href = 'javascript:addRemFavNew(' + id + ',1)';
		//fizNotify.notice('Removido dos favorito', 'O v&iacute;deo foi removido dos seus favoritos');
	} else {
		k.src = '/f/img/usuario/ico_favoritos_on.gif';
		l.href = 'javascript:addRemFavNew(' + id + ',0)';
		//fizNotify.notice('Adicionado aos favoritos', 'O v&iacute;deo foi adicionado aos seus favoritos');
	}*/
}

function apagarVideo(a, b) {
	//alert(a + ":" + b);
	myData = {
		'video' :b,
		'key' :a
	};
	$.post(baseLink + "Video/remVideo", myData, function(msg) {
		eval(msg.callback)
	}, "json");

	return false;
}
function apagarVideoOK(i) {
	fizNotify.notice('V&iacute;deo apagado com sucesso', 'O v&iacute;deo foi apagado com sucesso!');
	$('#vtfe_'+i).hide(100);
}
function erroApagarVideo() {
	fizNotify.error(
					'V&iacute;deo n&atilde;o pode ser apagado',
					'Ele pode ter ido pra TV ou alguma coisa de errado aconteceu na hora de apagar.');
}
function excluirVideoMesmo(call){
	$('.jGrowl-notification-status').animate({opacity: 'hide'}, 'normal', 'swing', function() {
		$(this).remove();
	});

	eval(call);
}
function doErase(callback){
	fizNotify.eraseVideo(callback);
}


function hvrIn(el){
	$('#'+el).stop().scrollTo(124,150);
}
function hvrOut(el){
	$('#'+el).stop().scrollTo(0,150);
}
function trunc(txt,len){
	var newTxt ='';
	if (txt.length>len){
		newTxt = txt.substr(0,len-3) + "...";
	}else{
		newTxt = txt;
	}
	return newTxt;
}

