(function($) {

	// onload hook
	$(function() {

		// input fields toggle default values
		$("input.js-default").focus(function() {
			if (this.value == this.defaultValue) {
				this.value = '';
			}
		}).blur(function() {
			if (this.value == '') {
				this.value = this.defaultValue;
			}
		}).closest('form').submit(function() {
			$(this).find('input.js-default').each(function(){
				// Attention!
				if (this.value == this.defaultValue) {
					this.value = '';
				}
			});
		});

		// auto-submit for select boxes that have the class "js-autosubmit"
		$('select.js-autosubmit').change(function() {
			$(this).closest('form').submit();
		});

		// external links (rel="external")
		$('a[rel~="external"]').attr('target', '_blank');

		// sets the focus for the first input field having the class "js-focus"
		$('input.js-focus:eq(0)').focus();

	});




	//---------------------------------------------------------------------------
	// TODO: check things below this line
	//---------------------------------------------------------------------------

	$.fn.hoverClass = function(c) {
		return this.each(function(){
			$(this).hover(
				function() { $(this).addClass(c);  },
				function() { $(this).removeClass(c); }
			);
		});
	};

	function popup(URL, width, height) {
		if (!width) {
			width = 600;
		}
		if (!height) {
			height = 600;
		}
		window.open(URL,'','scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=yes,left='+((screen.width-width) / 2)+',top='+((screen.height-height) / 2)+',width=' + width + ',height=' + height);
		return false;
	}

})(jQuery);


