new Asset.javascript("js/class.IE6.js"); //para ie6

var carruselFotos="";
Array.implement({
    getFirst: function() {
        if(this.length == 0) {
            return null;
        }
        return this[0];
    }
});
Element.implement({ 
	val:function(){
		return this.get("value");
	},
    show: function() { 
      this.setStyle('display','block'); 
	  this.setStyle('visibility','visible'); 
    }, 
    hide: function() { 
      this.setStyle('display','none'); 
	  this.setStyle('visibility','hidden'); 
    },
	Imprimir: function() {
		var strName = 'printer-' + (new Date()).getTime(),
		styles = $$('link[type=text/css]').clone(),
		title = document.title,
		that = this,
		iframe = new IFrame({
			name: strName,
			styles: {
				width: 1,
				height: 1,
				position: 'absolute',
				left: -9999
			},
			events: {
				load: function() {
					var doc = this.contentDocument || window.frames[strName].document;
					doc.title = title;
					$(doc.body).adopt(styles, that.clone());
					this.contentWindow.focus(); // IE necesita obtener el foco sino imprime el frame padre.
					this.contentWindow.print();
				}
			}
		}).inject($(document.body));
		iframe.dispose.delay(15000); // Destruimos el iframe luego de 15 segundos.
	},
	fadeTo: function(value){
		 speed=500;
		var elt = this; 
		 elt = new Fx.Tween(elt, {
			 duration : speed,
			 wait:true
		 }); 
		elt.start('opacity', value);
	},
	sendAjaxForm:function(fn,validate){
		this.set("send",{
			"onSuccess":fn,
			"onFailure":function(){
				alert("hubo en error el en envio del formulario");
			}
		});
		this.addEvent("submit",function(e){
			e.preventDefault();
			if(validate==true){
				var ret = Spry.Widget.Form.validate(this); //solo para spry
				if(ret){
					this.send();
				}
			}else{
				this.send();
			}
		});
		
		
		return false;
	}

}); 



/****/

var Auto= new Class({
	tipOlvido:"",
	activateCalendar:function(){
		$$('#tableCalendar td:not(td.eventoFecha)').
		fadeTo(0.7,"");
		this.creaTool();
	},
	navigate:function(month,year){
		$('caja_meses')
		.set("load",{
			 onSuccess:function(){
				this.creaTool();		 
			 }.bind(this)
		})
		.load("calendar.php?month="+month+"&year="+year);

	},
	creaTool:function(){
		allEvents=$$('#tableCalendar td.eventoFecha');
			allEvents.each(function(e,k){
				new Tooltips({
					div:e.get("id"),
					ancho:144,
					alto:90,
					fondo:"images/tooltip_rojo.png",
					posicion:"centroArriba",
					html:e.get("title"),
					estiloInterior:"txtToolTip"
				});
				e.set("title","");
		});
	},
	initialize:function(){
	},
	cargarVideo:function(url){
		var player=$('ply'); 
		player.sendEvent('LOAD',"videos/"+url);
	},
	initCarruselVideo:function(){
		if($('videos_carrusel')){
			carruselFotos=new ACarrusel("videos_carrusel",{
				avanze:1,
				ver:4,
				duracion:0.9,
				transicion:"sine:out",
				siguiente:'siguiente',
				anterior:'anterior',
				imgSiguienteDesactivo:'images/fc_siguiente2.png',
				imgAnteriorDesactivo:'images/fc_anterior2.png'
			});
			
		}
	},
	initShorcuts:function(){
		if($('videos_index')){
			color=$$('a.description').getStyle("color");
			$$('#videos_index li')
			.addEvents({
				"mouseenter":function(){
					this.getElement("a.description").morph({"text-decoration":"underline","color":"#000"});
					this.getElement("img").fade(0.7);
				},
				"mouseleave":function(){
					this.getElement("a.description").morph({"text-decoration":"none","color":color[0]});
					this.getElement("img").fade(1);
				}
			});
		}
	},
	activatePoll:function(){
		$('formPoll')
		.addEvent("submit",function(e){
			e.preventDefault();
			var choice=$$('#formPoll input[name="choice"]:checked').get("value");
			if(choice==""){
				$('erroPoll').fade("in");
				setTimeout(function(){
					$('erroPoll').fade("out");
				},2000);
			}else{
				new Request({
					url:this.get("action"),
					onSuccess:function(e){
						if(e=="ok"){
							$('pollAuto').set("load",{
								noCache :true
							}).load("_poll.php?view");
						}else{
							$('erroPoll').set("html","Limite de 10 votos por dia").fade("in");
						}
						
					}
				}).send("ip="+choice);
			}
			
			
			
			
		});
	},
	openRegister:function(){
		 new Ventana({
            titulo: "",
            url: "registrate.php",
            modal: true,
            fondo: "",
            alto: 533,
            ancho: 740,
            borde: 0,
            separacion: 0,
            btnCerrar: "txt_registrate"
        }).render();
	},
	scroollToComment:function(){
		var scroll = new Fx.Scroll(window, {
				wait: false,
				duration: 1500,
				offset: {'x': -200, 'y': -50},
				transition:  Fx.Transitions.Sine.easeInOut,
				onComplete:function(){
					$('nameComment').focus();
				}
			});
		scroll.toElement('comments');
	},
	closeFormComment:function(){
		if($('formComment')){
		
			$('formComment')
			.addEvent("submit",function(e){
			e.preventDefault();
				this.set("send",{
					"onFailure":function(){
						$('commentOk').set("html","El sistema est&aacute; ocupado, por favor intenta en unos minutos.");
					},
					"onSuccess":function(){
						$('commentOk').set("html","Tu comentario fue enviado, ser&aacute; revisado y aprobado antes de publicarlo.");
						this.reset();
						new Contador({ a:"comment",	 maximo:255, mensajeEn:"countChars"});		
					}.bind($('formComment'))
				});
				
				var ret = Spry.Widget.Form.validate(this);
				if(ret){
					this.send();
				}
				return false;
			});
		}
	},
	shareTo:function(sr,url){
		var title=document.title;
		switch(sr){
			case "facebook":
				url="http://www.facebook.com/sharer.php?u="+url+"&t="+encodeURIComponent(title);
			break;
			case 'twitter':
				url="http://twitter.com/home?status="+url;
			break;
		}
		window.open(url, 'sharer', 'toolbar=0, status=0, width=626, height=436');
		return false;
	},
	showSendFriend:function(){
		 new Ventana({
            titulo: "",
            url: "enviar_amigo.php",
            modal: true,
            fondo: "",
            alto: 395,
            ancho: 636,
            borde: 0,
            separacion: 0,
            btnCerrar: "b_cerrar_amigo",
			onLoad:function(){
				$('url').set("value",window.location);
				$('title').set("value",$$('h1').get("text"));
				
			}
			
        }).render();
	},
	setToFavorite:function(){
		var title=String(document.title);
		var url=String(window.location);

		if (window.sidebar) // firefox
			window.sidebar.addPanel(title, url, "");
		else if(window.opera && window.print){ // opera
			var elem = document.createElement('a');
			elem.setAttribute('href',href);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} 
		else if(document.all)// ie
			window.external.AddFavorite(url, title);
			else {// otros web Browsers
			alert ("Presione Crtl+D para agregar a este sitio en sus Favoritos");  
		}
	},
	loadModels:function(id){
		$('divModels').load("lista_marcas.php?id="+id);
	},
	detailsModel:function(id){
		if(id==""){
			alert("Debe elegir un modelo correcto.");
		}else{
			window.location.href="cuantovale_tuauto.php?im="+id;
		}
	},
	activeCarruselShowRoom:function(){
			new ACarrusel("carruselModelosShowroom",{
				avanze:1,
				ver:4,
				duracion:0.5,
				transicion:"quad:in:out",
				siguiente:'siguienteShowroom',
				anterior:'anteriorShowroom',
				anchoItem:138,
				altoItem:132,
				imgSiguienteDesactivo:'images/flecha_izq_1.jpg',
				imgAnteriorDesactivo:'images/flecha_der_1.jpg'
			});
	}

	
});

