// JavaScript Document

Event.observe(window,'load',function(){ initPage(); });

var imgs = new Array ();
function initPage() {

	// ie6 hacks
	if (typeof ie6hack == 'function') ie6hack();

	initTooltips();

	//preload images
	imgs = new Array ();
	$$("img").each(function(img){
		i = new Image();
		i.src = img.src;
		imgs.push(i);
	});

	Lightbox.initialize({strings: lbStrings, loop: false, autoPlay: false});

}

function initTooltips() {
    //convert titles to tooltips
	$$("a, img, span, input, textarea, th").findAll(function(node){
        return node.getAttribute('title');
    }).each(function(node){
        new Tooltip(node,node.title);
        //node.removeAttribute("title");
    });
}

function validate(form) {
	i = form.fullname;
	if (!i.value.strip() || isDefault(i) && !getCookie('fullname')) {
		alertInput(i);
		return false;
	}
	if ((i = form.phone_number) && !validateInput(i)) {
		alertInput(i);
		return false;
	}
	i = form.email;
	if (!i.value.strip() || isDefault(i) && !getCookie('email')) {
		alertInput(i);
		return false;
	}

	if ((i = form.adult) && isDefault(i)) {
		i.value = '';
	}
	if ((i = form.child) && isDefault(i)) {
		i.value = '';
	}
	if ((i = form.date) && isDefault(i)) {
		i.value = '';
	}
	if ((i = form.time) && isDefault(i)) {
		i.value = '';
	}

	if ((i = form.subject) && isDefault(i)) {
		i.value = '';
	}
	if ((i = form.city) && isDefault(i)) {
		i.value = '';
	}
	if ((i = form.notes) && isDefault(i)) {
		i.value = '';
	}

	if ((i = form.year_of_birth) && isDefault(i)) {
		i.value = '';
	}
	if ((i = form.illness) && isDefault(i)) {
		i.value = '';
	}

	if ((i = form.message) && !validateInput(i)) {
		alertInput(i);
		return false;
	}
	return true;
}

function alertInput(input) {
	new Effect.Shake(input,{distance:5});
	delaySelect(input);
}

function validateInput(input) {
	return input.value.strip() && !isDefault(input);
}

function isDefault(input) {
	return !postError && input.value.strip().toLowerCase() == input.defaultValue.strip().toLowerCase();
}

var ii;
function delaySelect(input) {
	ii = input;
	setTimeout('ii.focus();', 600);
	setTimeout('ii.select();', 600);
}

function galleryPrev() {
	new Effect.ScrollVertical('thumbs', {to: -140});
}
function galleryNext() {
	new Effect.ScrollVertical('thumbs', {to: 140});
}


Effect.ScrollVertical = Class.create();
Object.extend(Object.extend(Effect.ScrollVertical.prototype, Effect.Base.prototype), 
{
    initialize: function(element) 
    {
        if(typeof element == "string")
        {       
            this.element = $(element);
            if(!this.element) 
            {
                throw(Effect._elementDoesNotExistError);
            }
        }
        
        var options = Object.extend({
            from: this.element.scrollTop || 0,
            to:   this.element.scrollHeight
        }, arguments[1] || {});
        
        options.to = options.to == this.element.scrollHeight ? options.to : options.from + options.to;
        
        this.start(options);
    },
    
    update: function(position) 
    {
        this.element.scrollTop = position;
    }
});


