jQuery(function() {
	function hideItem(){
		$("#active").css({ background:"#fff" });
        urlImg = $("#active img").attr("src");
        nameImg = urlImg.substring(urlImg.lastIndexOf("/")+1, urlImg.lastIndexOf("_."));
         active_img = $("#active img").attr("hoveredImg");
                    notactive_img = $("#active img").attr("nothoveredImg");
        $("#active img").attr({"src": notactive_img});
        $("#active").attr({"id": ""});  
    }
    $(".navigation").hover(
        function () {},
        function () {
            if(document.getElementById('active')){
                hideItem();
                $(".secondLevel[name='on']").css({display:"none"}).attr({"name": ""});
				$(".currentItem").css({ background:"#8B1079" });
			}
			$(".curIt").css({ background:"#8B1079" });
			$(".mrpropper").css({display:"block"}).attr({"name": "on"});
			var mmaaiinn = $(".curIt");
			if(document.getElementById("currentItem") || mmaaiinn.length > 0){
				curImg = $(".curIt img").attr("src");
				if(curImg.lastIndexOf("_.")<0){
                                 active_img = $(".curIt img").attr("hoveredImg");
                                 notactive_img = $(".curIt img").attr("nothoveredImg");    
					nameCurImg = curImg.substring(curImg.lastIndexOf("/")+1, curImg.lastIndexOf("."));
					$(".curIt img").attr({"src": active_img});
					$(".curIt").attr({ "id":"currentItem" });
				}
			}
        }
    );
    $(".firstLevel a:not(.curIt)").hover(
		function () {
            //hide
            if(document.getElementById('active')){
                hideItem();
                $(".secondLevel[name='on']").css({display:"none"}).attr({"name": ""});
            }
			$(".mrpropper").css({display:"none"}).attr({"name": ""});
			target = $(this).attr("name");
            //light
            $(this).css({ background:"#8B1079" });
            $(this).attr({"id": "active"});
            urlImg = $("#active img").attr("src");
			nameImg = urlImg.substring(urlImg.lastIndexOf("/")+1, urlImg.lastIndexOf("."));
                    //   path = '/assets/images/1RU/';
                    //ids = $(this).attr("");
                    active_img = $("#active img").attr("hoveredImg");
                    notactive_img = $("#active img").attr("nothoveredImg");
          //  $("#active img").attr({"src": path + nameImg + ".png"});
      // alert(notactive_img);
          $("#active img").attr({"src": active_img});
           // alert( $("#active img").attr("src"));
            $("#" + target).attr({"name": "on"}).css({display:"block"});
			if(document.getElementById('currentItem')){
				$("#currentItem").css({ background:"#fff" });
				curImg = $("#currentItem img").attr("src");
				nameCurImg = curImg.substring(curImg.lastIndexOf("/")+1, curImg.lastIndexOf("_."));
				//$("#currentItem img").attr({"src": path + nameCurImg + ".png"});
                                $("#currentItem img").attr({"src": active_img});
				$("#currentItem").attr({"id": ""});
			}
        }, 
     	function () {
            target = $(this).attr("name");
            if(target == "null"){
                hideItem();
				$(this).css({ background:"#FFFFFF" });
            }
        }	
	);
	$(".firstLevel a.curIt").hover(
		function(){
			if(document.getElementById('active')){
                hideItem();
                $(".secondLevel[name='on']").css({display:"none"}).attr({"name": ""});
            }
			target = $(this).attr("name");
			$(this).css({ background:"#8B1079" });
           urlImg = $("a.curIt img").attr("src");
            active_img = $("a.curIt img").attr("hoveredImg");
            notactive_img = $("a.curIt img").attr("nothoveredImg");
			if(urlImg==noactive_img){
				nameCurImg = urlImg.substring(urlImg.lastIndexOf("/")+1, urlImg.lastIndexOf("."));
				//$(".curIt img").attr({"src": path + nameCurImg + "_.png"});
                                $(".curIt img").attr({"src": active_img});
				$(".curIt").attr({ "id":"currentItem" });
				$("#" + target).attr({"name": "on"}).css({display:"block"});
			}
		},
		function(){}
	);
    $(".secondLevel span a img").hover(
		function () {
            urlImg = $(this).attr("src");
            nameImg = urlImg.substring(urlImg.lastIndexOf("/")+1, urlImg.lastIndexOf("."));
            $(this).attr({"src": path + nameImg + "_.png"});
        }, 
     	function () {
            urlImg = $(this).attr("src");
            nameImg = urlImg.substring(urlImg.lastIndexOf("/")+1, urlImg.lastIndexOf("_."));
            $(this).attr({"src": path + nameImg + ".png"});
        }	
	);
});

