(function() {
    
    var Carrusel = {
        'nextImage': function() {
            this.myFx.start('margin-left', parseFloat($$('#carruselContainer > div')[0].getStyle('marginLeft')) - 950);
        },
        'procesarCola': function() {
            var copy = $$('#carruselContainer > div > div')[0].clone();
            $$('#carruselContainer > div')[0].grab(copy);
            $$('#carruselContainer > div > div')[0].dispose();
            $$('#carruselContainer > div')[0].setStyle('marginLeft', -950);
            var descripcion = $$('#carruselContainer > div div:nth-child(2) img')[0].get('alt');
            $('descripcionContainer').set('html', descripcion);
        },
        'init': function() {
            this.myFx = window.myFx = new Fx.Tween($$('#carruselContainer > div')[0]);
            this.myFx.addEvent('complete',
            function() {
                this.procesarCola();
            }.bind(this));
        },
        'ChangeTheCaption': function() {
            var scnWid,
            scnHei;
            if (self.innerHeight)
            // all except Explorer
            {
                scnWid = self.innerWidth;
                scnHei = self.innerHeight;
            }
            else if (document.documentElement && document.documentElement.clientHeight)
            // Explorer 6 Strict Mode
            {
                scnWid = document.documentElement.clientWidth;
                scnHei = document.documentElement.clientHeight;
            }
            else if (document.body)
            // other Explorers
            {
                scnWid = document.body.clientWidth;
                scnHei = document.body.clientHeight;
            }
            var theverticalposition = scnHei - $('photocaption').getStyle("height").toInt();
            theverticalposition = theverticalposition + "px";
            $('photocaption').setStyle("top", theverticalposition);
            $('carruselContainer').setStyle("height", scnHei + "px");
        }

    };


    window.LaminovaCarrusel = Carrusel;
    window.addEvent('domready',
    function() {
        Carrusel.init();

        $('bgChanger').addEvent('click',
        function() {
            Carrusel.nextImage();
        });
        window.addEvent('load',
        function() {
            Carrusel.ChangeTheCaption();
        });
        window.addEvent('resize',
        function() {
            Carrusel.ChangeTheCaption();
        });

    });


})();

if(window.laminova && window.laminova.effectOn) {
    window.addEvent('domready', function() {
        //if($('myWidget')) return;
        var folded = false;
        if($('photocaption')) {
        
            var photoCaption = $$('#photocaption h3')[0];
            photoCaption.setAttribute('title', 'Fotografía de Fondo::Haga click aquí para ver la foto completa');
            photoCaption.addClass('myTips');
            
            $$('.myTips').each(function(element,index) {
		        var content = element.get('title').split('::');
		        element.store('tip:title', content[0]);
		        element.store('tip:text', content[1]);
	        });
            
            var myTips = new Tips('.myTips',{
				className: 'tipz',
				fixed: true,
				hideDelay: 50,
				showDelay: 50
            });
            //console.log(myTips);
            
            var clone = new Element('div', {
                'styles': {
                    'width': '950px',
                    'margin' : '0 auto',
                    'position': 'relative',
                    'cursor' : 'pointer'
                },
                'title': 'Haz click aquí para ver la navegación completa',
                'class': 'myTips'
            });
            var ielt8 = Browser.Engine.trident && (Browser.Engine.version <= 5);
            
            var display = ielt8 ? 'display: none;' : '';
            
            clone.set('html', '<div id="fgr56yg" class="titledark flir-replaced" style="'+display+'position:absolute;margin-top:-23px;padding-top: 7px; width: 55px; height: 16px; background-color: #423B35; padding-left: 55px; margin-left: 42px;"><img style="border: medium none ;" src="templates/laminova/js/facelift-1.2/generate.php?text=menu&amp;h=25&amp;w=68&amp;fstyle=%7B%22mode%22%3A%22wrap%22%2C%22output%22%3A%22auto%22%2C%22cSize%22%3A%2218%22%2C%22cColor%22%3A%22rgb%28119%2C%20117%2C%20107%29%22%2C%22cFont%22%3A%22fgcond%22%2C%22realFontHeight%22%3A%22false%22%2C%22dpi%22%3A%2296%22%2C%22cBackground%22%3A%22transparent%22%2C%22cSpacing%22%3A%22%22%2C%22cLine%22%3A%221%22%2C%22cAlign%22%3A%22start%22%2C%22cTransform%22%3A%22none%22%7D" class="flir-image" alt="menu"></div>');
            
            
            
            clone.inject($$('body')[0]);//setStyle('display', 'none');
            
            var effectIn = function(){
                
                new Fx.Tween('fgr56yg').start('marginTop', -23).chain(function(){
                    new Fx.Reveal('backgroundbar').reveal().chain(function(){
                        new Fx.Reveal('content').reveal().chain(function(){
                            if($('myWidget')){
                                new Fx.Reveal('myWidget').reveal();
                            }
                            new Fx.Reveal('bigIntro').reveal().chain(function(){
                                new Fx.Reveal('headercontainer').reveal().chain(function(){
                                    new Fx.Reveal('news').reveal().chain(function(){
                                        new Fx.Reveal('linksRapidos').reveal();
                                    });
                                 });
                            });
                        });
                    });
                });
                folded = false;
            }; // end effectIn
            
            var effectOut = function(){
            
                folded = true;
                new Fx.Reveal('linksRapidos').dissolve().chain(function(){
                    new Fx.Reveal('news').dissolve().chain(function(){
                        new Fx.Reveal('headercontainer').dissolve().chain(function(){
                            if($('myWidget')){
                                new Fx.Reveal('myWidget').dissolve();
                            }
                            new Fx.Reveal('bigIntro').dissolve().chain(function(){
                                new Fx.Reveal('content').dissolve().chain(function(){
                                    new Fx.Reveal('backgroundbar').dissolve().chain(function(){
                                        new Fx.Tween('fgr56yg').start('marginTop', 0);
                                    });
                                });
                             });
                        });
                    });
                });
            }; // end effectOut
            
            $$('#photocaption .descriptiontitle')[0].setStyle('cursor', 'pointer');
            
            $$('#photocaption .descriptiontitle').each(function(el){
                el.addEvent('click', function(){
                    if (folded) {
                        effectIn();
                    }
                    else {
                        effectOut();
                    }
                });
            });
            
            $('fgr56yg').addEvent('click', function(){
                effectIn();
            });
        }
    });
}

