var itemPos = new Object;
itemPos.aboutus		= "0 -76px";
itemPos.theteam		= "-210px -76px";
itemPos.ourservices	= "0 -205px";
itemPos.news		= "0 0";
itemPos.portfolio	= "-420px -77px";
itemPos.contactus	= "-608px -77px";
itemPos.empty		= "-794px -441px";


$(document).ready(function() {
	addMenuHoverEffect();
	addHeaderMapFunctionality();
	addFooterMapFunctionality();
});


function addMenuHoverEffect() {
	if ( $("#header ul:first li.sel:first").length ) addMenuBg($("#header ul:first li.sel:first a").get(), 'sel');

	$("h1:first a").hover(
		function() {
			var isSel = $("#header ul:first li:first").hasClass("sel");
			if ( ! isSel ) addMenuBg( $("#header ul:first li.home:first a:first") );
		},
		function() {
			var isSel = $("#header ul:first li:first").hasClass("sel");
			if ( ! isSel ) removeMenuBg( $("#header ul:first li.home:first a:first") );
		}
	);

	$("#header ul:first li a").hover(
		function() {
			var isSel	= $(this).parent().hasClass("sel");
			var cls		= $(this).parent().attr("class").replace(" sel", "");
			var item	= (cls == "about-us" || cls == "the-team") ? "about-us--the-team" : ( (cls == "portfolio" || cls == "contact-us") ? "portfolio--contact-us" : cls );

			$("#header .menu_img ." + item + ":first").css("background-position", itemPos[ cls.replace("-", "") ]);
			$("#header .menu_txt ." + cls + ":first").show();
			if ( ! isSel ) addMenuBg(this);
		},
		function() {
			var isSel	= $(this).parent().hasClass("sel");
			var cls		= $(this).parent().attr("class").replace(" sel", "");
			var item	= (cls == "about-us" || cls == "the-team") ? "about-us--the-team" : ( (cls == "portfolio" || cls == "contact-us") ? "portfolio--contact-us" : cls );

			$("#header .menu_img ." + item + ":first").css("background-position", itemPos['empty']);
			$("#header .menu_txt ." + cls + ":first").hide();
			if ( ! isSel ) removeMenuBg(this);
		}
	);
}


function addMenuBg(linkObj, opt) {
	var $linkObj	= $(linkObj);
	var index		= $linkObj.parent().index();
	var width		= parseInt( $linkObj.parent().width() );
	var left		= parseInt( $linkObj.parent().position().left ) - ( (116 - width) / 2 );// + 5;
	if (opt != "sel") opt = "hover";

	var li = document.createElement('li');
	$(li).css("left", left + "px").addClass("bg-" + opt + " bg" + index);
	$("#header ul:first").append(li);
}


function removeMenuBg(linkObj) {
	var index = $(linkObj).parent().index();

	$("#header ul:first li.bg" + index).remove();
}


