window.addEvent('domready',function() {
								
/* Tooltips */	

var tips = $$('.tooltip');

var tooltips = new Tips(tips, {
	'className': 'tooltipStyle'						
});

tips.each(function(e) {
	e.store('tip:text', e.getElement('img').getProperty('alt'))				   
});

/* E-mail me */
	
var inputHints    = $$('.inputHint');
var inputHintObjs = {};

inputHints.each(function(el) {
	inputHintObjs[el] = new inputHint(el);
	
	el.addEvents({
		'mouseenter': function() {
			el.setStyle('border-color', '#aaa')	
		},
		'mouseleave': function() {
			el.setStyle('border-color', '#ccc')
		}
	});
});

/* enquiry form */

if($('enquiry')) {
	
	var formStatus  = $('enquiry').getElement('fieldset.formStatus');
	var statusLog   = $('enquiry').getElement('span.status');
	
	$('enquiry').addEvent('submit', function(e) {
		var e = new Event(e);
		e.stop();
		
		// form vars
		var formName    = $('enquiry').getElement('input[name=formName]').value;
		var formEmail   = $('enquiry').getElement('input[name=formEmail]').value;
		var formMessage = $('enquiry').getElement('textarea[name=formMessage]').value;
		var formCuddio  = $('enquiry').getElement('input[name=formCuddio]').value;
		var formSend    = $('formSend');
		
		// don't submit anything if default values are still in place
		for(var obj in inputHintObjs) {
			if(inputHintObjs[obj].defaultValue == inputHintObjs[obj].el.value) {
				// update status
				statusLog.innerHTML = 'You have left default values in place';
				statusLog.addClass('error');
				statusLog.highlight('#1dffd2');
				return;
			}
		}
						
		new Request.JSON({
			url: '/enquiry-send.inc.php',
			method: 'post',
			onRequest: function() {
				formStatus.addClass('loading');
				formSend.setProperty('disabled','true');
				formSend.value = 'Please wait...';
				statusLog.removeClass('error');
				statusLog.removeClass('success');
				statusLog.innerHTML = '&nbsp;';
			},
			onSuccess: function(jsonObj) {
				formStatus.removeClass('loading');
				formSend.value = 'Sent';
				var sent = jsonObj.result == true ? 'success' : 'error';
				statusLog.addClass(sent);
				statusLog.innerHTML = jsonObj.message;
				statusLog.highlight('#1dffd2');
				
				if(sent == 'success') {
					var backHome = function() { window.location = '/index.php?message=sent' }	
					
					var countdown = 3;
					
					(function(){
						statusLog.innerHTML = jsonObj.message + ' (' + countdown + ')';
						countdown = countdown > 1 ? countdown - 1 : countdown;
					}).periodical(1000);
					
					backHome.delay(4000);
				}
			},
			onError: function() {
				formStatus.removeClass('loading');
				formSend.removeProperty('disabled');
				formSend.value = 'Send';
				if(!jsonObj.status) statusLog.addClass('error');
				statusLog.innerHTML = 'Error creating HTTP request';
				statusLog.highlight('#1dffd2');
			},
			onCancel: function() {
				formStatus.removeClass('loading');
				formSend.removeProperty('disabled');
				formSend.value = 'Send';
				if(!jsonObj.status) statusLog.addClass('error');
				statusLog.innerHTML = 'Request was cancelled';
				statusLog.highlight('#1dffd2');
			}
		}).send('formName='+formName+'&formEmail='+formEmail+'&formMessage='+formMessage+'&formCuddio='+formCuddio);
	});
}

/* Slideshow */

if($('show')) {
	var myShow = new Slideshow('show', data, { controller: false, thumbnails: false, height: 320, width: 600 });
}

/* Scroller */

function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
var slider = new Slider(scrollbar, handle, {	
	steps: steps,
	mode: (horizontal?'horizontal':'vertical'),
	onChange: function(step){
		// Scrolls the content element in x or y direction.
		var x = (horizontal?step:0);
		var y = (horizontal?0:step);
		content.scrollTo(x,y);
	}
}).set(0);
if( !(ignoreMouse) ){
	// Scroll the content element when the mousewheel is used within the 
	// content or the scrollbar element.
	$$(content, scrollbar).addEvent('mousewheel', function(e){	
		e = new Event(e).stop();
		var step = slider.step - e.wheel * 30;	
		slider.set(step);					
	});
}
// Stops the handle dragging process when the mouse leaves the document body.
$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

if($('scrollbar')) makeScrollbar($('scroll'),$('scrollbar'),$('handle'),false,false);

});