var TransformText=new Class({
	Implements: [Options, Events],
	options:{
		max:'',
		interval:2,
		min:''
	},
	_min:'',
	container:'',
	_currentSize:'',
	initialize:function(container,options){
		this.setOptions(options);
		this.container=$(container);
		
		if(this.options.min==""){
			this._min=this.container.getStyle("font-size").toInt();
		}else{
			this._min=this.options.min;
		}
		
		this._max=this.options.max;
		this._currentSize=this.container.getStyle("font-size").toInt();
	},
	zoomIn:function(){
		this._currentSize=this.container.getStyle("font-size").toInt();
		if(this._currentSize < this._max){	
			this.container.setStyle("font-size",this._currentSize + this.options.interval);
		}
		
	},
	zoomOut:function(){
		this._currentSize=this.container.getStyle("font-size").toInt();
		if(this._currentSize > this._min){
			this.container.setStyle("font-size",this._currentSize - this.options.interval);
		}
	}
});


var Contador= new Class({
	Implements : Options,
	options:{
		a:"",
		maximo :400,
		mensaje:"",
		estiloMensaje:"",
		mensajeEn:"",
		colorEfecto1:"#7D4D25",
		colorEfecto2:"#FFFFFF"
		
	},
	initialize:function(options){		
		this.setOptions(options);
		this.options.mensaje="Contador de caracteres (m&aacute;ximo "+ this.options.maximo +")";
		var el=this.options.a;
		msg= new Element("span",{
			id:'___moo___conta__'+this.options.a,
			html:this.options.mensaje,
			'class':this.options.estiloMensaje
		});
		if(this.options.mensajeEn){
			$(this.options.mensajeEn).set("html",this.options.mensaje);
		}else{
			$(msg).injectAfter(this.options.a);
		}
		
		if($(this.options.a)){
			$(this.options.a)
			.addEvents({
					"keyup":function(){
						var actual=this.options.maximo - ($(this.options.a).value.length).toInt();
							if(actual>=0){
								this.options.mensaje="Contador de caracteres (m&aacute;ximo "+actual+")";
								if(this.options.mensajeEn!=""){
									$(this.options.mensajeEn).set("html",this.options.mensaje);
								}else{
									$('___moo___conta__'+this.options.a).set("html",this.options.mensaje);
								}
							}else{
								$(this.options.a).highlight(this.options.colorEfecto1,this.options.colorEfecto2);
								value=$(this.options.a).get("value");
								if(value.length > this.options.maximo){
										value =  value.substring(0, this.options.maximo);
									$(this.options.a).set('value',value);
								}
								return false;
							}
					}.bind(this)
			});
			
		}
	}
});

