/////////////////////////////////////////////////////////////////////////////
var UI = {};
UI.jq = jQuery;
UI.util = {};

/////////////////////////////////////////////////////////////////////////////
(function(UI) {	
	var jq = UI.jq;
	
	UI.toggle = function(element, howFast) {
		var speed;
		if(!howFast) { 
			speed = "normal"; 
		} else {
			speed = howFast;
		}
		try {
			jq(element).slideToggle(speed);
		} catch(error) {
			//TODO
		}
	};
	
	UI.makeHighlightable = function(element, themeClass) {
		var hiClass;
		if (!themeClass) { 
			hiClass = 'highlighted';
		} else {
			hiClass = themeClass;
		}
		jq(element).mouseover(function() {
			jq(this).addClass(hiClass);
		}).mouseout(function() {
			jq(this).removeClass(hiClass);
		});		
	};
	
	UI.makeInputClearOnFocus = function(element) {
		jq(element).bind('focus', function() {
			var stored_val = jq(this).val();
			jq(this).val("");
			jq(this).bind('blur', function() {
				if(jq(this).val() === ""){
					jq(this).val(stored_val);
				} else {
					stored_val = jq(this).val();
				}
			});	
		});	
	};
	
	UI.bindFormSubmit = function(element){
		jq(element+' .s-btn-wrap').bind('click', function() {
			jq(this).parent().get(0).submit();
		});
	};
	
	UI.makeVerticalScroller = function(lPath, scrollSpeed) {
				
		var speed;
		if (!scrollSpeed) {
			speed = 400;
		} else {
			speed = scrollSpeed;
		}
		
		jq('a[href*=#]').each(function($) {
			var thisPath = UI.util.filterPath(this.pathname) || lPath;
			if ( lPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'') ) { 
				var $target = jq(this.hash), target = this.hash;
				if (target) {
					var targetOffset = $target.offset().top; 
					jq(this).click(function(event) { 
						event.preventDefault(); 
						jq('html, body').animate({scrollTop: targetOffset}, speed, function() { 
							location.hash = target; 
						});
					});
				}
			}
		});
	};
	
	UI.util.filterPath = function(string) {
		return string.replace(/^\//,'').replace(/(index|default).[a-zA-Z]{3,4}$/,'').replace(/\/$/,'');
	};
	
})(UI);

/////////////////////////////////////////////////////////////////////////////
jQuery(document).ready(function($) {
	
});
