var NavigationItem = new Class({

    options: {
        active: false
    },

    initialize: function(eTopMenuItem) {
        this.eTopMenuItem = eTopMenuItem;


        this.eLinkImgNormal = this.eTopMenuItem.getElement('DIV.link_img_normal');
        this.eLinkImgOver = this.eTopMenuItem.getElement('DIV.link_img_over');


        this.buttonLinkImgNormal = this.eLinkImgNormal.getElement('A');

        if($defined(this.buttonLinkImgNormal)) {
            this.buttonLinkImgNormal.addEvent('mouseover', this.eventMouseOver.bind(this));
            this.buttonLinkImgNormal.addEvent('mouseout', this.eventMouseOut.bind(this));
        }

        this.buttonLinkImgOver = this.eLinkImgOver.getElement('A');

        if($defined(this.buttonLinkImgOver)) {
            this.buttonLinkImgOver.addEvent('mouseover', this.eventMouseOver.bind(this));
            this.buttonLinkImgOver.addEvent('mouseout', this.eventMouseOut.bind(this));
        }


        if(this.eTopMenuItem.get('class').contains('active')) {
            this.eventMouseOver();

            this.options.active = true;
        }
    },

    eventMouseOver: function() {
        if(!this.options.active) {
            this.eLinkImgNormal.setStyle('display', 'none');
            this.eLinkImgOver.setStyle('display', 'block');
        }
    },

    eventMouseOut: function() {
        if(!this.options.active) {
            this.eLinkImgNormal.setStyle('display', 'block');
            this.eLinkImgOver.setStyle('display', 'none');
        }
    }
	
});

var Gallery = new Class({
    
    options: {
        active: 0
    },
    
    initialize: function(element) {
        this.eGallery = element;

        this.eNavigation = this.eGallery.getElement('DIV.gallery_navigation');
        this.eNavigationPrevious = this.eNavigation.getElement('DIV.previous');
        this.eNavigationNext = this.eNavigation.getElement('DIV.next');
        this.eImages = this.eGallery.getElement('DIV.gallery_images');

        this.eNavigationPrevious.addEvent('click', this.eventShowPrevious.bind(this));
        this.eNavigationNext.addEvent('click', this.eventShowNext.bind(this));

        this.eNavigationPrevious.addEvent('mouseout', function() {
            $('gallery_navigation_previous').removeClass('previous_hover');
        });
        this.eNavigationPrevious.addEvent('mouseover', function() {
            if(!$('gallery_navigation_previous').hasClass('disabled'))
                $('gallery_navigation_previous').addClass('previous_hover');
        });
        this.eNavigationNext.addEvent('mouseout', function() {
            $('gallery_navigation_next').removeClass('next_hover');
        });
        this.eNavigationNext.addEvent('mouseover', function() {
            if(!$('gallery_navigation_next').hasClass('disabled'))
                $('gallery_navigation_next').addClass('next_hover');
        });


        this.aImages = new Array();

        var tImages = this.eImages.getElements('DIV.gallery_image');
        for(var i=0; i<tImages.length; i++) {
            this.aImages[i] = tImages[i];
        }

        var tAnimations = this.eImages.getElements('DIV.gallery_animation');
        for(var i=0; i<tAnimations.length; i++) {
            this.aImages[i] = tAnimations[i];
        }

        if(this.aImages.length<=1) {
            this.eNavigation.setStyle('display', 'none');
        }

        this.eventHideImages();
        this.eventShowImage(0);
    },
    
    eventShowPrevious: function() {
        if((this.options.active-1)>=0) {
            this.eventHideImages();
            this.eventShowImage(this.options.active-1);
        }
    },
    
    eventShowNext: function() {
        if((this.options.active+1)<this.aImages.length) {
            this.eventHideImages();
            this.eventShowImage(this.options.active+1);
        }
    },
	
    eventShowImage: function(index) {
        this.options.active = index;

        if(this.aImages[this.options.active]) {
            this.aImages[this.options.active].setStyle('display', 'block');

            var tImage = this.aImages[this.options.active].getElement('IMG');
            var tCode = this.aImages[this.options.active].getElement('DIV.gallery_animation_code');
            var tDescription = false;

            if(tImage) {
                tDescription = this.aImages[this.options.active].getElement('DIV.gallery_image_description');
                if(tDescription) {
                    var tImageSize = tImage.getSize();

                    tDescription.setStyle('top', tImageSize.y + 50 + 'px');
                    tDescription.setStyle('left', 0 + 'px');
                }
                
            }

            if(tCode) {
                tDescription = this.aImages[this.options.active].getElement('DIV.gallery_animation_description');
                if(tDescription) {
                    var tCodeSize = tCode.getSize();

                    tDescription.setStyle('top', tCodeSize.y + 50 + 'px');
                    tDescription.setStyle('left', 0 + 'px');
                }
            }
        }

		
        if(this.options.active==0) {
            $('gallery_navigation_previous').addClass('disabled');
            $('gallery_navigation_previous').removeClass('previous_hover');
        } else {
            $('gallery_navigation_previous').removeClass('disabled');
        }

        if(this.options.active==this.aImages.length-1) {
            $('gallery_navigation_next').addClass('disabled');
            $('gallery_navigation_next').removeClass('next_hover');
        } else {
            $('gallery_navigation_next').removeClass('disabled');
        }

    },
	
    eventHideImages: function(index) {
        for(var i=0; i<this.aImages.length; i++) {
            this.aImages[i].setStyle('display', 'none');
        }
    }
	
});

var InputTextHideValue = new Class({

    options: {
        value: ''
    },

    initialize: function(eInputText) {
        this.eInputText = eInputText;
		this.options.value = this.eInputText.value;
		
        this.eInputText.addEvent('focus', this.eventFocus.bind(this));
		this.eInputText.addEvent('blur', this.eventBlur.bind(this));
    },

    eventFocus: function() {
        this.eInputText.value = '';
    },
	
	eventBlur: function() {
        if(this.eInputText.value == '') {
			this.eInputText.value = this.options.value;
		}
    }
	
});

window.addEvent('load', function() {

    var galleries = $$('DIV.gallery');
    galleries.each(function(element, index) {
        var tGallery = new Gallery(element);
    });


    var navigationmainitems = $$('DIV.navigation_main UL.items LI.item');
    navigationmainitems.each(function(element, index) {
        var tNavigationItem = new NavigationItem(element);
    });


    var subnavigationitems = $$('DIV.navigation_sub UL.subitems LI.subitem');
    subnavigationitems.each(function(element, index) {
        var tNavigationItem = new NavigationItem(element);
    });


    var navigationnewsletteritems = $$('DIV.navigation_newsletter UL.items LI.item');
    navigationnewsletteritems.each(function(element, index) {
        var tNavigationItem = new NavigationItem(element);
    });

    var navigationlangitems = $$('DIV.navigation_lang UL.items LI.item');
    navigationlangitems.each(function(element, index) {
        var tNavigationItem = new NavigationItem(element);
    });
	
	var inputtextitems = $$('DIV.newsletter_form INPUT.textfield');
    inputtextitems.each(function(element, index) {
        var tInputTextHideValue = new InputTextHideValue(element);
    });
	
});