var Ventana = new Class({
    Implements: [Options, Events],
    options: {
        modal: false,
        ancho: 350,
        titulo: '',
        alto: 350,
        id: "VentanaMoo",
        fondo: "white",
        fondoModal: "#000",
        opacidad: 0.2,
        html: "",
        url: "",
        arrastra: false,
        juntoA: "",
        separacion: 10,
        borde: 1,
        btnCerrar: "",
        imagenFondo: "",
        colorfondoCabecera: "",
        colorBorde: "",
        textoCerrar: "",
        anchoPrivado: 35,
        htmlCerrar: "",
        estiloCabecera: "",
        onCerrar: $empty(),
        onLoad: $empty()
    },
    initialize: function(options){
        this.setOptions(options);
        av = window.getWidth() / 2;
        alv = window.getHeight() / 2;
        ad = this.options.ancho / 2;
        ald = this.options.alto / 2;
        ventana = new Element("div", {
            id: this.options.id,
            styles: {
                backgroundColor: this.options.fondo,
                padding: this.options.separacion + 'px',
                height: this.options.alto + 'px',
                width: this.options.ancho + 'px',
                position: 'relative',
                border: this.options.borde + 'px solid #CCC',
//                left: parseInt(av) - parseInt(ad),
                top: parseInt(alv) - parseInt(ald),
                zIndex: 1200,
                display: 'none',
				margin : '0 auto'
            }
        
        });
        
        if (!$(this.options.juntoA)) {
            ventana.set('html', '<div id="header__moo" class="cabecera__moo" style="padding:10px;height:15px" >' +
            '<div style="width:85%;float:left;">' +
            this.options.titulo +
            '</div>' +
            '<div align="right" id="cierra_v_moo" style="float:left;width:15%;cursor:pointer;" title=""></div>' +
            '</div>' +
            '<div style="border-top:0px solid #CCC;padding:35px;height:' +
            parseInt(this.options.alto - 25) +
            'px;overflow:auto;vertical-align:middle" align="center" id="conte__moo" class="cuerpo__moo">' +
            '</div>');
            
        }
        else {
            ventana.set('html', '<div style="border-top:0px solid #CCC;height:' + parseInt(this.options.alto) +
            'px;overflow:auto;vertical-align:middle" align="center" id="conte__moo" class="cuerpo__moo">' +
            '</div>');
        }
        
    },
    render: function(){
        if (!this.options.modal) {
            $$('select').setStyle("visibility", "hidden");
            $$('body').grab(ventana);
            
            if (!$(this.options.juntoA)) {
                $('cierra_v_moo').addEvent('click', this.cerrar.bind(this));
            }
            
            if (this.options.url == "") {
                $('conte__moo').set('html', this.options.html);
            }
            else {
                $('conte__moo').set("load", {
                    evalScripts: true,
                    evalResponse: true,
                    onSuccess: function(){
                        this.fireEvent('load');
                    }.bind(this)
                });
                $('conte__moo').load(this.options.url);
            }
            
        }
        else {
            var modal = new Element('div', {
                id: "VentanaMooModal",
                styles: {
                    backgroundColor: this.options.fondoModal,
                    opacity: this.options.opacidad,
                    height: window.getScrollHeight(),
                    width: window.getScrollWidth(),
                    zIndex: 1009,
                    position: 'absolute',
                    top: '0px',
                    left: '0px',
                    visibility: 'hidden'
                }
            });
            $$('select').setStyle("visibility", "hidden");
            $$('body').grab(modal);
            modal.tween("opacity", [0, this.options.opacidad]);
            //modal.fadeTo(this.options.opacidad);
            $$('body').grab(ventana);
            
            if (this.options.separacion == 0) {
                $('conte__moo').setStyle("padding", "0px");
            }
            
            if (this.options.htmlCerrar != "") {
                $('cierra_v_moo').set("html", this.options.htmlCerrar);
            }
            if (this.options.colorBorde != "") {
                ventana.setStyles({
                    "border-color": this.options.colorBorde
                });
            }
            if (this.options.estiloCabecera != "") {
                $('header__moo').addClass(this.options.estiloCabecera);
            }
            if (this.options.imagenFondo != "") {
                $('conte__moo').setStyle("background-image", "url(" + this.options.imagenFondo + ")");
                $('conte__moo').setStyle("background-repeat", "repeat-x");
            }
            
            this.posicionar();
            if (this.options.url == "") {
                $('conte__moo').set('html', this.options.html);
            }
            else {
               
                    $('conte__moo').set('load', {
                        'evalResponse': true,
                        'onSuccess': function(){
                            if ($(this.options.btnCerrar) && this.options.url) {
                                $(this.options.btnCerrar).addEvent('click', this.cerrar.bind(this)).setStyle("cursor", "pointer").set("title", "");
                            }
                            else {
                                $('cierra_v_moo').addEvent('click', this.cerrar.bind(this));
                            }
                            this.fireEvent('load');
                        }.bind(this)
                    });
                $('conte__moo').load(this.options.url);
            }
        }
        
        if (this.options.arrastra == "si") {
            if ($('header__moo')) {
                $('header__moo').setStyle("cursor", "move");
                $(ventana).makeDraggable({
                    handle: 'header__moo'/*,container:document.body*/
                });
            }
            
        }
        
        document.addEvents({
            'keypress': function(e){
                if (e.key == 'esc') {
                    if ($('conte__moo')) {
                        this.cerrar();
                    }
                }
            }.bind(this)
        });
        window.addEvents({
            'resize': function(){
                if ($('conte__moo')) {
                    //	$('VentanaMooModal').morph({"width":window.getScrollWidth(),"height":window.getScrollHeight()});
                    this.posicionar();
                }
                
            }.bind(this)            ,
            "scroll": function(){
                if ($('conte__moo')) {
                    //$('VentanaMooModal').morph({"width":window.getScrollWidth(),"height":window.getScrollHeight()});
                    this.posicionar();
                }
            }.bind(this)
        });
        
        if ($('VentanaMooModal')) {
            $('VentanaMooModal').addEvent("click", function(){
                if ($('conte__moo')) {
                    this.cerrar();
                }
            }.bind(this));
            
        }
        
        
        
        
        var pos = window.getHeight();
        var posAncho = window.getWidth();
        sizes = window.getSize();
        scrollito = window.getScroll();
        
        
        ventana.setStyles({
            //top:0 + defaz.toInt()  
            'top': (scrollito.y + (sizes.y - this.options.alto) / 2).toInt()
        });
        
        
    },
    cerrar: function(){
        //window.removeEvent('keypress',function(e){});
        $$('select').setStyle("visibility", "visible");
        $('VentanaMooModal').set("tween", {
            duration: 500,
            onComplete: function(){
                $('VentanaMooModal').destroy();
            }
        });
        if ($(this.options.id)) {
            $(this.options.id).destroy();
        }
        $('VentanaMooModal').tween("opacity", [this.options.opacidad, 0])
        
        $$('select').setStyle("visibility", "visible");
        this.fireEvent('cerrar');
    },
    load: function(){
    },
    posicionar: function(){
        var scrollventana = new Fx.Scroll(window, {
            wait: false,
            duration: 800,
            transition: Fx.Transitions.Sine.easeInOut
        });
        if ($(this.options.juntoA != "")) {
            var pos = $(this.options.juntoA).getCoordinates();
            scrollventana.toElement($(this.options.juntoA).getParent());
            
                ventana.set('morph', {
                    duration: 800,
                    transition: 'quad:out',
                    onComplete: function(){
                        //$('VentanaMooModal').setStyles({"width","100","height":"100"})
                    }
                }).setStyle("left", pos.left - (this.options.ancho / 2).toInt());
                ventana.morph({
                    opacity: [0.5, 1],
                    top: pos.top - (this.options.alto).toInt() - 30
                });
          
            
        }
        else {
            var pos = window.getHeight();
            var posAncho = window.getWidth();
            sizes = window.getSize();
            scrollito = window.getScroll();
            //ventana.setStyles({"top":0,"display":"none"});
            /*
             ventana.setStyles({
             //top:0 + defaz.toInt()
             'top': (scrollito.y + (sizes.y - this.options.alto) / 2).toInt()
             });
             */
           
                //$('VentanaMooModal').morph({"width":window.getScrollWidth(),"height":window.getScrollHeight()});
                //ventana.setStyles({'top': (scrollito.y + (sizes.y - this.options.alto) / 2).toInt()});
                ventana.set('morph', {
                    duration: 500,
                    transition: 'sine:in:out',
                    onComplete: function(){
                        //scrollventana.toElement($('conte__moo'));
                        ventana.setStyles({
                            "display": "block"
                        });
                    }
                }).morph({                    /*'top': (scrollito.y + (sizes.y - this.options.alto) / 2).toInt(),
                     "left":posAncho / 2 - (this.options.ancho / 2).toInt()
                     */
                });
                $('cierra_v_moo').addEvent('click', this.cerrar.bind(this));
            
        }
    }
});

