//<![CDATA[
/*
 Copyright (c) 2006 MexWebs Developer Team. All rights reserved.
 version 0.1.0
 Author: Caridy Patiño

 JS-EVENTS
 ==============
 Assumed Document Object Model described in:
 "Document Object Model (DOM) Level 2 Specification Version 1.0"
 (http://www.w3.org/TR/1999/CR-DOM-Level-2-19991210)
 Latest version: (http://www.w3.org/TR/DOM-Level-2)

 Successfully tested on:
  - Miscrosoft Internet Explorer 6.02
  - Mozilla Firefox 1.5
  - Opera 8.5
 All in platform Win32, Operating System Windows XP SP2.

 Description:
 ============
 Implementación de los principales eventos que pueden ser generados dinamicamente a partir del parametro REL o CLASS de un enlace...
*/
var handleSuccess = function(o){
	if ((o.responseText !== undefined) && (o.argument.c))
	  o.argument.c = o.responseText;
}
var handleFailure = function(o){
	return false;
}
/**
* Este metodo se encarga de revisar cada uno de los elementos que pueden causar navegación y le aplica
* el respectivo evento para garantizar que funcionen las llamadas usando ajax...
* @public
* @param {object} content    Referencia al elemento que se le va a aplicar el filtro de navegación...
* @return void
*/
function verify_ajax_link( content, tt, deffunc ) { 
  if (!(content = assetObj (content, document)) || (!content.getElementsByTagName)) return false;
  tt = assetbool( tt, true );
  var items    = new Array();
  var relType   = null, relRef   = null; // definiendo el tipo de referencia y la referencia como tal a una funcion...
  var classType = null, classRef = null; // definiendo el tipo de clase y la referencia como tal a una funcion...
  var itemclass = null, itemrel  = null; 
  items.merge( content.getElementsByTagName("a") );
  items.merge( content.getElementsByTagName("area") );
  for (var i=0; i<items.length; i++) {
    var anch = items[i];
    if (anch.getAttribute("href") && isAjaxble(anch.getAttribute("href"))) {
	  relType   = null;
	  relRef    = null; 
	  classType = null;
	  classRef  = null;
	  itemrel   = new String(anch.getAttribute("rel"));
	  itemclass = new String(anch.className);
	  if ((itemrel != "") && (itemrel.indexOf('nav') == 0)) {
		try {
	      relType = eval("typeof "+itemrel);
		  relRef  = eval(anch.getAttribute("rel"));
		} catch (e) {}
	  }
	  if ((itemclass != "") && (itemclass.indexOf('nav') == 0)) {
		try {
	      classType = eval("typeof "+itemclass);
		  classRef  = eval(anch.className);
		} catch (e) {}
	  }
	  switch (itemrel.toString()) {
		case "external":
		  anch.target = "_blank";
		  break;
		case "internal":
		  anch.target = "_top";
		  break;
		default:
		  // si se especific aun valor para REL que es una funcion definida, entonces se aplica el evento correspondiente...
		  if (relType == "function")
            YAHOO.util.Event.addListener ( anch, 'click', relRef );
		  else {
			if (classType == "function")
              YAHOO.util.Event.addListener ( anch, 'click', classRef );
			else if (!isEmpty(deffunc) && (typeof deffunc == 'function'))
              YAHOO.util.Event.addListener ( anch, 'click', deffunc );
		  }
	  }
    }
	//if (tt) 
	  //applyToolTip( anch );
  }
}
/**
* Este método determina si una URL es interna al sitio o no, de esta manera sabemos si la url puede usarse a través del ajax
* @public
* @param {string} url URI de navegación
* @return boolean
*/
function isAjaxble( url ) {
  // Primeramente debo revisar si es una url simple sin DNS y protocolo,
  // sino verificar que el dominio de ejecución sea el mismo que el actual.
  return true;
}
// ------------------------
// Galeria Dinamica en AJAX
// ------------------------
var gallerySuccess = function(o){
	if((o.responseText !== undefined)){
	  displayDialog( o.argument.c, o.responseText, '50em', true );
	  var myGallery = new YAHOO.widget.Gallery('gallery', { container:'yuigallery' } );
	}
}
/**
* Este método representa un evento de navegación sobre un enlace a una galeria dinamica...
* @public
* @param {object} e Referencia al evento
* @return void
*/
function navAjaxGallery(e) {
  if (this && this.href) {
	var title = document.createElement("span");
	title.innerHTML = "&nbsp;";
    ajaxLoadContent ( title,  url_completion ( this.href, 'tpl=tpls/ajax&page=pages/object-gallery' ),  gallerySuccess, handleFailure);
    YAHOO.util.Event.stopEvent(e);
  }
}
// -----------------
// Páginado Dinamico
// -----------------
var paginationSuccess = function(o){
	if((o.responseText !== undefined) && (o.argument.c)){
	  // aqui utilizo el magicFade para intercambiar contenidos, pero además le mando la funcion que debe 
	  // ejecutarse inmediatamente despues de la conclusión de la animación, para garantizar que nada falle...
	  var onCompleteMagicFade = function() { verify_ajax_link ( o.argument.c ); reinitialization (); executeble ( o.argument.c ); }
	  magicFade ( o.argument.c, o.responseText, onCompleteMagicFade  );
	}
	YAHOO.tms.panel.wait.hide();
}
var paginationFailure = function(o){
	YAHOO.tms.panel.wait.hide();
	return false;
}
/**
* * Este método representa un evento de navegación sobre el paginado...
* @public
* @param {object} e Referencia al evento
* @return void
*/
function navAjaxPagination(e) {
  if (this && this.href) {
	displayLoading ();
	ajaxLoadContent ( 'tms-pagination', url_completion ( this.href, 'tpl=tpls/ajax' ), paginationSuccess, paginationFailure);
    YAHOO.util.Event.stopEvent(e);
  }
}
// -----------------
// BANNERS Dinamicos
// -----------------
var bannerSuccess = function(o){
	if((o.responseText !== undefined) && (o.argument.c)){
	  var onCompleteMagicFade = function() { reinitialization (); executeble ( o.argument.c ); }
	  magicFade ( o.argument.c, o.responseText, onCompleteMagicFade  );
	}
}


/**
* * Este método representa un evento de navegación sobre el paginado...
* @public
* @param {object} e Referencia al evento
* @return void
*/
function eventGarbage(e) {
  YAHOO.util.Event.stopEvent(e);
}
















//]]>