
/**
 * Biznet PixelProfesional.com Javascript functions
 * @author cowanb
 * 0.8 - 1 - bcowan - 2008/10/22 :: First verision with History, added $.bzPix.reTooltip
 */

$.bzPix=new Object();
$.bzPix.t=new Object();

//Make sure we only add tooltip event for new items (using xph.tooltip)
$.bzPix.reTooltip=function()
{
  $('*[tooltip]').each(function() {
    var tt=$(this);
    if(!tt.hasClass('tooltipped')) {
      var ttxt=tt.attr('tooltip');
      tt.tooltip({text:ttxt });
      tt.addClass('tooltipped');
    }
  });
}
$.bzPix.t.clickIc=0;

$.bzPix.clickOut=function(id,left)
{
  if(left>1) {
    $('#'+id).hide('puff','fast',null,function() {$.bzPix.clickOut(id,(left-1)); });
  } else {
    $('#'+id).hide('puff','slow');
  }
}
$.bzPix.showClicks=function(sel,num)
{
  num=num || 3;
  to=0;
  var ic=$.bzPix.t.clickIc;
  $(sel || '.click').each(function(){
    var l=$(this).offset().left;
    var t=$(this).offset().top;
    var w=$(this).width();
    var h=$(this).height();
    if(t<120) {
         var iob=$('<img id="clkout_'+ic+'" src="/img/click.gif" style="position:absolute;top:'+(t+h)+'px;left:'+(l+(w/2))+'px;z-index:900;" onclick="$(this).hide(\'slow\');"/>');
    
    } else {
      var iob=$('<img id="clkout_'+ic+'" src="/img/click.gif" style="position:absolute;top:'+(t-20)+'px;left:'+(l+w)+'px;z-index:900;" onclick="$(this).hide(\'slow\');"/>');
    }
    $('body').append(iob);
    setTimeout('$.bzPix.clickOut("clkout_'+ic+'",'+num+');',100);
    
    ic++;
    $.bzPix.t.clickIc=ic;
   
  });
  
}
//Esto pone una foto en un cuadro
$.bzPix.fitFoto=function(div_elm,foto_url)
{
  $.bz.taboverlay.hide();
  
  //$.bz.msg(div_elm.id+" - "+foto_url);
  var d=new Date();
  $(div_elm).get(0).style.background='url('+foto_url+'?'+d.getTime()+') center no-repeat';

}

$.bzPix.vote=function(id,pad)
{
	$.post('/foto/'+id+'/votar.js',{"authenticity_token": authenticity_token,"vote":pad},function(data){
			var ret;
			eval('ret='+data);
			$.bz.msg(ret.msg,4);
			if (ret.score != null) {
				$("#idiv_score_" + id).html(ret.score);
			}
			if(ret.p_score!=null) {
				$("#cal_1").html(ret.c_score[1]);
				$("#cal_2").html(ret.c_score[2]);
				$("#cal_3").html(ret.c_score[3]);
				$("#cal_4").html(ret.c_score[4]);
			}
		});

}

$.bzPix.medal=function(id,position)
{
	$.post('/foto/'+id+'/medalla.js',{"authenticity_token": authenticity_token,"position":position},function(data){
			var ret;
                
			eval('ret='+data);
                       
			if(ret.msg){$.bz.msg(ret.msg,4);}
			if(ret.reload){window.location.reload();}
		});

}
$.bzPix.t.informacionTipo="foto";
$.bzPix.cambiarInformacion=function(id,titulo)
{
	$.bz.post('foto',id,'informacion',{"titulo":titulo})
	
}
var borrarTipo="foto";
$.bzPix.t.del=function(id)
{
	$.post('/'+borrarTipo+'/'+id+'/borrar.js',{"authenticity_token": authenticity_token},function(data){
			var ret;
			eval('ret='+data);
			if(ret.msg){$.bz.msg(ret.msg,4);}
			if(ret.eval){eval(ret.eval);}
				
			
		});
	
}
$.bzPix.borrarComentario=function(id)
{
	borrarTipo="comentario";
	$.bzPix.confirmDelete(id);
	
}
$.bzPix.confirmDelete=function(id) {
	
//	e.jGrowl('<input type="button" onclick="$.bzPix.t.delete();" value="Si"> / <input type="button" onclick="$.bzPix.t.closer.jGrowl(\'shutdown\');" value="No">', {header: 'Seguro Que Quieres Borrar?'} );
	$.bz.msg('Seguro Que Desea Borrar? <input type="button" onclick="$.bzPix.t.del('+id+');" value="Si"> ' );
}

var oldId=0;
$.bzPix.emitirComentario=function(cid)
{
	var d={
		"id":cid,
		"oldid":oldId,
		"titulo":$('#i_titulo').val(),
	    "txt":$('#i_comentario').val(),
		"authenticity_token":authenticity_token
		};
	
	$("#commentarios_de_foto").load('/tx/comentar.html',d);
	
}


/* --------- CRITICAS ---------------*/
//Esta funcion emite a ser criticada la foto
$.bzPix.emitirCritica=function(id)
{	
	$.bz.post('foto',id,'emitir_a_critica_publica');
}

$.bzPix.emitirPool=function(id,p_id)
{
	$.bz.post('foto',id,'emitir_a_pool',{pool_id:p_id});
}