function Alertas(msg,w){
	if(!w){
		$ancho=300;
	}else{
		$ancho=w;	
	}
		
	
	new Ventana({
		id:"ventana_1_registroooo",
		titulo:'Autoperu.com.pe',
		modal:true,
		html:"<div class='contenidoVentana'><img src='images/alert.png' align='absmiddle'/>"+msg+"</div>",
		ancho:$ancho,
		alto:120,
		arrastra:"si",
		fondo:"#FFF",
		estiloCabecera:"fondocabecera",
		separacion:0,
		colorBorde:"#FFB652",
		htmlCerrar: "X",
		borde:3
	}).render();
}

var ASlide = new Class({
	options: {
		showControls: false,
		showDuration: 5000,
		showTOC: false,
		tocWidth: 20,
		tocClass: 'toc',
		tocActiveClass: 'toc-active'
	},
	Implements: [Options,Events],
	initialize: function(container,elements,options) {
		//settings
		this.container = $(container);
		this.elements = $$(elements);
		this.currentIndex = 0;
		this.interval = '';
		if(this.options.showTOC) this.toc = [];
		
		//assign
		this.elements.each(function(el,i){
			var capa= new Element('div',{
			});
			capa.inject(this.container);
			if(this.options.showTOC) {
				this.toc.push(new Element('a',{
					text: i+1,
					href: '#',
					'class': this.options.tocClass + '' + (i == 0 ? ' ' + this.options.tocActiveClass : ''), //modificado para dulce
					//'class': 'toc'+(i+1)+' ' + (i == 0 ? ' ' + 'toc'+(i+1)+'-active' : ''),
					events: {
						click: function(e) {
							if(e) e.stop();
							this.stop();
							this.show(i);
						}.bind(this)
					},
					styles: {
						left: 270+ ((i + 1) * (this.options.tocWidth + 70)) //mpodificado parsa dulce  < ((i + 1) * (this.options.tocWidth + 10)) >
					}
				}).inject(this.container));
				//.inject(capa))
			}
			
			if(i > 0) el.set('opacity',0);
		},this);
		
		//next,previous links
		if(this.options.showControls) {
			this.createControls();
			
		}
		//events
		this.container.addEvents({
			mouseenter: function() { this.stop(); }.bind(this),
			mouseleave: function() { this.start(); }.bind(this)
		});

	},
	show: function(to) {
		//alert(this.currentIndex+1);
		this.elements[this.currentIndex].fade('out');
		if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
		this.elements[this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex+1 : 0))].fade('in');
		if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
	},
	start: function() {
		this.interval = this.show.bind(this).periodical(this.options.showDuration);
	},
	stop: function() {
		$clear(this.interval);
	},
	//"private"
	createControls: function() {
		var next = new Element('a',{
			href: '#',
			id: 'next',
			text: '>>',
			events: {
				click: function(e) {
					if(e) e.stop();
					this.stop(); 
					this.show();
				}.bind(this)
			}
		}).inject(this.container); 
		var previous = new Element('a',{
			href: '#',
			id: 'previous',
			text: '<<',
			events: {
				click: function(e) {
					if(e) e.stop();
					this.stop(); 
					this.show(this.currentIndex != 0 ? this.currentIndex -1 : this.elements.length-1);
				}.bind(this)
			}
		}).inject(this.container); 
	}
});

