///*
//---
//name: FitImage
//description: fix in place and fitto screen any background image
//license: MIT-style license.
//authors:
//- Anton Suprun
//requires:
//- Core/Array
//- Core/Class.Extras
//- Core/DOMReady
//- Core/Element.Dimensions
//provides: [FitImage]
//...
//*/


//var FitImage = new Class({

//    Implements: [Events, Options],

//    options: {
//        'class': 'resize-background',
//        'center': true,
//        'minWidth': 1024,
//        'minHeight': 768,
//        'primary': 'auto',
//        'injectElement': null,
//        'injectPosition': 'top'
//    },

//    initialize: function(image, options) {
//        options = options || {};
//        options.primary = options.primary && ['width', 'height', 'auto'].contains(options.primary)
//			? options.primary
//			: 'auto';
//        this.setOptions(options);
//        // *** Permanently bind some methods
//        this.resize = this.resize.bind(this);
//        this.inject = this.inject.bind(this);
//        // *** Load the image
//        this.image = new Element('img', {
//            'src': image,
//            'class': this.options['class']
//        }).addEvent('load', this.inject);
//        // In case browser does not support load event for images
//        this.attach();
//    },

//    attach: function() {
//        window.addEvents({
//            'load': this.inject,
//            'domready': this.resize,
//            'resize': this.resize
//        });
//    },

//    detach: function() {
//        window.removeEvents({
//            'load': this.inject,
//            'domready': this.resize,
//            'resize': this.resize
//        });
//    },

//    inject: function() {
//        if (!this.injected) {
//            if (!this.options.injectElement) this.options.injectElement = document.body;
//            this.image.inject(this.options.injectElement, this.options.injectPosition);
//            this.injected = true;
//        }
//        // *** If image fails to resize, return launching resize on inject call even after inject becomes true
//        this.resize();
//        return this;
//    },

//    resize: function() {
//        var size = window.getSize(),
//			rate = size.x / size.y,
//			styles = {};

//        if (!this.size || this.size.x == 0) {
//            // *** Detect image size
//            this.size = this.image.getSize();
//            if (this.size.x == 0) return this; // Not loaded yet
//            this.rate = this.size.x / this.size.y;
//        }

//        // *** Set first dimension size
//        if (this.options.primary == 'width' || (this.options.primary == 'auto' && this.rate < rate)) {
//            styles.width = size.x;
//            styles.height = null;
//        } else if (this.options.primary == 'height' || (this.options.primary == 'auto' && this.rate > rate)) {
//            styles.width = null;
//            styles.height = size.y;
//        } else {
//            // *** Perfect fit!
//            styles.width = size.x;
//            styles.height = size.y;
//        }

//        // *** Min width && height
//        if (styles.width !== null && this.options.minWidth > styles.width) styles.width = this.options.minWidth;
//        if (styles.height !== null && this.options.minHeight > styles.height) styles.height = this.options.minHeight;

//        // *** Calculate second dimension size
//        if (styles.width === null) styles.width = Math.round(styles.height * this.size.x / this.size.y);
//        if (styles.height === null) styles.height = Math.round(styles.width * this.size.y / this.size.x);

//        // *** Position in the center of the screen
//        if (this.options.center) {
//            // *** Horizontal
//            if (styles.width > size.x) styles.left = 0 - Math.round((styles.width - size.x) / 2);
//            else if (styles.width < size.x) styles.left = Math.round((size.x - styles.width) / 2);
//            else styles.left = 0;

//            // *** Vertical
//            if (styles.height > size.y) styles.top = 0 - Math.round((styles.height - size.y) / 2);
//            else if (styles.height < size.y) styles.top = Math.round((size.y - styles.height) / 2);
//            else styles.top = 0;
//        }

//        this.image.setStyles(styles);
//        return this;
//    },

//    toElement: function() {
//        return this.image;
//    }

//});




//Needs Mootools - Fades things in and out on hover - Conor L.
window.addEvent('domready', function() {
    var fadeLayers = $$('.fader');
    var fadeLayersFully = $$('.faderFull');
    //Adds all items with the class "fader" to an array
    //Give each item in the array a mouseover and mouseout function to fade them in and out :)
    fadeLayers.addEvents({
        'mouseover': function() {
            this.fade(1);
        },
        'mouseout': function() {
            this.fade(0.1);
        }
    });

    //Give each item in the array a mouseover and mouseout function to fade them in and out :)
    fadeLayersFully.addEvents({
        'mouseover': function() {
            this.fade(0);
        },
        'mouseout': function() {
            this.fade(1);
        }
    });

});



//Needs Mootools - Slides header panel out. Hides it on init - Conor L.
window.addEvent('domready', function() {

    var toggleBox = $$('.toggleBox');
    var toggleLayer = $('layer');
    var toggleBtn = $$('.toggleBtn');
    var toggle = 0;

    toggleBox.setStyle("opacity", "0");

    toggleBox.fade(0);

    toggleBtn.addEvent('click', function(e) {
        e.stop();
        if (toggle == 1) {
            toggleBox.fade(0);
            toggleLayer.fade(1);
            toggle = 0;
            toggleBtn.setStyle('background-position', '-160px 0');
            //toggleBox.setStyle('height', '0');
        }
        else {
            toggleBox.fade(1);
            toggleLayer.fade(0);
            toggle = 1;
            toggleBtn.setStyle('background-position', '-4px 1px');
            //toggleBox.setStyle('height', 'auto');
        }
    });

});

window.addEvent('domready', function () {

    var toggleBox = $$('.toggleBox2');
    //var toggleLayer = $('layer');
    var toggleBtn = $$('.toggleBtn2');
    var toggle = 0;

    toggleBox.setStyle("opacity", "0");

    toggleBox.fade(0);

    toggleBtn.addEvent('click', function (e) {
        e.stop();
        if (toggle == 1) {
            toggleBox.fade(0);
            //toggleLayer.fade(1);
            toggle = 0;
            toggleBtn.setStyle('background-position', '0 0');
            //toggleBox.setStyle('height', '0');
        }
        else {
            toggleBox.fade(1);
            //toggleLayer.fade(0);
            toggle = 1;
            toggleBtn.setStyle('background-position', '0 -30px');
            //toggleBox.setStyle('height', 'auto');
        }
    });

});
