/**
*Procedimientos y funciones de uso general
*
*/
var nav4 = window.event ? true : false;
var tipmage = "";

$( document ).ready(function(){
	/*
	$("#fotos").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		scroll: 1,
		visible: 1,
		speed:500,
		circular: "false",
		afterEnd: function( a ) {

			$("#idfoto").val( a.attr("rel") );
			$(".linkcomentarios").attr("href","comentarios.php?id=" + a.attr("rel") ) ;

			incializatip( a.attr("rev") );

		}

	});
	*/
	
	/*
	 * Nuestro calendario 
	 */
	/*Date.firstDayOfWeek = 7;
	Date.format = 'yyyy-mm-dd';
	
	$('.calendar').datePicker();*/	
	
//solo numeros
	$( "input.onlynumber" ).keypress(function( evt ){
		var key = nav4 ? evt.keyCode : evt.which;
		return /[\d]/.test( String.fromCharCode( key ) );
	});
	
	//monetario
	$( "input.money" ).keyup(function(){
		this.value = number_format( this.value );
	});
	
	//solo letras
	$( "input.onlyword" ).keypress(function(){
		var key = nav4 ? evt.keyCode : evt.which;
		return /[\w]/.test( String.fromCharCode( key ) );
	});
	
	$( "form.formvalida" ).submit(function(){  return EvaluaReg( this ) });
	
	
	$( "form#frmfoto" ).submit(function(){  
		if( $( "#comentar" ).val( ) != "" )								
		add_comment_foto(   $( "#comentar" ).val( ), $( "#idfoto" ).val( )   )
		return false;
	});

	$( ".denunciar" ).click(function(){  
		denunciar_comment(   $( this ).attr( "rel" )   )
		return false;
	});
	
	$( ".votafoto" ).click(function(){  
		votar_foto(   $( this ).attr( "rel" )   )
		return false;
	});
	
	$( ".votacompos" ).click(function(){  
		votar_compo(   $( this ).attr( "rel" )   )
		return false;
	});
	
	$( ".votavideo" ).click(function(){  
		votar_video(   $( this ).attr( "rel" )   )
		return false;
	});
	
	$( "#addVideo" ).click(function(){
		aparecer( "#hidevid" , this, 10 );
		return false;
	});
	
	$( "#addVideoi" ).click(function(){
		aparecerv( "#hidevid" , this, 450 );
		return false;
	});
	
	$( "#addVideoa" ).click(function(){
		apareceri( "#hidevid" , this, 450 );
		return false;
	});
	
	$( "#cerrarv" ).click(function(){
		aparecer( "#hidevid" , this, 400 );
		return false;
	});
	
	$( "#addFoto" ).click(function(){
		aparecer( "#hidepic" , this, 500 );
		return false;
	});
	
	$( "#addFotoi" ).click(function(){
		apareceri( "#hidepic" , this, 400 );
		return false;
	});
	
	$( "#cerrarimg" ).click(function(){
		aparecer( "#hidepic" , this, 400 );
		return false;
	});
	
	$( "#cerrarmail" ).click(function(){
		aparecer( "#hidemail" , this, 400 );
		return false;
	});
	
	$( ".addMail" ).click(function(){
		aparecer( "#hidemail" , this, 10 );
		return false;
	});
	$( ".addMailr" ).click(function(){
		aparecer( "#hidemail" , this, 400 );
		return false;
	});
	$( ".addMailc" ).click(function(){
		aparecer( "#hidemail" , this, 300 );
		return false;
	});
	
	$( ".addMaili" ).click(function(){
		apareceri( "#hidemail" , this, 400 );
		return false;
	});
	/*
	$("#galeria_evento").jCarouselLite({
		btnNext: ".nextgal",
		btnPrev: ".prevgal",
		scroll: 1,
		visible: 2,
		speed:800,
		circular: "true"
	});
	
	
	$('#dialog').jqm();
	$('#ex2').jqm({trigger: '.ex2trigger'});
	
	$('#layer_recetas').jqm({trigger: '.open_receta'});


	$('#videodialog').jqmAddTrigger('.openDialog'); 
	
	$( ".nologin" ).click(function(){
		Sexy.alert( "Debes estar registrado y tener una sesi&oacute;n activa." );
	});							   
	*/
	
	
});


function addNotify()
{
	if( !window.contactonotify )
	{
		window.contactonotify = $( '<div id="volatilnotif" class="info_notify">Obteniendo datos...</div>' )
					.css({ 
							"position":"absolute",
							"top" : "1200px",
							"left" : "650px",
							"width" : "400px",
							"height" : "50px",
							"z-index" : "10"
				}).get();
				
		$( document.body ).append( window.contactonotify );
	}
	else
		$( window.contactonotify ).show();
		
	setTimeout( function(){$( "#volatilnotif" ).fadeOut( "slow" )} , 600 );	
}

