
/*  Speedy JavaScript framework, version 1.2.3
 *  (c) 2009 Jeronimo Costa
 *
 *
 *--------------------------------------------------------------------------*/
function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
function isBoolean(a) {
    return typeof a == 'boolean';
}
function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}
function isFunction(a) {
    return typeof a == 'function';
}
function isNull(a) {
    return typeof a == 'object' && !a;
}
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
function isString(a) {
    return typeof a == 'string';
}
function isTag(a) {
    return a.nodeType && a.nodeType ==1;
} 

/*  Functions Load Images After Charge
 *  
 *
 *--------------------------------------------------------------------------*/
function chargeExtraImages() {
	$('box_container_01').innerHTML = '<a href="http://argentina.aula365.com/redirect.aspx?mode=referral&code=PTFAONSBC0708/?utm_source=banner_aul365&utm_medium=banner&utm_campaign=SpeedyClientes" target="_blank"><img src="images/banner_aula_365.jpg" alt="Aula 365 Speedy" title="Aula 365 Speedy" width="300" height="250" border="0"></a>';
	$('box_container_02').innerHTML = '<a href="http://club.speedy.com.ar/concursos/categoria/viajes" target="_blank"><img src="images/temaiken300.jpg" alt="Club Speedy – Temaiken" title="Club Speedy – Temaiken" width="300" height="254" border="0"></a>';
	$('box_container_03').innerHTML = '<a href="http://sonica.speedy.com.ar/?utm_source=banner_sonica&utm_medium=banner&utm_campaign=SpeedyClientes" target="_blank"><img src="images/banner_sonica.jpg" alt="SONICA" title="SONICA" width="300" height="250" border="0"></a>';
	$('box_container_04').innerHTML = '<a href="http://www.speedy.com.ar/sonora-meet-and-greet/" target="_blank" onClick=""><img src="images/300x254_sonora_nelly.jpg" alt="Musica como vos queres" title="Musica como vos queres" width="300" height="250" border="0"></a>';
	$('box_container_05').innerHTML = '<a href="http://www.3dgames.com.ar/?utm_source=banner_3dgames&utm_medium=banner&utm_campaign=SpeedyClientes" target="_blank"><img src="images/banner_3DG.gif" alt="3D Games Juegos Online" title="3D Games Juegos Online" width="300" height="250" border="0"></a>';
}
/*  Functions Modulo Box Container
 *  
 *
 *--------------------------------------------------------------------------*/
function changeContainer(id) {
	
	// Oculto los demas SubMenues
	for(i=0 ; i < 15 ; i++) {
		if($('box_title_0' + i) && id != i && Element.visible('box_container_0' + i) == true) {
			Effect.BlindUp('box_container_0' + i, { duration: 0.5} );
			$('box_title_0' + i).className = 'box_titulo_mod_off';
			$('mod_title_0' + i).className = 'titulo_mod_off';			
		}
	}
	
	// Muestro el SubMenu Actual
	if($('box_container_0' + id)) {
		Effect.BlindDown('box_container_0' + id, { duration: 0.5} );
		$('box_title_0' + id).className = 'box_titulo_mod';
		$('mod_title_0' + id).className = 'titulo_mod';		
	}
}


function initAllContainer() {
	// changeContainer(1);
	setOnGlobo(1);
	loadVideo(1,'stop');
}

/*
* Function Noticias.
*
*/
function setOnGlobo(id) {
	for(i=1 ; i < 8 ; i++) {
		if ($('globo_' + i)) { 
			if (i == id) {
				$('globo_' + i).className = "globos_on";
			} else {
				$('globo_' + i).className = "globos";
			}
		}
	}
}
 
/*  Function Encuesta
 *  
 *
 *--------------------------------------------------------------------------*/
function showEncuesta() {
	new Effect.Tooltip(element, content, {title : 'title', className: 'class', offset: {x:0, y:0}});

}

/*  Functions Envio de Correos
 *  
 *
 *--------------------------------------------------------------------------*/
function send_email(parametros) {
	if (echeck($('amigo').value) == true){
		// Pantalla de Envio
		$('msg_error').style.display = 'none';
		cargarAjaxGenerico('enviar_correo','includes/ajax',parametros,'recomendar_container_div','0.05','0.1','60')
	} else {
		$('msg_error').style.display = '';
	}

}

/*  Functions Votar Encuesta
 *  
 *
 *--------------------------------------------------------------------------*/
function votar_encuesta(parametros) {
	// Pantalla de Votacion
	cargarAjaxGenerico('votacion_encuesta','includes/ajax',parametros,'encuesta_container','0.05','0.1','60');
	$('votar_container').innerHTML = '';
}

/*  Functions Video
 *  
 *
 *--------------------------------------------------------------------------*/
function loadVideo(id,action) {
	id--;
	// Modificamos el Titulo
	$('video_title').innerHTML = array_video_titulos[id];
	
	// Modificamos el Video
	var so = new SWFObject("player/playerjvideo.swf", "promoId", "300", "245", "7", "#000000");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.addVariable("film", array_video_film[id]);
	so.addVariable("action", action);
	so.addParam("salign", "t");
	so.write("video_container");
	// Modificamos la Descripcion
	$('video_description').innerHTML = '&gt;&gt; ' + array_video_descripcion[id];
	
}

