// JavaScript Document
$(document).ready(function(){
	$("a.popup").click(function(){
		window.open($(this).attr('href'), 'popup', $(this).attr('rel'));

		return false;
	});

	$(".colorbox,[rel='colorbox']").colorbox();

	$(".price").each(function(){
		var text = $(this).text();
		price = text.split('.');
		$(this).html(price[0] + '<span class="pence">.' + price[1] + '</span>');
	});

	$("input.buyButton").hover(
		function(){
			$(this).attr('src', '/images/buy_button_over.gif');
		},
		function(){
			$(this).attr('src', '/images/buy_button.gif');
		}
	);

	$("img#printBasketButton").hover(
		function(){
			$(this).attr('src', '/images/basket_print_over.gif');
		},
		function(){
			$(this).attr('src', '/images/basket_print.gif');
		}
	);

	var defaultSearchText = 'enter keywords...';

	$("#quickSearchInput").bind('focus', function(){
		if ($(this).val() == defaultSearchText) {
			$(this).addClass('searchActive').val('');
		}
	});

	$("#quickSearchInput").bind('blur', function(){
		if ($(this).val() == '') {
			$(this).removeClass('searchActive').val(defaultSearchText);
		}
	});

	if ($("#quickSearchInput").val() != defaultSearchText) {
		$("#quickSearchInput").addClass('searchActive');
	}

	$("#contactForm input[name='callback']").click(function(){
		if ($("#contactForm input[name='callback']").is(':checked')) {
			$("select[name='timeToCall']").slideDown('fast');
		}
		else {
			$("select[name='timeToCall']").slideUp('fast');
		}
	});

	if ($("#contactForm input[name='callback']").is(':checked')) {
		$("select[name='timeToCall']").show();
	}
	else {
		$("select[name='timeToCall']").hide();
	}

	$("#contactForm").bind('submit', function(){
		if ($("#contactForm input[name='phone']").val() == '' && $("#contactForm input[name='callback']").is(':checked')) {
			alert('Please enter a telephone number for us to call you back');
			$("input[name='phone']").focus();

			return false;
		}
	});
})

