// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
jQuery(document).ready(function(){
//zebralizer($('table'),'tr');

	HoverBehave = $.klass({
	  initialize: function(hoverClass) {
	    this.hoverClass = hoverClass;
	  },
	  onmouseover: function() {
	    this.element.addClass(this.hoverClass);
	  },
	  onmouseout: function() {
	    this.element.removeClass(this.hoverClass);
	  }
	});
	
	Zebralizer = $.klass({
	  initialize: function(zebralizerElement) {
			//this.element = id;
	    this.zebralizerElement = zebralizerElement;
			$(this.element)
				.find(zebralizerElement)
					.removeClass('odd')
				.end()
				.find(zebralizerElement+':odd')
					.addClass('odd');
				//hover
	  },
	  onmouseover: function() {
	  },
	  onmouseout: function() {
	  }
	}); 
	
	
	try_ajax = $.klass({
		initialize: function(tag_id) {
			this.tag_id = tag_id;
			$.ajax({
			  type: "GET",
			  url: 'get_tagged_with',  
			  data: "id="+tag_id,
			  dataType: "script",
				beforeSend:function(){
				//alert('cargando');
					$('#spinner').fadeIn('slow');
				},
				complete:function(){ 
				  // /*  
					var  phrase_id =  $('#load-drawer li:first').attr('id');  // saco el phrase id del attr id del primer li 
					var  new_tag_id =  $('#load-drawer li:first').attr('tag_id');  // saco el phrase id del attr id del primer li 
					var tag_name =    $('#load-drawer li:first').attr('tag_name').toUpperCase(); 
										 
					var obj1 =  $('#text_drawer #'+phrase_id).jTypeWriter({onComplete:function(){ 
					if ($('#load-drawer li:first').attr('tag_id') != 'over'){ 
							$('#load-drawer li:first').each(function() { $.highlight(this, tag_name); });
							$('#text_drawer #'+phrase_id).attach(try_ajax,new_tag_id); 
						} else {
							alert("Terminó el proceso");
						} 
					}});
						// boton detener 
						$("a#end").fadeIn('fast');  
						$("a#end").click(function(){obj1.endEffect();});    
			   // */ 
				}    
			});
		}
	}) 
	
	
	
	
	ToggleBehavior = $.klass({
		initialize: function(ToggleElement) {
			$(this.element).toggle(function(){
				$(ToggleElement).fadeIn('fast');
			},function(){
				$(ToggleElement).fadeOut('fast');
			});
		},
		onclick: function() {    
			return false;
		} 
	});
	
	
	
	jQuery(function($) {
		$('table').attach(Zebralizer,'tr');
		$('tr').attach(HoverBehave,'hoverColor');
	});   
	
	     /*  */
	$("#pages_link").click(function(e) { 
	              $("#pages_form").show();  
				   $("#phrases_form").hide();  
				return false;
	}); 
	$("#phrases_link").click(function(e) { 
	              $("#phrases_form").show();
	 				$("#pages_form").hide(); 
	 			 return false;         
	});
	
	
	
	     /* */  
	$('.flash').fadeOut(8000);
	$('.alert').fadeOut(8000);   
	


});

//paginacion 
jQuery(function($) {
  $('div.pagination a').attach(Remote.Link, { 
	type: 'GET',
	dataType: 'script' ,
		beforeSend:function(){
     //alert('cargando');
			$('#spinner').fadeIn('slow');
					},
		complete:function(){
			$('#spinner').fadeOut('slow');
    }
	});
});

     
  
jQuery(function($) {
  $('.spyder_status a').attach(Remote.Link, {  type: 'GET', dataType: 'script' });
});  


jQuery(function($) {
  $('#toogle_presentation').attach(ToggleBehavior, '#load_explanation');
 });    

   // foro typewriter
/* $('.detail_border li').jTypeWriter({duration:1.5}); */   

  function alerta(msg){
		alert(msg);
  }
    