function add_comment_foto( comentario, idfoto )
{
	var val = [];
	var params = {};
	var tmpname = "";
	var myfield;
	params[ "idfoto" ] = idfoto;
	params[ "comentario" ] = comentario;
	
	//return false;
	jQuery.ajax( {
		"type" : "POST",
		"data" : "idfoto=" + idfoto + "&comentario=" + comentario,
		"url" : "includes/comentariofoto.async.php" ,
		"beforeSend" : function(){
			addNotify();
		},
		"success" : function( meg ){
			$( "#volatilnotif" ).html( "Comentario guardado correctamente!!" );
			$("#comentar").val( "" );
			setTimeout( function(){
				$( "#volatilnotif" ).fadeOut( "slow" );
			} , 700);

		}
	});
	return false;	
}

function denunciar_comment( idcomentario )
{
	var val = [];
	var params = {};
	var tmpname = "";
	var myfield;
	params[ "idcomentario" ] = idcomentario;
	
	//return false;
	jQuery.ajax( {
		"type" : "POST",
		"data" : "idcomentario=" + idcomentario ,
		"url" : "includes/denunciar.async.php" ,
		"beforeSend" : function(){
			addNotify();
		},
		"success" : function( meg ){
			alert( "Muchas gracias, el comentario ha sido denunciado !" );

		}
	});
	return false;	
}//end function

function incializatip( idimg )
{
	
	tipmage = new Tipmage(idimg,true);
  	tipmage.startup();
	
	
}//end function


function inserta_etiqueta( posx, posy, width, height, text, idfoto  )
{
	var val = [];
	var params = {};
	var tmpname = "";
	var myfield;
	tmpname = posx + "," + posy + "," + width + "," + height
	
	//return false;
	jQuery.ajax( {
		"type" : "POST",
		"data" : "idfoto=" + idfoto + "&posx=" + posx + "&posy=" + posy + "&width=" + width + "&height=" + height + "&text="+ text ,
		"url" : "includes/etiquetar.async.php" ,
		"beforeSend" : function(){
			addNotify();
		},
		"success" : function( meg ){
			alert( "La foto ha sido etiquetada correctamente !" );

		}
	});
	return false;	
}//end function


function votar_foto( idfoto  )
{
	var val = [];
	var params = {};
	var tmpname = "";
	var myfield;
	
	//return false;
	jQuery.ajax( {
		"type" : "POST",
		"data" : "idfoto=" + idfoto ,
		"url" : "includes/votarfoto.async.php" ,
		"beforeSend" : function(){
			addNotify();
		},
		"success" : function( meg ){
			Sexy.alert( meg );
			window.top.location.reload( );
		}
	});
	return false;	
}//end function

function votar_compo( idfoto  )
{
	var val = [];
	var params = {};
	var tmpname = "";
	var myfield;
	
	//return false;
	jQuery.ajax( {
		"type" : "POST",
		"data" : "idfoto=" + idfoto ,
		"url" : "includes/votarcompo.async.php" ,
		"beforeSend" : function(){
			addNotify();
		},
		"success" : function( meg ){
			alert( meg );
			window.top.location.reload( );
		}
	});
	return false;	
}//end function

function votar_video( idfoto  )
{
	var val = [];
	var params = {};
	var tmpname = "";
	var myfield;
	
	//return false;
	jQuery.ajax( {
		"type" : "POST",
		"data" : "idfoto=" + idfoto ,
		"url" : "includes/votarvideo.async.php" ,
		"beforeSend" : function(){
			addNotify();
		},
		"success" : function( meg ){
			Sexy.alert( meg );
			window.top.location.reload( );
		}
	});
	return false;	
}//end function

function aparecer( selector , obj, abscisa )
{
	$( selector ).css( 'top' , $( obj ).offset().top + $( obj ).height() - 100 + "px")
		.css( 'left' , $( obj ).offset().left - abscisa  )
		.toggle( 400 );
	return true;
}

function apareceri( selector , obj, abscisa )
{
	$( selector ).css( 'top' , $( obj ).offset().top + $( obj ).height() - 100 + "px")
		.css( 'left' , $( obj ).offset().left - abscisa  )
		.toggle( 400 );
	return true;
}

function aparecerv( selector , obj, abscisa )
{
	$( selector ).css( 'top' , $( obj ).offset().top + $( obj ).height() - 100 + "px")
		.css( 'left' , $( obj ).offset().left - abscisa  )
		.toggle( 400 );
	return true;
}

