// JavaScript Document
var Neff = {

        InputFocus: new Class({
                text: null,
                input: null,
                initialize: function (elm) {
                        this.input = $(elm);

                        if (this.input == null || this.input == undefined) return false;

                        this.text = this.input.value;
                        this.input.addEvent('focus', this.handler_focus.bindWithEvent(this));
                        this.input.addEvent('blur', this.handler_blur.bindWithEvent(this));
                },
                handler_focus: function (e) {
                        if (this.input.value == this.text) this.input.value = "";
                },
                handler_blur: function (e) {
                        if (this.input.value == "") this.input.value = this.text;
                }
        }),

        ExternalLinks: new Class({
                initialize: function () {
                        $$('a').each( function (item) {
                                if (item.getProperty('rel') == "external") item.setProperty('target', '_blank');
                        });
                }
        }),

		SelectForm: new Class({
			select: null,
			initialize: function (form) {
            	var submit;
            
            	form = $(form);
            	if (!form) return;
            
            	this.select = form.getElement('select');
				if (!this.select) return;
	
				this.select.addEvent("change", this.onChange.bind(this))
			},
			getURL: function (href, target) {
				
			},
			onChange: function (e) {
				var href;
				
				if (this.select.selectedIndex != 0) {
					href = this.select.options[this.select.selectedIndex].value;
					window.location = href;
					this.select.selectedIndex = 0;
				}
				
				e.stop();
				return false;
			}
        }),

	Pages: new Class({
		initialize: function () {
			this.global();
			$(document.body).getProperty('class').split().each( function (item) {
				if (this[item]) this[item]();
			}.bind(this));
        },

        global: function () {
			new Neff.ExternalLinks();
			swfobject.embedSWF("/flash/neff_website_flashmap.swf", "embed", "341", "253", "9.0.0", "/flash/expressInstall.swf", null, {menu: "false", wmode: "transparent", bgcolor: "204882"});
			new Neff.InputFocus('mansearch');
			new Neff.SelectForm('form_location');							
        },

		home: function () {
			
        },
        
        products: function () {
        	new Neff.AjaxSelectForm('productfilter');
        },
        
        info: function () {        	        
        	$('productdemo').addEvent('click', function (event) {
        		$('demoproducts').set('disabled', !event.target.get('checked'));
        		if (event.target.get('checked')) {
        			$('demoproducts').focus();
        		}        		
        	});
        	$('demoproducts').addEvent('focus', function (event) {
        		$('productdemo').set('checked', 'checked');
        	});
        	$('demoproducts').addEvent('blur', function (event) {
        		if (event.target.get('value') == '') {
        			$('productdemo').set('checked', false);
        			$('demoproducts').set('disabled', true);
        		}
        	});
        }
    })
}

Neff.AjaxSelectForm = new Class({
	Extends: Neff.SelectForm,
	initialize: function (form) {
		this.parent(form);
	},
	onChange: function (e) {
		this.update();
		
		e.stop();
		return false;
	},
	update: function (url) {
		var url = url;
		
		var complete = function () {
			$('productlogos').set('tween', {onComplete: null});
			this.sendRequest(url);
		};
		
		$('productlogos').set('tween', {onComplete: complete.bindWithEvent(this)});
		$('productlogos').fade('out');		
	},
	sendRequest: function () {
		href = this.select.options[this.select.selectedIndex].value;
		var myHTMLRequest = new Request.HTML({onComplete: this.hightlight.bindWithEvent(this), update: 'productlogos'}).get(href);
	},
	hightlight: function () {
		$('productlogos').fade('in');
	}
});

window.addEvent('domready', function(){
        new Neff.Pages();
});