var ACarrusel= new Class({
	Implements : [Options,Events],
	contenedor:"",
	options:{
		anchoItem:"",
		altoItem:"",
		ver:2,
		avanze:2,
		anterior:"",
		siguiente:"",
		duracion:0.5,
		auto:"",
		anchoTotal:"",
		transicion:"linear",
		ruedita:"",
		controles:"si",
		imgSiguienteDesactivo:"images/eventos_flecha_sgte_desactivado.png",
		imgAnteriorDesactivo:"images/eventos_flecha_desactivado.png"
	},
	imgSiguienteActivo:"",
	imgAnteriorActivo:"",
	anchoTotal:"",
	timer:"",
	hijos:"",
	_actual:'',
	moveTo:$empty,
	initialize:function (contenedor,options){
		this.setOptions(options);
		this.contenedor=$(contenedor);
		padre=this.contenedor.getParent().getStyle("width");
		var warp= new Element("div",{
			styles:{
				"overflow":"hidden",
				"position":"relative",
				"width":padre
			}
		});
		
		
		if(this.options.ruedita!=""){
			this.contenedor.addEvents({
				"mousewheel":function(e){
					var e = new Event(e).stop();
					if ( e.wheel > 0  ) {
						this.mover("adelante");
					}else{
						this.mover("atras");
					}
				
				}.bind(this)
			});
		}
		this.contenedor.getParent().grab(warp);
		warp.adopt(this.contenedor);
		var ancho=this.contenedor.getParent().getCoordinates();
		if(this.options.anchoItem=="" && this.options.altoItem==""){
			this.options.anchoItem= (ancho.width.toInt()/this.options.ver);
			this.options.altoItem= (ancho.height.toInt()/this.options.ver);
		}
		var nodos=this.contenedor.getChildren();
		this.hijos=nodos;
		this.anchoTotal=this.options.anchoItem * nodos.length;
		this.contenedor.setStyles({"overflow":"hidden","position":"relative","list-style":"none","margin":0,"padding":0,"width":this.anchoTotal,"height":ancho.height });
		this.contenedor.getChildren()
		.setStyles({"float":"left","height":this.options.altoItem,"width":this.options.anchoItem})
		.each(function(e,k){
			//e.set("id","_item_"+(k+1).toInt());
			e.addEvents({
				"mouseenter":function(){
					if(this.options.auto!=""){
						this.detenerAutomovible();
					}
					//e.setStyle("cursor","pointer");
				}.bind(this),
				"mouseleave":function(){
					if(this.options.auto!=""){
						this.automovible();
					}
				}.bind(this)
			});
		}.bind(this));
		
		this.imgSiguienteActivo=$(this.options.siguiente).getElement("img").get("src");
		this.imgAnteriorActivo=$(this.options.anterior).getElement("img").get("src");
		
		new Asset.images([
			this.options.imgSiguienteDesactivo , this.options.imgAnteriorDesactivo
		]);
		
		
		
		if(this.options.controles=="si"){
			if(this.hijos.length > this.options.ver){
				$(this.options.anterior)
				.setStyle("cursor","pointer");
				$(this.options.siguiente)
				.setStyle("cursor","pointer");
				$(this.options.siguiente).
						addEvent("click",function(){
							this.mover("adelante");
					}.bind(this));
					
					$(this.options.anterior).
						addEvent("click",function(){
							this.mover("atras");
					}.bind(this));
				
			}else{
				//$(this.options.siguiente).getElement("img").set("src",this.options.imgSiguienteDesactivo);
				
			}
			//$(this.options.anterior).getElement("img").set("src",this.options.imgAnteriorDesactivo);
		}
		
		if(this.options.auto!=""){
				this.automovible();
		}
		this._actual=this.contenedor.getStyle("margin-left").toInt();
	},
	automovible:function(){
		this.timer=this.mover.periodical(this.options.auto * 1000,this,["adelante"]);
	},
	detenerAutomovible:function(){
		$clear(this.timer);
	},
	mover:function(direccion){	
			
			if(direccion=="adelante"){
				if(this.hijos.length > this.options.ver){
						actual=this.contenedor.getStyle("margin-left").toInt();
						this.contenedor.set("morph",{
							duration:this.options.duracion * 1000,wait:false,transition:this.options.transicion,
							
							onStart:function(){
							
								itemactual= - (this.contenedor.getStyle("margin-left").toInt());//this.anchoTotal
								aver=(itemactual/this.options.anchoItem)+1;
								if(aver>(this.hijos.length-this.options.avanze)){
									this.contenedor.get("morph").cancel();
									this.moverAlPrimero();
									return false;
								}
							}.bind(this),
							onComplete:function(){
								this._actual=this.contenedor.getStyle("margin-left").toInt();
							}.bind(this)
						});
						this.contenedor.morph({
							"margin-left":  (this._actual - this.options.anchoItem * this.options.avanze)
							//"opacity" : [0.5,1]
						});
						$(this.options.anterior).getElement("img").set("src",this.imgAnteriorActivo);
						//alert(this.imgSiguienteActivo);
						
				}else{
					//para hola hola
					$(this.options.siguiente).setStyle("cursor","default");
							
				}
				
			}else if (direccion="atras"){
			
				if(this.hijos.length > this.options.ver){		
				
					actual=this.contenedor.getStyle("margin-left").toInt();
					
					this.contenedor.set("morph",{duration:this.options.duracion * 1000,wait:false,transition:this.options.transicion,
						onStart:function(){
						
							itemactual=(this.contenedor.getStyle("margin-left").toInt());//this.anchoTotal
							
							if(itemactual==0){
								this.contenedor.get("morph").cancel();
								
									$(this.options.anterior).getElement("img").set("src",this.options.imgAnteriorDesactivo);
									
								return false;
							}
						}.bind(this),
						onComplete:function(){
							this._actual=this.contenedor.getStyle("margin-left").toInt();
						}.bind(this)
					});
					
					var posActual=this._actual;
					
					if(posActual<0){
						this.moverAlPrimero(0);
					}else{
						this.contenedor.morph({
							"margin-left":  (this._actual + this.options.anchoItem * this.options.avanze)
							//"opacity" : [0.5,1]
						});
					}
					
					
					
					
				}else{
					$(this.options.anterior).setStyle("cursor","default");
				}
			}
	},
	moverAlPrimero:function(index){
		this.contenedor.set("morph",{duration:this.options.duracion * 1000,wait:true,transition:this.options.transicion});
		this.contenedor.morph({
			"margin-left":  0
			//"opacity" : [0.5,1]
		});
		this._actual=0;
	},
	moveTo:function(index){
		coords=$(index).getCoordinates();
		coorContainer=this.contenedor.getCoordinates();
		
		
		this.contenedor.set("morph",{
			onComplete:function(){
				this._actual=this.contenedor.getStyle("margin-left").toInt();
			}.bind(this)
		});
		
		this.contenedor.morph({
			"margin-left":  -(this._actual - ( coorContainer.left - coords.left) )
		});
		
		var posActual=this._actual;
		
	}
});

