$(document).ready(function(){
	$('#colorpickerSearch').ColorPicker({
		flat: true,
		color: $('#colorpickerValue').val(),
		onChange: function(hsb, hex, rgb, el) {
			$('#colorpickerPreview').css('background-color','#'+hex).css('background-image','none');
			$('#red').val(rgb.r);
			$('#green').val(rgb.g);
			$('#blue').val(rgb.b);
			$('#colorpickerValue').val(hex);
			$('#colorSearch').attr('checked', true);
		}
	});
	$('#colorpickerPreview').css('background-color','#'+$('#colorpickerValue').val()).css('background-image','none');
	$(".tablesorter").tablesorter({widthFixed: true, widgets: ['zebra']});
	$(".postalCode").keyup(function(event){
		if (this.value.length == 4) {
			$.get('/ajax/postalCode2city.php?pc='+$('.postalCode').val(), function(data){
				$('.city').val(data);
			});
		}
	});
	$(".datepickerFuture").datepicker({ minDate: '+0m +0w +0y' });
    $("#search").autocomplete("/ajax/suggestSearch.php",{
		minChars: 1,
		max: 5,
		matchSubset: true,
		highlight: false,
		offsetLeft: -31,
		offsetTop: -1,
		width: 186,
		scrollHeight: 220,
		extraParams: {
	    	mode: function() { return $('input[@name=mode]:checked').val(); }
	   	},
		formatItem: function(data, i, n, value) {
			return "<div style=\"width:25px;padding:0 0;float:left;\"><img height='20' src='" + value.split("^^")[1] + "'/></div> " + value.split("^^")[0];
		},
		formatResult: function(data, value) {
			return value.split("^^")[0];
		}
	}).result(function(event, data, formatted) {
		if(data) {
			data = data.toString();
			location.href = data.split("^^")[2];
		}
	});
	$(".suggestTags").autocomplete("/ajax/suggestTags.php", {
		mustMatch: false,
		multiple: true,
		autoFill: true,
		offsetLeft: 0,
		offsetTop: -2,
		width: 186,
		scrollHeight: 220,
	});
	$('input:not(.noExample,[type*=file],[title=]),textarea:not(.noExample,[title=])').example(function() {
		return $(this).attr('title'); 
	});
	
});
