/*
 JS-AJAX-VOODOO
 ==============
 $Id$
 Author: caridy@gmail.com
 Company: MexWebs - Soluciones Web Globales

 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:
 ============

 Use Example for Simple Rotator:
 ============
	<script type="text/javascript" src="rotator.js"></script>
    <script type="text/javascript">
	  init_rotator ( 'rotator_id',                // Id de la imagen que queremos rotar...
	   new Array (                                // Arreglo de imagenes que queremos mostrar...
	     TMS_THEMEPATH + "images/intro1.jpg",
	     TMS_THEMEPATH + "images/intro2.jpg",
	     TMS_THEMEPATH + "images/intro3.jpg"
	   )
	  );
    </script>
*/
//<![CDATA[

var rotator_img_id  			= 'rotator_id';   // id of the IMG tag for rotation
var rotator_img_reference  		= null;   // id of the IMG tag for rotation
var rotator_default_timeout 	= 5;             // 10 second between images
var rotator_stock			    = new Array (     // list of images
								);

var rotator_handle    		    = null;
var rotator_opacity_handle      = null;
var rotator_index               = 0;
var rotator_navigation_detect   = (navigator.appName=="Microsoft Internet Explorer" ? true : false);
var rotator_navigation_property = (rotator_navigation_detect?'filters.alpha.opacity':'style.MozOpacity');
var rotator_navigation_opacity  = (rotator_navigation_detect?100:1);
var rotator_current_opacity     = (rotator_navigation_detect?100:1);
var rotator_navigation_bit      = (rotator_navigation_detect?10:0.1);

// initialization of the rotator
function init_rotator ( obj_id, imgs ) {
  if (obj_id != '')
     rotator_img_id = obj_id;
  if (imgs != '')
     rotator_stock = imgs;
  rotator_img_reference = findObj ( rotator_img_id );  // locate the img
  if (rotator_img_reference && rotator_stock.length > 0) {
    for (var i=0; i < rotator_stock.length; i++) {
      MM_preloadImages ( rotator_stock [i] );
      if (rotator_img_reference.src.indexOf(rotator_stock [i]) != -1)
        rotator_index = i;
    }
    clearTimeout( rotator_handle );
    rotator_darkness();
  }
}

/*funciones que cambian de intensidad la opaciad de una imagen*/

function rotator_go(){
  if (rotator_index < rotator_stock.length-1)
    rotator_index++;
  else
    rotator_index = 0;
  clearTimeout( rotator_handle );
  rotator_current_opacity = 0; // forcing to darkness
  eval('rotator_img_reference.' + rotator_navigation_property + ' = rotator_current_opacity');
  rotator_img_reference.src = rotator_stock [rotator_index];
  rotator_brigtness();
  rotator_handle = window.setTimeout( 'rotator_darkness()', rotator_default_timeout * 1000 );
}

function rotator_next(){
  if (rotator_index < rotator_stock.length-1)
    rotator_index++;
  else
    rotator_index = 0;
  clearTimeout( rotator_handle );
  rotator_img_reference.src = rotator_stock [rotator_index];
  eval('rotator_img_reference.' + rotator_navigation_property + ' = rotator_navigation_opacity');
  rotator_handle = window.setTimeout( 'rotator_darkness()', rotator_default_timeout * 1000 );
  return false;
}

function rotator_previous() {
  if (rotator_index > 0)
    rotator_index--;
  else
    rotator_index = rotator_stock.length-1;
  clearTimeout( rotator_handle );
  rotator_img_reference.src = rotator_stock [rotator_index];
  eval('rotator_img_reference.' + rotator_navigation_property + ' = rotator_navigation_opacity');
  rotator_handle = window.setTimeout( 'rotator_darkness()', rotator_default_timeout * 1000 );
  return false;
}

function rotator_darkness(){
  if (rotator_current_opacity >= 0) {
  	eval('rotator_img_reference.' + rotator_navigation_property + ' = rotator_current_opacity');
    rotator_current_opacity -= rotator_navigation_bit;
    rotator_opacity_handle = setTimeout('rotator_darkness()',10 )
  }
  else
    rotator_go();
}

function rotator_brigtness(){
  if (rotator_current_opacity <= rotator_navigation_opacity) {
    eval('rotator_img_reference.' + rotator_navigation_property + ' = rotator_current_opacity')
    rotator_current_opacity += rotator_navigation_bit;
    rotator_opacity_handle = setTimeout( 'rotator_brigtness()', 10 );
  }
}

/* AJAX ROTATOR

 Use Example for Simple Rotator:
 ============
	<script type="text/javascript" src="ajax.js"></script>
	<script type="text/javascript" src="rotator.js"></script>
    <script type="text/javascript">
	  var AJAX_GlobalRequestObject = InitAjax ();
	  ajax_init_rotator ( 'rotator_id',           // Id del tag que queremos rotar...
	   new Array (                                // Arreglo de urls que queremos mostrar...
	     "/pagina-uno",
	     "/pagina-dos",
	     "/pagina-tres"
	   )
	  );
    </script>

*/

var ajax_rotator_tag_id 			= null;
var ajax_rotator_reference      	= null;   		  // id of the TAG for rotation
var ajax_rotator_default_timeout 	= 10;             // 10 second between images
var ajax_rotator_stock			    = new Array (     // list of urls
									);
var ajax_rotator_handle    		    = null;
var ajax_rotator_opacity_handle     = null;
var ajax_rotator_index              = 0;

// initialization of the ajax rotator
function ajax_init_rotator ( obj_id, urls ) {
  ajax_rotator_tag_id = obj_id;
  if (urls != '')
     ajax_rotator_stock = urls;
  ajax_rotator_reference = findObj ( ajax_rotator_tag_id );  // locate the tag (usually we use a DIV with ID param defined)
  if (ajax_rotator_reference && ajax_rotator_stock.length > 0) {
    clearTimeout( ajax_rotator_handle );
    ajax_rotator_go();
  }
}

/*funciones que cambian el contenido de un tag*/

function ajax_rotator_go(){
  if (ajax_rotator_index < ajax_rotator_stock.length-1)
    ajax_rotator_index++;
  else
    ajax_rotator_index = 0;
  clearTimeout( ajax_rotator_handle );
  LoadUsingAjax( 'LoadDivUsingAjax', ajax_rotator_tag_id, ajax_rotator_stock [ajax_rotator_index], 'get', null );
  ajax_rotator_handle = window.setTimeout( 'ajax_rotator_go()', ajax_rotator_default_timeout * 1000 );
}

//]]>