var AGalery= new Class({
	Implements: [Options,Events],
	options :{
		altoImagen:400,
		anchoImagen:400,
		klass:"galery",
		opacidad:0.5,
		fondoModal:"#000",
		altoDiv:600,
		anchoDiv:600,
		colorFondo:'white',
		imgFondo:''
	},
	imgs:[],
	prev:null,
	next:null,
	imagenActual:0,
	divImagen:null,
	modal:null,
	initialize:function(options){
		this.modal= new Element('div',{
				id:"VentanaMooModal",
				styles:{
					backgroundColor : this.options.fondoModal,
					opacity:this.options.opacidad,
					height:window.getScrollHeight(),
					width:window.getScrollWidth(),
					zIndex:1009,
					position:'absolute',
					top:'0px',
					left:'0px',
					visibility:'hidden'
				}
			});	
			
	
			
			
		this.divImagen=new Element("div",{
				id:this.options.id,
					styles:{
						backgroundColor : this.options.colorFondo,
						height:this.options.altodiv,
						width:this.options.anchodiv,
						position:'absolute',
						left:parseInt(window.getWidth()/2)-parseInt(this.options.anchoDiv/2),
						top:parseInt(window.getHeight()/2)-parseInt(this.options.altoDiv/2),
						zIndex:1200,
						display:'none'
					}
					
		});
			
		this.modal.addEvent("click",this.close.bind(this))	;
		this.setOptions(options);
		this.imgs=$$('a.'+this.options.klass);
		this.imgs
		.each(function(j,k){
			j.
			addEvent("click",function(e){
				e.stop();
				this.init(k);
			}.bind(this));
		}.bind(this));
	},
	init:function(e){
		if(!$('VentanaMooModal')){
			$$('body').grab(this.modal);
			this.modal.tween("opacity",[0,this.options.opacidad]);
			$$('body').grab(this.divImagen);

		}
	
	},
	close:function(){
		$$('select').setStyle("visibility","visible");
			$('VentanaMooModal')
			.set("tween",{
				duration:500,
				onComplete:function(){
						$('VentanaMooModal').destroy();
				}
			});
			
			$('VentanaMooModal').tween("opacity",[this.options.opacidad,0])
			
			$$('select').setStyle("visibility","visible");
			this.fireEvent('cerrar');
	}
	
});

