/**

Class papaJohns
require Mootools 1.2.5 + More
require class.Carrusel
require class.Slide
require class.Window

**/

new Asset.javascript("js/class.IE6.js"); //para ie6
var opreload;
var PapaJohns= new Class({

	initialize:function(){},

	prepareHome:function(){

		new ASlide('promo', '#promo img').start();

		var CarruselHome = new ACarrusel("carruselHome",{
				avanze:3,
				ver:3,
				anchoItem:303,
				altoItem:"auto",
				siguiente:'sig',
				anterior:'ant',
				duracion:0.5,
				transition :'sin:in',
				regresaAlPrimero : true
		});
	},
	prepareDelivery:function(){

		new AZoom("aZoom",{
			capaZoom:"area_zoom",
			mas:"b_mas",
			menos:"b_menos",
			altoImagen:806,
			anchoImagen:734,
			limita:"si",
			modeSlider:"vertical"

		});

		var links = $$('a.envio');
		links.each(function(element,index){
			element.addEvent("click",function(ev){
				ev.stop();
				this.sendToFriend(element);
			}.bind(this));
		}.bind(this));

	},
	prepareMenu:function(){

		var links = $$('a.envio');
		links.each(function(element,index){
			element.addEvent("click",function(ev){
				ev.stop();
				this.sendToFriend(element);
			}.bind(this));
		}.bind(this));

	},
	preparePromos:function(){
		new ASlide('foto_promo', '#foto_promo img', {showDuration:6000, onChange: function(){ alert($$('#foto_promo img[style^="visibility: visible"]')[0].id)} }).start();


		var links = $$('a.envio');
		links.each(function(element,index){
			element.addEvent("click",function(ev){
				ev.stop();
				this.sendToFriend(element);
			}.bind(this));
		}.bind(this));
	},
	openShareTwitter:function(url,title){
		titulo=title;
		window.open("http://www.twitter.com/intent/tweet?text="+titulo.replace(/ /g,"+",title)+"&url="+url,"Twitter","toolbar=0, status=0, width=550, height=420");

	},
	openShareTwitter2:function(url,title){
		id = $('foto_promo').getChildren('img[style^="visibility: visible"]')[0].id
		url = url+''+id
		titulo=title;
		window.open("http://www.twitter.com/intent/tweet?text="+titulo.replace(/ /g,"+",title)+"&url="+url,"Twitter","toolbar=0, status=0, width=550, height=420");

	},

	openShareTwitterSpecial:function(id){
		titulo=document.title;
		window.location.href=document.location.pathname+"#!"+id;
		url_completa=window.location.href;
		window.open("http://www.twitter.com/intent/tweet?text="+titulo.replace(/ /g,"+",document.title)+"&url="+url_completa,"Twitter","toolbar=0, status=0, width=550, height=420");
	},

	openShareFacebook:function(url){
		window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent((url=="")?window.location.href:url)+"&rand="+$random(0, 200),"Facebook","toolbar=0, status=0, width=550, height=420");
	},

	openShareFacebook2:function(url){
		id = $('foto_promo').getChildren('img[style^="visibility: visible"]')[0].id
		url = url+''+id
		window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent((url=="")?window.location.href:url)+"&rand="+$random(0, 200),"Facebook","toolbar=0, status=0, width=550, height=420");
	},
	openShareFacebookSpecial:function(id){
		window.location.href=document.location.pathname+"#!"+id;
		url_completa=window.location.href;
		window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(url_completa)+"&rand="+$random(0, 200),"Facebook","toolbar=0, status=0, width=550, height=420");
	},
	sendToFriend:function(element){

		urlToSend = element.get("href");

		new Ventana({
			modal:true,
			fondo:"",
			alto:500,
			ancho:680,
			borde:0,
			separacion:0,
			btnCerrar:"cerrar",
			url:"enviar_amigo.php?url="+encodeURIComponent(urlToSend),
			move:true
		}).render();

	},
	prepareSales:function(){
		$('form_ventas').addEvent("submit",function(e){
			if(Spry.Widget.Form.validate($('form_ventas'))){
				document.getElementById('enviar').disabled = 'disabled'
			}
		});

		var theForm = $('form_ventas');

		theForm.sendAjaxForm(function(e){
			this.thanks();
			theForm.reset();
			document.getElementById('enviar').disabled = ''
		}.bind(this),true);

	},
	prepareCustomerService:function(){
		var t = this;
		$('form_serviciocliente').addEvent("submit",function(e){
			if(Spry.Widget.Form.validate($('form_serviciocliente'))){
				document.getElementById('enviar').disabled = 'disabled'
			}
		});
		var theForm = $('form_serviciocliente');
			$('form_serviciocliente').reset();
			theForm.sendAjaxForm(function(e){
				this.thanks();
				theForm.reset();
			document.getElementById('enviar').disabled = ''
                        }.bind(this),true);
	},
	prepareWorks:function(){

		var t = this;
		$('form_trabaja').addEvent("submit",function(e){
			if(Spry.Widget.Form.validate($('form_trabaja'))){
				document.getElementById('enviar').disabled = 'disabled'
				alert('Espere un momento porfavor.');
				t.preload();
			}else{
				e.preventDefault()
			}
		});

		$$('div.opciones').hide();
		$('form_trabaja').reset();

		var op1 = $$('div.opciones p')[0];
		var op2 = $$('div.opciones p')[1];
		var checks1 = $$('div.opciones p')[0].getElements('input[type="checkbox"]');
		var checks2 = $$('div.opciones p')[1].getElements('input[type="checkbox"]');


		$$('input[name="area"]')
		.addEvent("click",function(){
			$$('div.opciones').hide();
			if(this.value=="tienda"){
				op1.hide();
				checks1.set("checked","");
				op2.show();
				$$('div.opciones').show();
			}else{
				op2.hide();
				checks2.set("checked","");
				op1.show();
				$$('div.opciones').show();
			}
		});

		$$('input[value="otros"]')
		.addEvent("click",function(){
			if(this.checked){
				$('texto_otros').show();
				$('texto_otros').focus();
			}else{
				$('texto_otros').set("value","").hide();
			}
		});
	},
	openBirthday:function(){
		new Ventana({
			modal:true,
			fondo:"",
			alto:600,
			ancho:650,
			borde:0,
			separacion:0,
			btnCerrar:"btn_cerrar",
			url:"reservacumple.php",
			onCerrar:function(){
				$$('div.datePicker').hide();
			},
			move:false
		}).render();
	},
	prepareFormBirthday:function(){

		$('form_cumple').addEvent("submit",function(e){
			if(Spry.Widget.Form.validate($('form_cumple'))){
				document.getElementById('enviar').disabled = 'disabled'
			}
		});

		var hoy = new Date();
		var salidaFrom = new Date(hoy.getFullYear(),hoy.getMonth(),hoy.getDate());
		salidaFrom = [salidaFrom.getFullYear(),salidaFrom.getMonth(),salidaFrom.getDate()];

		$('fecha').datePicker({
			from: salidaFrom
		});

		$('form_cumple').sendAjaxForm(function(){
			$('btn_cerrar').fireEvent("click");
		}.bind(this),true);
	},
	prepareTours:function(){

		$('form_papatour').addEvent("submit",function(e){
			if(Spry.Widget.Form.validate($('form_papatour'))){
				document.getElementById('enviar').disabled = 'disabled'
			}
		});

		$('distrito').addEvent("change",function(){
			new Request.JSON({
				url:'filterStores/',
				onComplete:function(data){

					if(data.id!=0){
						$('nombre_tienda').set("value",data.nombre);
						$('tienda').set("value",data.id);
					}else{
						$('nombre_tienda').set("value","Lamentablemente no tenemos locales cerca.");
						$('tienda').set("value",data.id);
					}
				}
			}).send("id="+this.value);
		});

		$('form_papatour').sendAjaxForm(function(){
			this.thanks();
			document.getElementById('enviar').disabled = ''
		}.bind(this),true);
	},
	thanksAlert:function(){
		alert("Gracias por enviarnos la informacion.Pronto estaremos en contacto con Ud.");
	},
	thanks:function(){

		new Ventana({
			modal:true,
			fondo:"",
			alto:200,
			ancho:450,
			borde:0,
			separacion:0,
			btnCerrar:"cerrar",
			url:"agradecimiento.php",
			move:true
		}).render();

	},
	thanks2:function(){
		opreload = new Ventana({
			modal:true,
			fondo:"",
			alto:200,
			ancho:450,
			borde:0,
			separacion:0,
			btnCerrar:"cerrar",
			url:"agradecimiento.php",
			move:true
		}).render();

	},
	preload:function(){

		var modalX = new Element('div', {
                id: "VentanaX",
                styles: {
                    backgroundColor: '#fff',
                    opacity: 0.0,
                    height: window.getScrollHeight(),
                    width: window.getScrollWidth(),
                    zIndex: 99999,
                    position: 'absolute',
                    top: '0px',
                    left: '0px',
                    visibility: 'hidden'
                }
            });

            $$('body').grab(modalX);
            modalX.tween("opacity", [0, 0.2]);

	},
	filterCollections:function(id){

		new Request.JSON({
			url:'colecctions.php',
			onComplete:function(data){
				var selectChange=$('tour_name');
				selectChange.set("html","");

				new Element("option",{
					value:"",html:"- Please select a tour name -"
				}).inject(selectChange);

				data.each(function(k){
					new Element("option",{
						value:k.id,html:k.titulo
					}).inject(selectChange);
				});
			}
		}).send("id="+id); 
	}
});

alertWorks = function (){
	alert("Gracias por enviarnos tu cv pornto estaremos en contacto contigo");
        window.location.href = '/trabaja-con-nosotros'
}

var papaJohns= new PapaJohns();

window.addEvent("domready",function(){
	//new Asset.image("images/bg_menu_despleg.png");
	$$('iframe').set("allowtransparency",true);
});