/*
* INFORMACION MODIFICABLE
*/ 
array_video_titulos = new Array ("Club Speedy","Club Speedy te invita", "Aula 365 Speedy");
array_video_film = new Array ("/player/flv/clubspeedy02.flv","/player/flv/speedy_2.flv", "/player/flv/3.flv");
array_video_url = new Array ( "http://sonica.speedy.com.ar/indica","#", "http://argentina.aula365.com/permalink/curso/La-memoria-nos-permite-construir-el-futuro-908919.aspx");
array_video_descripcion = new Array ("Descubrí todos los beneficios que Club Speedy tiene preparado para vos: recitales, avant premieres, premios, cenas y descuentos.","<a href='http://www.speedy.com.ar/cms/index.php?page=concursos&tipoContenido=teatro' style='text-decoration:none;color: #3A3B3B;' target='_blank'>Club Speedy te invita al Show exclusivo del Mago Emanuel, el 17 de Diciembre. Particpá del sorteo y ganá entradas!</a>", "Aprende, Crea y Comparte. Encontrá todo lo que necesitas para el colegio: Cursos de Inglés, material para padres y docentes, biografías y mucho más.");



/*
*
*/
function cargarAjaxGenerico(pagina,folder,formulario,container_local,tim1,tim2,tim3) {

	// Actualizo la URL
	var some_url = "/" + folder+"/"+pagina+".php"
	var parametros = null;
	if (formulario != undefined && formulario != null ) {
		parametros = formulario;
	} else {
	}

	// Realizo el Update
	new Ajax.Updater(container_local, some_url , { method: 'post',  parameters: parametros});
	// new Effect.Fade(container_local, { duration: tim1} );
	// setTimeout("new Ajax.Updater('" + container_local + "','" + some_url + "',{onComplete:function(){ new Effect.Appear('" + container_local + "', { duration: " + tim2 + "} );scroll(0, heightGoto);}, method: 'post', parameters: '" + parametros + "', asynchronous:true, evalScripts:true});",tim3);
	return false;
}
function cargar(formulario) {
	cargarGenerico('submenu','body',formulario,'submenu-container','0.05','0.1','60')
}
/*  reloadPage
 *  
 *
 *--------------------------------------------------------------------------*/
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

/*  Menu Functions
 *  
 *
 *--------------------------------------------------------------------------*/
var timeout         = 0;
var closetimer		= 0;
var ddmenuitem      = 0;
var idname = "";
// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();
	// also change the header className
	if (document.getElementById(idname + '_header')) 
		document.getElementById(idname + '_header').className = 'dir1';

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';
	idname = id;
	// also change the header className
	if (document.getElementById(id + '_header')) {
		document.getElementById(id + '_header').className = 'dir1_hover';
	}
}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';	
	
	// also change the header className
	if (document.getElementById(idname + '_header')) 
		document.getElementById(idname + '_header').className = 'dir1';
		
	
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 


/*  Glider Functions
 *  
 *
 *--------------------------------------------------------------------------*/
Glider = Class.create();
Object.extend(Object.extend(Glider.prototype, Abstract.prototype), {
	initialize: function(wrapper, options){
	    this.scrolling  = false;
	    this.wrapper    = $(wrapper);
	    this.scroller   = this.wrapper.down('div.scroller');
	    this.sections   = this.wrapper.getElementsBySelector('div.section');
	    this.options    = Object.extend({ duration: 1.0, frequency: 3 }, options || {});

	    this.sections.each( function(section, index) {
	      section._index = index;
	    });    

	    this.events = {
	      click: this.click.bind(this)
	    };

	    this.addObservers();
			if(this.options.initialSection) this.moveTo(this.options.initialSection, this.scroller, { duration:this.options.duration });  // initialSection should be the id of the section you want to show up on load
			if(this.options.autoGlide) this.start();
	  },
	
  addObservers: function() {
    var controls = this.wrapper.getElementsBySelector('div.controls a');
    controls.invoke('observe', 'click', this.events.click);
  },	

  click: function(event) {
		this.stop();
    var element = Event.findElement(event, 'a');
    if (this.scrolling) this.scrolling.cancel();
    
    this.moveTo(element.href.split("#")[1], this.scroller, { duration:this.options.duration });     
    Event.stop(event);
  },

	moveTo: function(element, container, options){
			this.current = $(element);

			Position.prepare();
	    var containerOffset = Position.cumulativeOffset(container),
	     elementOffset = Position.cumulativeOffset($(element));

		  this.scrolling 	= new Effect.SmoothScroll(container, 
				{duration:options.duration, x:(elementOffset[0]-containerOffset[0]), y:(elementOffset[1]-containerOffset[1])});
		  return false;
		},
		
  next: function(){
    if (this.current) {
      var currentIndex = this.current._index;
      var nextIndex = (this.sections.length - 1 == currentIndex) ? 0 : currentIndex + 1;      
    } else var nextIndex = 1;

    this.moveTo(this.sections[nextIndex], this.scroller, { 
      duration: this.options.duration
    });
  },
	
  previous: function(){
    if (this.current) {
      var currentIndex = this.current._index;
      var prevIndex = (currentIndex == 0) ? this.sections.length - 1 : 
       currentIndex - 1;
    } else var prevIndex = this.sections.length - 1;
    
    this.moveTo(this.sections[prevIndex], this.scroller, { 
      duration: this.options.duration
    });
  },

	stop: function()
	{
		clearTimeout(this.timer);
	},
	
	start: function()
	{
		this.periodicallyUpdate();
	},
		
	periodicallyUpdate: function()
	{ 
		if (this.timer != null) {
			clearTimeout(this.timer);
			this.next();
		}
		this.timer = setTimeout(this.periodicallyUpdate.bind(this), this.options.frequency*1000);
	}

});

Effect.SmoothScroll = Class.create();
Object.extend(Object.extend(Effect.SmoothScroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }
   
    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;
   
    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    } 
  },
  update: function(position) {   
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}