var Tooltips = new Class({
    Implements: Options,
    options: {
        objeto: "moo__tip",
        clase: "mootips",
        ancho: 250,
        alto: 150,
        fondo: "",
        html: "",
        div: "moo",
        posicion: "arriba",
        estiloInterior: "",
        evento: "over",
        bntCerrar: "",
        colorFondo: "",
        borde: "",
        forzarCierre: true,
        aliner: "",
        opacidad: 1,
        cerrarTodos: false,
		top:'',
		left:'',
		offsetX:0,
		offsetY:0,
		duracion:0.5
    },
    initialize: function(options){
        this.setOptions(options);
        this.cerrar();
        if (this.options.evento == "over") {
            this.bntCerrar = "";
        }
        
        
        moo___tip = new Element("div", {
            id: 'moo_tip__' + this.options.div,
            styles: {
                backgroundImage: 'url(' + this.options.fondo + ')',
                backgroundRepeat: 'no-repeat',
                border: '0px solid blue',
                width: this.options.ancho + 'px',
                height: this.options.alto + 'px',
                position: 'absolute',
                visibility: 'hidden',
                padding: '0px',
                zIndex: 1500
            },
            'class': 'moot_tipo_alex',
            html: '<div align="right" style="padding-right:10px;margin-top:2px;float:right"  id="cierraTip__' + this.options.div + '">' + this.options.bntCerrar + '</div><div style="padding:10px">' +
            '<div class="' +
            this.options.estiloInterior +
            '">' +
            this.options.html +
            '</div></div>'
        });
        if (this.options.fondo != "") {
        }
        
        if (this.options.colorFondo != "") {
            moo___tip.setStyle("background-color", this.options.colorFondo);
        }
        
        if (this.options.borde != "") {
            moo___tip.setStyle("border", this.options.borde);
        }
        moo___tip.setStyle("top", "0px");
        
        moo___tip.setOpacity(this.options.opacidad);
        
        if (!$('moo_tip__' + this.options.div)) {
            $$('body').grab(moo___tip);
        }
        
        

        $(this.options.div).addEvents({
            "mouseenter": function(e){
                e.stop();
                if (this.options.evento == "over") {
                    this.mostrar();
                }
                
                
            }.bind(this)            ,
            "mouseleave": function(){
                if (this.options.evento == "over" || this.options.forzarCierre == false) {
                    this.cerrar();
                }
            }.bind(this)            ,
            "click": function(e){
               // e.stop();
                if (this.options.evento == "click") {
                    this.mostrar();
                }
            }.bind(this)
        }).setStyle('cursor', 'pointer');
        
        $('cierraTip__' + this.options.div).addEvent("click", function(){
            this.cerrar();
        }.bind(this)).setStyle("cursor", "pointer");
        

        
        document.addEvent("click", function(){
            if (moo___tip) {
            }
        }.bind(this));
        
        $('moo_tip__' + this.options.div).set("morph",{duration:(this.options.duracion * 1000)  });
    },
    iniciar: function(){
    
    
    },
    mostrar: function(){
        if (this.options.cerrarTodos) {
            $$('.moot_tipo_alex').hide();
        }
        
        pos = $(this.options.div).getCoordinates();
        if (this.options.alinear != "") {
            switch (this.options.alinear) {
                case "izquierda":
                    miizquierdaarriba = (pos.left).toInt();
                    miizquierdaabajo = (pos.left).toInt();
                    break;
                default:
                    miizquierdaarriba = (pos.left).toInt() - (this.options.ancho / 2);
                    miizquierdaabajo = (pos.left).toInt() - ((this.options.ancho - pos.width) / 2).toInt();
            }
            
        }
        switch (this.options.posicion) {
            case "arriba":
                $('moo_tip__' + this.options.div).setStyles({
                    'left': miizquierdaarriba,
                    'top': (pos.top) - this.options.alto - 10
                }).morph({
                    'top': [$('moo_tip__' + this.options.div).getStyle("top"), (pos.top).toInt() - this.options.alto]
                });
                break;
                
            case "abajo":
                $('moo_tip__' + this.options.div).setStyle('left', miizquierdaabajo).morph({
                    'top': [(pos.top).toInt() + pos.height + 10, (pos.top).toInt() + pos.height]
                });
                break;
            case "centroArriba":
                $('moo_tip__' + this.options.div).setStyles({
					'left': miizquierdaarriba + $(this.options.div).getStyle("width").toInt() / 2  + this.options.offsetX,
					'top': pos.top - this.options.alto + this.options.offsetY
                })
				.morph({
                    'top': [(pos.top - this.options.alto) - 10, (pos.top).toInt() - this.options.alto + this.options.offsetY]
                });
            break;
			
			case "personalizado":
                $('moo_tip__' + this.options.div)
				.setStyle('left', this.options.left).morph({
                    'top': this.options.top
                });
            break;
        }
        $('moo_tip__' + this.options.div).show();
    
    },
    cerrar: function(){
        if ($('moo_tip__' + this.options.div)) {
            $('moo_tip__' + this.options.div).hide();
    
        }
    }
});


