/**
* Javascript used on all pages of the Eland website
*  Lee Caine
**/

$(function() {
	//Tooltips on homepage
	$('div.link[title]').qtip({
		style: {
			name: 'dark',
			tip: 'leftMiddle',
			border: {
				radius: 5,
				color: '#114588'
			},
			background: '#6381bb',
			color: '#ffffff'
		},
		position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			}
		}
	});
	$('.datePicker').datepicker({
		numberOfMonths: 2,
		showButtonPanel: true,
		onClose: function(dateText, inst) {
			var parts = dateText.split("/");
			if(parts.length == 3) {
				window.location.href += "date/" + parts[1] + "/" + parts[0] + "/" + parts[2] + "/";
			}else {
				return;
			}
		}
	});
	$('#eventsSearchBox').submit(function() {
		var query = $('#q').val();
		query = query.replace(/ /g, "_");
		window.location.href = "http://" + document.domain + "/events/search/" + query + "/";
		return false;
	});
	$('#productsSearchBox').submit(function() {
		var query = $('#q').val();
		query = query.replace(/ /g, "_");
		window.location.href = "http://" + document.domain + "/shop/search/" + query + "/";
		return false;
	});
	$('#cmsSearchBox').submit(function() {
		var query = $('#q').val();
		query = query.replace(/ /g, "_");
		window.location.href = "http://" + document.domain + "/equestrian/search/" + query + "/";
		return false;
	});
	$('#productsSearchBox').submit(function() {
		var query = $('#q').val();
		query = query.replace(/ /g, "_");
		window.location.href = "http://" + document.domain + "/shop/search/" + query + "/";
		return false;
	});
	//Rollovers on left image menu(homepage)
	$('#centre_img').mouseover(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/centre_btn_over.png');
	}).mouseout(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/centre_btn.png');
	});
	
	$('#shop_img').mouseover(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/shop_btn_over.png');
	}).mouseout(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/shop_btn.png');
	});
	
	$('#event_img').mouseover(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/events_btn_over.png');
	}).mouseout(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/events_btn.png');
	});
	
	$('#top_event_img').mouseover(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/events_top_over.png');
	}).mouseout(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/events_top.png');
	});
	
	$('#top_shop_img').mouseover(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/shop_top_over.png');
	}).mouseout(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/shop_top.png');
	});
	
	$('#top_centre_img').mouseover(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/centre_top_over.png');
	}).mouseout(function() {
		$(this).children('img').attr('src', '/media/new_menu_images/centre_top.png');
	});
});

