// *************************** jQuery Initialisation **************************** //

$(document).ready(function() {

	if ( typeof(menu) !== "undefined") {
		// 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');
		} );
	}

	// mouse over images
	$('#priNav .menu img').imghover();
	$('a.mailto img').imghover();
	$('.btnView').imghover();

	// mailto obsfucation
	$('a.mailto').mailtoObsfucator();

	// mailto obsfucation
	$('#marginContactForm input:text, #marginContactForm textarea').defaultRestore();

	// product zoom icon needs to trigger the lightbox
	$('#zoomIcon').click(function(){
		$('#mainPic').trigger('click');
	});

});