function addHeaderMapFunctionality() {
	$("#header-map-about-us--the-team:first area:eq(0)").hover(
		function() {
			$("#header .menu_img .about-us--the-team:first").css("background-position", itemPos['aboutus']);
			$("#header .menu_txt .about-us:first").show();
			addMenuBg( $("#header ul:first li.about-us:not(.sel) a").get() );
		},
		function() {
			$("#header .menu_img .about-us--the-team:first").css("background-position", itemPos['empty']);
			$("#header .menu_txt .about-us:first").hide();
			removeMenuBg( $("#header ul:first li.about-us:not(.sel) a").get() );
		}
	);
	$("#header-map-about-us--the-team:first area:eq(1)").hover(
		function() {
			$("#header .menu_img .about-us--the-team:first").css("background-position", itemPos['theteam']);
			$("#header .menu_txt .the-team:first").show();
			addMenuBg( $("#header ul:first li.the-team:not(.sel) a").get() );
		},
		function() {
			$("#header .menu_img .about-us--the-team:first").css("background-position", itemPos['empty']);
			$("#header .menu_txt .the-team:first").hide();
			removeMenuBg( $("#header ul:first li.the-team:not(.sel) a").get() );
		}
	);
	$("#header-map-our-services:first area:eq(0)").hover(
		function() {
			$("#header .menu_img .our-services:first").css("background-position", itemPos['ourservices']);
			$("#header .menu_txt .our-services:first").show();
			addMenuBg( $("#header ul:first li.our-services:not(.sel) a").get() );
		},
		function() {
			$("#header .menu_img .our-services:first").css("background-position", itemPos['empty']);
			$("#header .menu_txt .our-services:first").hide();
			removeMenuBg( $("#header ul:first li.our-services:not(.sel) a").get() );
		}
	);
	$("#header-map-news:first area:eq(0)").hover(
		function() {
			$("#header .menu_img .news:first").css("background-position", itemPos['news']);
			$("#header .menu_txt .news:first").show();
			addMenuBg( $("#header ul:first li.news:not(.sel) a").get() );
		},
		function() {
			$("#header .menu_img .news:first").css("background-position", itemPos['empty']);
			$("#header .menu_txt .news:first").hide();
			removeMenuBg( $("#header ul:first li.news:not(.sel) a").get() );
		}
	);
	$("#header-map-portfolio--contact-us:first area:eq(0)").hover(
		function() {
			$("#header .menu_img .portfolio--contact-us:first").css("background-position", itemPos['portfolio']);
			$("#header .menu_txt .portfolio:first").show();
			addMenuBg( $("#header ul:first li.portfolio:not(.sel) a").get() );
		},
		function() {
			$("#header .menu_img .portfolio--contact-us:first").css("background-position", itemPos['empty']);
			$("#header .menu_txt .portfolio:first").hide();
			removeMenuBg( $("#header ul:first li.portfolio:not(.sel) a").get() );
		}
	);
	$("#header-map-portfolio--contact-us:first area:eq(1)").hover(
		function() {
			$("#header .menu_img .portfolio--contact-us:first").css("background-position", itemPos['contactus']);
			$("#header .menu_txt .contact-us:first").show();
			addMenuBg( $("#header ul:first li.contact-us:not(.sel) a").get() );
		},
		function() {
			$("#header .menu_img .portfolio--contact-us:first").css("background-position", itemPos['empty']);
			$("#header .menu_txt .contact-us:first").hide();
			removeMenuBg( $("#header ul:first li.contact-us:not(.sel) a").get() );
		}
	);
}



function addFooterMapFunctionality() {
	$("#footer-links-left-map:first area:eq(0)").hover(
		function() { $(".footer-links:first img.green:first").css("background-position", "0 -70px"); },
		function() { $(".footer-links:first img.green:first").css("background-position", "0 0"); }
	);
	$("#footer-links-left-map:first area:eq(1)").hover(
		function() { $(".footer-links:first img.green:first").css("background-position", "0 -140px"); },
		function() { $(".footer-links:first img.green:first").css("background-position", "0 0"); }
	);
	$("#footer-links-left-map:first area:eq(2)").hover(
		function() { $(".footer-links:first img.green:first").css("background-position", "0 -210px"); },
		function() { $(".footer-links:first img.green:first").css("background-position", "0 0"); }
	);
	$("#footer-links-left-map:first area:eq(3)").hover(
		function() { $(".footer-links:first img.green:first").css("background-position", "0 -280px"); },
		function() { $(".footer-links:first img.green:first").css("background-position", "0 0"); }
	);

	$("#footer-links-right-map:first area:eq(0)").hover(
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 -82px"); },
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 0"); }
	);
	$("#footer-links-right-map:first area:eq(1)").hover(
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 -164px"); },
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 0"); }
	);
	$("#footer-links-right-map:first area:eq(2)").hover(
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 -246px"); },
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 0"); }
	);
	$("#footer-links-right-map:first area:eq(3)").hover(
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 -328px"); },
		function() { $(".footer-links:first img.purple:first").css("background-position", "0 0"); }
	);

	$("#footer-websites-map:first area:eq(0)").hover(
		function() { $(".footer-websites:first img:first").css("background-position", "0 -76px"); },
		function() { $(".footer-websites:first img:first").css("background-position", "0 0"); }
	);
	$("#footer-websites-map:first area:eq(1)").hover(
		function() { $(".footer-websites:first img:first").css("background-position", "0 -152px"); },
		function() { $(".footer-websites:first img:first").css("background-position", "0 0"); }
	);
	$("#footer-websites-map:first area:eq(2)").hover(
		function() { $(".footer-websites:first img:first").css("background-position", "0 -228px"); },
		function() { $(".footer-websites:first img:first").css("background-position", "0 0"); }
	);
}
