$(document).ready(function(){
	//IE6 hover
	if(getInternetExplorerVersion() > 0 && getInternetExplorerVersion() <= 6){
		$(".mod-menu li").hover( function(){
			$(this).addClass("over");
		}, function(){
			$(this).removeClass("over");
		});
	}

	$(".mod-menu .lev-2-wrapper").hide();
	var menu_lev2_width = null;
	var menu_lev3_width = null;
	var lev_2_wrapper_opened = null;
	var lev_3_wrapper_opened = null;
	var lev_4_wrapper_opened = null;

	$(".mod-menu li.lev-1-parent").hover(
		function(){
			if(lev_2_wrapper_opened){
				lev_2_wrapper_opened.slideUp();
			}
			lev_2_wrapper_opened = $(this).children(".lev-2-wrapper");
			lev_2_wrapper_opened.slideDown().addClass("lev-2-wrapper-opened");
		},

		function(){
			lev_2_wrapper_opened.stop(true, true).slideUp();
		}
		);

	$(".mod-menu li.lev-2-parent").hover(

		function(){
			if(!menu_lev2_width){
				menu_lev2_width = $(this).children(".lev-3-wrapper").width();
			}
			if(getInternetExplorerVersion() > 0){
				menu_lev2_width = 190;
			}

			if(lev_3_wrapper_opened){
				lev_3_wrapper_opened.children(".round-box").stop();
				lev_3_wrapper_opened.children(".round-box").animate({
					marginLeft: -menu_lev2_width,
					"opacity":0
				}, 300, "linear", function(){
					$(this).parent().removeClass("lev-3-wrapper-opened");
				});
			}

			lev_3_wrapper_opened = $(this).children(".lev-3-wrapper");
			lev_3_wrapper_opened.css({
				"overflow":"hidden"
			});
			lev_3_wrapper_opened.children(".round-box").stop();
			lev_3_wrapper_opened.children(".round-box").css({
				"display":"block",
				marginLeft: -menu_lev2_width,
				"width":menu_lev2_width,
				opacity: 0
			}).animate({
				marginLeft: 1,
				"opacity":1
			}, 300, 'linear', function(){
				$(this).parent().removeClass("lev-3-wrapper-opened");
			});
			lev_3_wrapper_opened.addClass("lev-3-wrapper-opened");

			var imgObj = $('a.lev-3-image', lev_3_wrapper_opened);

			if(imgObj.size()) {
				var html = imgObj.html();

				if($.trim(html)) {
					var data = html.match(/(.*)\|(.*)/);

					if(data) {
						if(/&amp;/.test(data[1])) data[1] = data[1].replace(/&amp;/gi, '&');
						var img = $('<img>').attr({
							src : $.trim(data[1]),
							title : $.trim(data[2]),
							alt : $.trim(data[2])
						});
						imgObj.html('').append(img);
					}
				}
			}
		},

		function(){
			lev_3_wrapper_opened.children(".round-box").stop();
			lev_3_wrapper_opened.children(".round-box").css({
				marginLeft: -menu_lev2_width,
				"opacity":0
			});
			lev_3_wrapper_opened.children(".round-box").parent().removeClass("lev-3-wrapper-opened");
		}
		);

	$(".mod-menu li.lev-3-parent").hover(

		function(){
			$(this).parents(".lev-3-wrapper").css({
				"overflow":"visible"
			});
			if(!menu_lev3_width){
				menu_lev3_width = $(this).children(".lev-4-wrapper").width();
			}

			if(lev_4_wrapper_opened){
				lev_4_wrapper_opened.children(".round-box").animate({
					marginLeft: -menu_lev3_width,
					"opacity":0
				}, 300, "linear", function(){
					$(this).parent().removeClass("lev-4-wrapper-opened");
				});

			}

			lev_4_wrapper_opened = $(this).children(".lev-4-wrapper");
			lev_4_wrapper_opened.css({
				"overflow":"hidden"
			});
			lev_4_wrapper_opened.children(".round-box").css({
				"display":"block",
				marginLeft: -menu_lev3_width,
				"width":menu_lev3_width,
				opacity: 0
			}).animate({
				marginLeft: 1,
				"opacity":1
			}, 300);
			lev_4_wrapper_opened.addClass("lev-4-wrapper-opened");

			var imgObj = $('a.lev-4-image', lev_4_wrapper_opened);

			if(imgObj.size()) {
				var html = imgObj.html();

				if($.trim(html)) {
					var data = html.match(/(.*)\|(.*)/);

					if(data) {
						if(/&amp;/.test(data[1])) data[1] = data[1].replace(/&amp;/gi, '&');
						var img = $('<img>').attr({
							src : $.trim(data[1]),
							title : $.trim(data[2]),
							alt : $.trim(data[2])
						});
						imgObj.html('').append(img);
					}
				}
			}

		},

		function(){
			lev_4_wrapper_opened.children(".round-box").animate({
				marginLeft: -menu_lev3_width,
				"opacity":0
			}, 300, "linear", function(){
				$(this).parent().removeClass("lev-4-wrapper-opened");
			});
		}
		);
});
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).

{
	var rv = -1; // Return value assumes failure.
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat( RegExp.$1 );
	}

	return rv;
}
