// JavaScript Document
var Shelby = {

        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');
                        });
                }
        }),

        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 Shelby.ExternalLinks();
				new Shelby.FormHandler('equipment_form');
            },
            
            home: function () {
            	var flashvars = {
            		paramXMLPath: "/api/params",
            		initialURL: escape(document.location)
            	}
            	var params = { 
            		base: ".",
            		bgcolor: "#171717",
            		allowfullscreen: "false"
            	}                
            	var attributes = {}
            	swfobject.embedSWF("/flash/slideshowpro.swf", "flash", "213", "207", "9.0.0", false, flashvars, params, attributes);
            }
        })
}

Shelby.FormHandler = new Class({
	initialize: function (form) 
	{
		if (! form)
		{
			return;
		}
		this.form = $(form);	
		this.validate = new FormCheck(this.form, {			
			display: {
				scrollToFirst: false,
				showErrors: 0,
				flashTips: 1,
				addClassErrorToField : 1
			}
		});	
	}
})

window.addEvent('domready', function(){
        new Shelby.Pages();
});
