// global custom javascript functions

// onload event (jQuery method)
$(document).ready(function(){
	
	// apply ie png fix to elements with a class of transpng
	$('.transpng').ifixpng(); 


	// search box behavior
	$('#srch_q').click(function(){
		if($(this).val()=='Search');
		$(this).val('');
	});

	$('#srch_q').blur(function(){
		if($(this).val()==''){
			$(this).val('Search');
		}
	});


	
	// autocomplete search
	function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}
	$("#srch_q").autocomplete("/shop/scripts/ajaxSearch.php", {
		width: 180,
		selectFirst: false
	});
	$("#srch_q").result(function(event, data, formatted) {
		if (data)
			$(this).parent().next().find("input").val(data[1]);
	});
	
	
	// price slider
	//$('select#fromprice, select#toprice').accessibleUISlider({width: 300});
	
	// hide price slider labels - do it here for accessibility
	$('#priceslidercontainer label').css('border','1px solid red !important');
	
	// table striping
	$('.striped tr:even').addClass('altrow');
	
	
	// rollovers
	// preload rollover images
	$('.rollover').children('img').each(function() {
		rollsrc = $(this).attr('src');
		rollON = rollsrc.replace(/(.*)\.(jpg|gif|png)$/i, '$1_over.$2');
		$('<img>').attr('src', rollON);
	});

	// check for rollover
	$('.rollover').mouseover(function(){
		var imgsrc=$(this).children('img').attr('src');
		matches = imgsrc.match(/_over/);

		// don't do the rollover if state is already ON
		if (!matches) {
			var imgsrcOn = imgsrc.replace(/(.*)\.(jpg|gif|png)$/i, '$1_over.$2');
			$(this).children('img').attr('src', imgsrcOn);
			
			$('.rollover').mouseout(function(){
				$(this).children('img').attr('src', imgsrc);
			});
		}
	});
		
		
	// product thumbnail/image swapping
	$('.imglink').click(function(){
		$('.productImage').attr('src',$(this).attr('href'));
		return false;
	});
	
});
