function $type(object){
	var type = typeOf(object);
	if (type == 'elements') return 'array';
	return (type == 'null') ? false : type;
}

function $E(str) {
	return document.getElement(str);
}

function $isArray(obj) {
	return ($type(obj) == 'array' || $type(obj) == 'elements' || $type(obj) == 'collection');
}
function $isNonEmptyArray(obj){
	if ($isArray(obj)) {
		if (obj.length > 0) return true;
	}
	return false;
}
function $isElement(obj) {
	if ($isNonEmptyArray(obj)) {
		return obj.every($isElement);
	} else {
		if ($type(obj) == 'element') return true;
	}
	return false;
}
function $isFunction(obj) {
	if ($type(obj) == 'function') return true;
	else return false;
}
function $chk(obj) {
	if (undefined === obj) return false;
	if (null === obj) return false;
	if (false === obj) return false;
	if (NaN === obj) return false;
	if ("" === obj) return false;
	return true;
}

var Json = JSON;

function $time() {
	return new Date().getTime();
}

var Page = {
	config: {
		'title': 'RPM Software: '
	},
	onDomReady: function() {
		// On DOM load

		// Lightbox
		var box = new CeraBox();
		$$('a.box-vid').each(function (el) {
			box.addItems(el, {
				displayTitle: false,
				displayOverlay: false,
				width: 800,
				height: 617
			});
		});

		// URI
		var uri = new URI(window.location.href);

		// Window title
//		var titleElem = document.getElement('h1');
//		if ($chk(titleElem)) window.parent.document.title = Page.config.title + titleElem.get('text').trim();
		
		// Contact form
		var elForm = $('contact-form');

		if ($isElement(elForm)) {
			new Form.Validator.Inline(elForm, {
				stopOnFailure: true
			});
			var formReq = new Form.Request(elForm, $('formResult'), {
				requestOptions: {
					'spinnerTarget': elForm
				},
				extraData: { // This is just to make this example work.
					'html': 'Form sent.'
				}
			});
			formReq.addEvent('success', function (str) {
				Cookie.write('contact', 'sent', {duration: 365});
				if (uri.parsed.directory == '/demo/') window.location.reload();
				elForm.addClass('hidden');			
				new Element('div', {'class':'msgDone', 'text': 'Thank-you. We will contact you soon.'}).inject(elForm, 'after');
			});
			formReq.addEvent('failure', function (obj) {
				elForm.addClass('hidden');
				new Element('div', {'class':'msgError', 'text':obj.responseText}).inject(elForm, 'after');
			});
		}
		
	}
}

window.addEvent('domready', Page.onDomReady);

