// on dom ready stuff
$(function() {
	// regenerate captcha on click
	$('.captcha').click(function() {
		var img = $(this);
		img.attr('src', img.attr('src').replace(/\?.*/, '') + '?' + (new Date()));
		return false;
	});
	
	// preload
	$.preload(
		'/images/ajax_loader.gif',
		'/images/contact_potm_tooltip_top.png',
		'/images/contact_potm_tooltip_bttm.png',
		'/images/contact_potm_tooltip_bg.png'
	);
	
	// bind custom selects
	$('.custom-select').customSelect();
});

// input with default value if empty
$.fn.inputWithDefault = function() {
	this.each(function() {
		var input = $(this);
		if (input.val() == input.attr('title'))
			input.addClass('def');
	});
	
	this
		.focus(function() {
			var input = $(this);
			if (input.val() == input.attr('title'))
				input.val('').removeClass('def');
		})
		.blur(function() {
			var input = $(this);
			if (!input.val())
				input.addClass('def').val(input.attr('title'));
		});
	
	return this;
};

// input with default value if empty
$.preload = function() {
	if (!arguments.length)
		return;
		
	var img;
	for (var i = 0; i < arguments.length; i++) {
		img = $('<img>').css('display', 'none').appendTo($(document.body)).attr('src', arguments[i]);
		if (img.complete)
			img.remove();
		else
			img.load(function() { $(this).remove(); });
	}
};

//
function addBookmark(obj, title) {
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, $(obj).attr('href'), '');
	else if (window.opera && window.print) { // opera
		$(obj).attr('title', title).animate({ opacity: 1 }, function() { $(this).attr('title', 'Bookmark this page'); });
		return true;
	}
	else if(document.all)// ie
		window.external.AddFavorite($(obj).attr('href'), title);
	return false;
}


