// *************************** jQuery Initialisation **************************** //

$(document).ready(function() {

	$('#priNav a img:not(.current)').imghover();
	$('a.mailto img').imghover();

	$('a.mailto').mailtoObsfucator();

	$('#marginContact :input:not(:submit)').defaultRestore();

	// product page - thumbnail image swap
	$('#productPics .thumbnail img').mouseover(function() {
		$('#productPics .thumbnail').removeClass('highlight');
		var smallSrc = $(this).attr('src');
		var largeSrc = smallSrc.replace('_t', '_m');
		$('#mainPic img').attr('src', largeSrc );
		$(this).parent().parent().addClass('highlight');
	});

	// fake the lightbox click on the main pic - to prevent duplicate entries
	$('#mainPic').click(function(){
		$('#productPics .thumbnail a:eq(' + $('#productPics div.thumbnail').index( $('#productPics div.highlight') ) + ')').trigger('click');
	});


	// add the menus to the DOM
	for(key in menu) {
		var str = '<div class="subMenu">';
		var subMenu = menu[key];
		for(subKey in subMenu) {
			str += '<div><a href="' + subMenu[subKey] + '">' + subKey + '</a></div>';
		}
		str += '</div>';
		$("#" + key).append(str);
	}
	// show and hide the sub-menus on hover 
	$("#priNav .menu").hover( function () {
		$(this).find(".subMenu").show();
		t = $(this).find("img").attr("title"); // hide the images title as was
		$(this).find("img").attr("title", ""); // causing mouseout probs in safari
	}, function () {
		$(this).find(".subMenu").hide();
		$(this).find("img").attr("title", t); // restore the image title
	} );
	// add a hover class - because ie doesn't support 
	// css :hover styles on anything other than an anchor
	$("#priNav .menu .subMenu div").hover( function () {
		$(this).addClass("hover");
	}, function () {
		$(this).removeClass("hover");
	} );
	// trigger the image hover on the parent menu image
	$("#priNav .menu .subMenu").hover( function () {
		$(this).prev("a").find("img").trigger('mouseover');
	}, function () {
		$(this).prev("a").find("img").trigger('mouseout');
	} );



});


