$( function() {
	$('#leftlinks .mhead_img img').load( function() {
		rszLeft();
	});
	$('.gal_small').mouseover( function() {
		$(this).stop();
		var t = $(this).find('.caption')[0].innerHTML;
		var s = $(this).find('img').attr("src");
		var c = $(this).parent().parent().parent().attr('id');
		$('#' + c + ' .gal_big img').attr("src", s);
		var x = $('#' + c + ' .gal_big').find('.caption')[0];
		x.innerHTML = t;
	})

	function rszLeft() {
		var ph = $('#box').height();
		if (ph < 780) {
			ph = 800;
		}
		$('#leftlinks').css("height", ph);
		$('.foot_left').css("position", "absolute");
		$('.foot_left').css("bottom", "0");
	}

	showMessage(message);
});
var foc = null;
var OSX = {
	container : null,
	open : function(d) {
		var self = this;
		self.container = d.container[0];
		d.overlay.fadeIn('slow', function() {
			$("#osx-modal-content", self.container).show();
			var title = $("#osx-modal-title", self.container);
			title.show();
			d.container.slideDown('slow', function() {
				setTimeout( function() {
					var h = $("#osx-modal-data", self.container).height()
							+ title.height() + 20; // padding
						d.container.animate( {
							height : h
						}, 200, function() {
							$("div.close", self.container).show();
							$("#osx-modal-data", self.container).show();
						});
					}, 300);
			});
		})
	},
	close : function(d) {
		var self = this;
		d.container.animate( {
			top : "-" + (d.container.height() + 20)
		}, 500, function() {
			self.close(); // or $.modal.close();
				if (foc != null) {
					foc.focus();
				}
			});
	}
};
function showMessage(message, focComp) {
	if (message.length > 0) {
		foc = focComp
		$('#msgp').html(message);
		$("#osx-modal-content")
				.modal(
						{
							overlayId : 'osx-overlay',
							containerId : 'osx-container',
							closeHTML : '<div class="close"><a href="#" class="simplemodal-close">x</a></div>',
							minHeight : 80,
							opacity : 65,
							position : [ '0' ],
							overlayClose : true,
							onOpen : OSX.open,
							onClose : OSX.close
						});
	}
}
function checkForm() {
	var toValidate = $(".fvalidate");
	for ( var i = 0; i < toValidate.length; i++) {
		var f = toValidate[i];
		var name = f.name;
		var value = f.value;
		var ed = $("#c" + name);
		var niceName = ed.closest("td").prev("td")[0].innerText;
		if (value.trim().length == 0) {
			showMessage('Please enter a value for ' + niceName, ed);
			return false;
		}

		if (name.indexOf('email') > -1
				&& (value.indexOf("@") == -1 || value.indexOf(".") == -1)) {
			showMessage('Please enter a valid value for ' + niceName, ed);
			return false;
		}

		if (name.indexOf('phone') > -1 || name.indexOf('mobile') > -1) {
			var ok = value.length > 7;
			if (ok) {
				for ( var i = 0; i < value.length; i++) {
					if ((value.charAt(i) >= 'a' && value.charAt(i) <= 'z')
							|| (value.charAt(i) >= 'A' && value.charAt(i) <= 'Z')) {
						ok = false;
						break;
					}
				}
			}
			if (!ok) {
				showMessage('Please enter a valid value for ' + niceName, ed);

				return false;
			}
		}
	}
	return true;
}