Fx.MorphList = new Class({   
	
	Implements: [Events, Options],
	
	options: {/*             
		onClick: $empty,
		onMorph: $empty,*/
		bg: {'class': 'background', html: '<div class="inner"></div>', morph: {link: 'cancel'}}		
	},
	
	initialize: function(element, options){
		var self = this;
		this.setOptions(options);
		this.element = $(element);		
		this.items = this.element.getChildren().addEvents({
			mouseenter: function(){ self.morphTo(this); },
			mouseleave: function(){ self.morphTo(self.current); },
			click: function(ev){ self.onClick(ev, this); }
		});       
		this.bg = new Element('li', this.options.bg).inject(this.element).fade('hide');
		this.setCurrent(this.element.getElement('.current'));
	},

	onClick: function(ev, item){
		this.setCurrent(item, true).fireEvent('click', [ev, item]);
	},
	
	setCurrent: function(el, effect){  
		if (el && !this.current){
			this.bg.set('styles', el.getCoordinates(this.element));
			(effect) ? this.bg.fade('in') : this.bg.fade('show');
		}
		if (this.current) this.current.removeClass('current');
		if (el) this.current = el.addClass('current');    
		return this;
	},         
         
	morphTo: function(to){
		if (to){
			var c = to.getCoordinates(this.element);
			delete c['right']; delete c['bottom'];
			this.bg.morph(c);
			this.fireEvent('morph', to);
		}
		return this;
	}

});


var BarackSlideshow = new Class({
  
  Extends: Fx.MorphList,
  
  options: {
    onShow: $empty,
    auto: true,
    autostart: true,
    autointerval: 2000,
    transition: 'fade',
    tween: { duration: 800}
  },
  
  initialize: function(menu, images, loader, options){
    this.parent(menu, options);
    this.images = $(images);
    this.imagesitems = this.images.getChildren().fade('hide');
    $(loader).fade('in');
    new Asset.images(this.images.getElements('img').map(function(el) { return el.setStyle('display', 'none').get('src'); }), { onComplete: function() {
      this.loaded = true;      
	  this.images.fade("in");
      $(loader).fade('out');
      if (this.current) this.show(this.items.indexOf(this.current));
      else if (this.options.auto && this.options.autostart) this.progress();
    }.bind(this) });
    if ($type(this.options.transition) != 'function') this.options.transition = $lambda(this.options.transition);
  },
  
  auto: function(){
    if (!this.options.auto) return false;
    $clear(this.autotimer);
    this.autotimer = this.progress.delay(this.options.autointerval, this);
  },
  			
  onClick: function(event, item){
    this.parent(event, item);
    event.stop();
    this.show(this.items.indexOf(item));
    $clear(this.autotimer);
  },
  
  show: function(index) {
    if (!this.loaded) return;
    var image = this.imagesitems[index];    
		if (image == this.curimage) return;
    image.set('tween', this.options.tween).dispose().inject(this.curimage || this.images.getFirst(), this.curimage ? 'after' : 'before').fade('hide');
		image.getElement('img').setStyle('display', 'block');
    var trans = this.options.transition.run(null, this).split('-');
    switch(trans[0]){
      case 'slide': 
        var dir = $pick(trans[1], 'left');
        var prop = (dir == 'left' || dir == 'right') ? 'left' : 'top';
        image.fade('show').setStyle(prop, image['offset' + (prop == 'left' ? 'Width' : 'Height')] * ((dir == 'bottom' || dir == 'right') ? 1 : -1)).tween(prop, 0); 
        break;
      case 'fade': image.fade('in'); break;
    }
    image.get('tween').chain(function(){ 
      this.auto();
      //this.fireEvent('show', image);  //alex
	  this.fireEvent('show', index);  //alex
    }.bind(this));
    this.curimage = image;
    this.setCurrent(this.items[index])
    this.morphTo(this.items[index]);
		return this;
  },
  
  progress: function(){
    var curindex = this.imagesitems.indexOf(this.curimage);
    this.show((this.curimage && (curindex + 1 < this.imagesitems.length)) ? curindex + 1 : 0);
  }
  
});

/****/		
//new Asset.css('css/formcheck.css');
var auto = new Auto();

window.addEvent("domready",function(){
//*title a links e imagenes**/	
	//$$('a').each(function(e){e.set("title",e.get("html"))});
	$$('img').each(function(e){e.set("title",e.get("alt"))});
//****//
});


