var morper;
var leftIni;
var topIni;
window.addEvent('domready', function() {
new MorphList($('menu').getElement('ul'), {transition: Fx.Transitions.backOut, duration: 300,onClick: function(ev, item) { 

ev.stop(); 

}
});
var infox= document.getScrollSize().x-400-(document.getScrollSize().x%20);
var infoy= document.getScrollSize().y-440-(document.getScrollSize().y%20);

$$('body').setStyle('background-position',infox+'px '+infoy+'px');
var foto=new Array();
var alt=new Array();
foto[0]='fachada.jpg';
alt[0]='Fachada de la casa rural Apezetxea en Munarriz';
foto[1]='hall.jpg';
alt[1]='Parte del hall del edificio';
foto[2]='salon2.jpg';
alt[2]='Vista de la chimenea en el salón principal';
foto[3]='salon1.jpg';
alt[3]='Una vista del salón principal';
foto[4]='salon3.jpg';
alt[4]='Vista del salon pricipal';
foto[5]='habitacion_1.jpg';
alt[5]='Vista de una habitación';
foto[6]='habitacion_5.jpg';
alt[6]='Vista de una habitación';
foto[7]='habitacion_6.jpg';
alt[7]='Vista de una habitación';
foto[8]='habitacion_7.jpg';
alt[8]='Vista de una habitación';
foto[9]='habitacion_2.jpg';
alt[9]='Vista de una habitación';
foto[10]='habitacion_4.jpg';
alt[10]='Vista de una habitación';
foto[11]='habitacion_3.jpg';
alt[11]='Vista de una habitación';
foto[12]='habitacion_8.jpg';
alt[12]='Vista de una habitación';
foto[13]='escalera_2.jpg';
alt[13]='Escalera acceso a tercera planta';
foto[14]='salon_b.jpg';
alt[14]='Salón alternativo';
foto[15]='cocina.jpg';
alt[15]='Vista de la cocina';


var indice=0;

var mitad = document.getScrollSize().x/2;
$('derecha').setStyle('left',mitad+165);
$('izquierda').setStyle('left',mitad-275);
$('fotografias').addEvent('click',function(e){
e.stop();
//$$('#menu ul').setStyle('margin-top','-110px')
$$('#menu ul').each(function(el, i){

el.removeClass('current');


})

$('fotografias').addClass('current');
    //$('izquierda').setStyle('display',"block");
SqueezeBox.open('http://www.casaruralapezetxea.com/es/fotografias?&foto=fachada.jpg&alt=Fachada de la casa rural Apezetxea en Munarriz', {handler: 'iframe',size:{x:600,y:356}});

    var toBlock = function(){
    $('derecha').setStyle('display',"block");
    };
    toBlock.delay(1200);
    
})
$('derecha').addEvents({
    'mouseenter':function(){
    
        if(this.getLast().vmlBg){
            //this.innerHTML=this.innerHTML.replace(/derecha.png/g,'derecha_hover.png');
            //this.getLast().vmlBg="/assets/templates/apezetxea/images/derecha_hover.png";
            //this.getLast().src="/assets/templates/apezetxea/images/derecha_hover.png";
        }else{
            this.getChildren()[0].src="/assets/templates/apezetxea/images/derecha_hover.png";
        }
    },
    'mouseout':function(){
        if(this.getLast().vmlBg){
           //this.innerHTML=this.innerHTML.replace(/derecha_hover.png/g,'derecha.png');
            //this.getLast().vmlBg="/assets/templates/apezetxea/images/derecha.png";
            //this.getLast().src="/assets/templates/apezetxea/images/derecha.png";
        }else{
            this.getChildren()[0].src="/assets/templates/apezetxea/images/derecha.png";
        }
    },
    'click':function(){
    indice=indice+1;
    if(foto[indice]==foto.getLast()){
    $('derecha').setStyle('display',"none");
    }else{
    $('derecha').setStyle('display',"block");
    }
    $('iforframe').src="/es/fotografias?&foto="+foto[indice]+"&alt="+alt[indice]+"";
    $('izquierda').setStyle('display',"block");
    }
});
$('izquierda').addEvents({
    'mouseover':function(){
        if(this.getLast().vmlBg){
            //this.innerHTML=this.innerHTML.replace(/izquierda.png/g,'izquierda_hover.png');
            //this.getLast().vmlBg="/assets/templates/apezetxea/images/izquierda_hover.png";
            //this.getLast().src="/assets/templates/apezetxea/images/izquierda_hover.png";
        }else{
            this.getChildren()[0].src="/assets/templates/apezetxea/images/izquierda_hover.png";
        }
    },
    'mouseout':function(){
        if(this.getLast().vmlBg){
            //this.innerHTML=this.innerHTML.replace(/izquierda_hover.png/g,'izquierda.png');
            //this.getLast().vmlBg="/assets/templates/apezetxea/images/izquierda.png";
            //this.getLast().src="/assets/templates/apezetxea/images/izquierda.png";
        }else{
            this.getChildren()[0].src="/assets/templates/apezetxea/images/izquierda.png";
        }
   },
    'click':function(){
    indice=indice-1;
    if(indice==0){
    $('izquierda').setStyle('display',"none");
    }else{
   
    $('izquierda').setStyle('display',"block");
    }
    $('iforframe').src="/es/fotografias?&foto="+foto[indice]+"&alt="+alt[indice]+"";
    $('derecha').setStyle('display',"block");
    }
});


$$('#menu ul li a').addEvent('mouseover', function(e) {

    //fademe($$('.background'),0.7);
    //clear_morpme(this);
    leftIni=backgroundPosition(this).split(' ')[0].toInt();
    topIni= backgroundPosition(this).split(' ')[1].toInt();
    //alert(backgroundPosition(this).split(' ')[1].toInt());
    morper=morpme.periodical(150,this,this);
    

    
})
$$('#menu ul li a').addEvents({

'mouseout': function() {
    clear_morpme(this);
},
'mousedown': function() {
    clear_morpme(this);
},
'click': function() {
    clear_morpme(this);
},
'mouseup': function() {
    clear_morpme(this);
}    
})

$('fade').setStyle('opacity',0);
SqueezeBox.assign($$('a.boxed'), {
		parse: 'rel'
	});



})
function toogleme(el,total){
if (el.getStyle('display')=="none"){
el.setStyle('display','block');
}else{
el.setStyle('display','none');
}
}
function morpme(el){
var top= topIni+$random(-7, 7);
var left= leftIni+$random(-7, 7);
el.setStyle('backgroundPosition',backgroundPosition(el));
el.setStyle('background-position',left+'px '+top+'px');
}
function clear_morpme(el){
$clear(morper);

    var top= topIni;
    var left= leftIni;
   el.setStyle('backgroundPosition',backgroundPosition(el));
    el.setStyle('background-position',left+'px '+top+'px');
}
function backgroundPosition( el )
	{
	  var bp = el.getStyle("background-position");
	  if(bp == undefined) 
	  {
 
	    bp = el.getStyle("background-position-x")+" "+el.getStyle("background-position-y");
	    return bp;
 
	  } 
	  else
	  {
	 	return bp;
	  }
	}




