var pImages = [];
function trim(str) {
	var str = str.replace(/^\s\s*/, ''),
		  ws = /\s/,
		  i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function newImage(src) {
	if (document.images) {
		var rslt = new Image();
		rslt.src = src;
		pImages[src] = rslt;
	}
}

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

function change_input_width(obj, howwide) {
	obj.style.width = howwide;
	return true;
}

jQuery.fn.hint = function() {
	return this.each(function(){
		var t = $(this); // get jQuery version of 'this'
		var title = t.attr('title'); // get it once since it won't change
		
		if (title) { // only apply logic if the element has the attribute
			
			t.focus(function(){
				if (t.val() == title) {
				  t.val('');
				  t.removeClass('blur');
				}
			});
			
			t.blur(function(){
				if (t.val() == '') {
				  t.val(title);
				  t.addClass('blur');
				}
			});
			
			t.parents('form:first').submit(function(){
				if (t.val() == title) {
					t.val('');
					t.removeClass('blur');
				}
			});
			
			t.blur();
		}
	})				
}

function activateMenuItem() {
	if(location.search.search(/searchfor/) > -1 || location.pathname.search(/inventory/) > -1) {
		if(location.search.search(/searchfor=qd/) > -1 || location.pathname.search(/inventory/) > -1) {
			$("#sidebar-left a[href='/new-homes/search/results?searchfor=qd']").addClass("active");
			$("#sidebar-left a[href='/new-homes/search/results/?searchfor=qd']").addClass("active");
			$("#sidebar-left a[href='/new-homes/search/c/quick-delivery-homes']").addClass("active");
			return false;
		}
		return false;
	}
	
	var path = location.pathname;
	var pieces = path.split("index.html");
	for(var x=pieces.length; x>0; x--) {
		if(path.length > 1) {
			if($("#sidebar-left a[href='" + path + "']").length > 0) {
				$("#sidebar-left a[href='" + path + "']").addClass("active");
				return false;
			}
		}
		pieces.pop();
		path = pieces.join("index.html");
	}
	return false;
}

function showSwf(div_id, img_str, swf_width, swf_height, bg_color) {
        var so = new SWFObject("content/common/flash/image_viewer.swf", div_id + "_swf", swf_width, swf_height, "8", bg_color);
        so.addVariable("i", img_str);
        so.addParam("wmode", "transparent");
        so.write(div_id);
}

