var t;

$(document).ready(function(){

    var items = $(".mainMenuLevel3").parent();

    //items.appendTo(".dropDown");

    items.each(function(){
        var newDiv = $("#dropDown_0").clone();
        var dropDownCount = $(".dropDown").length;
        newDiv.attr("id", "dropDown_"+dropDownCount);
        $(this).parent().attr("id", "dropDownParent_"+dropDownCount);
        $(this).parent().addClass("dropDownParent");
        newDiv.append($(this));
        $(".dropDown").parent().append(newDiv);
        $(".dropDown").hide();
    });

//    $(".dropDown").hide();
    $(".mainMenuLevel3").show();
    
    $(".dropDown").mouseenter(function(){
         $(this).show();
         var id = $(this).attr("id").split("_")[1];
         var parent = $("#dropDownParent_"+id);
         parent.css("backgroundColor", "#1F0A01");
    });

    $(".dropDown").mouseleave(function(){
         $(this).hide();
         var id = $(this).attr("id").split("_")[1];
         var parent = $("#dropDownParent_"+id);
         parent.css("backgroundColor", "#321203");
    });

    $(".dropDownParent").mouseenter(function(){
        var id = $(this).attr("id").split("_")[1];
        var parentOffset = $(this).offset();
        $(this).css("backgroundColor", "#1F0A01");
        var dropDown = $("#dropDown_"+id);
        dropDown.css("top", parentOffset.top);
        dropDown.css("left", parentOffset.left+185);
        dropDown.show();
    });

    $(".dropDownParent").mouseleave(function(){
        var id = $(this).attr("id").split("_")[1];
        var dropDown = $("#dropDown_"+id);
        $(this).css("backgroundColor", "#321203");
        dropDown.hide();
    });

    $("#persianLink").click(function(){
//        alert("A");
        return false;
    });

    $("#persianLink").mouseenter(function(){
        clearTimeout(t);
        $("#persianMenu").css("left", 190);
        $("#persianMenu").css("top", 180 );
        $("#persianMenu").show();
    });

$("#persianMenu").mouseenter(function(){
    clearTimeout(t);
    $(this).show();
});

    $("#persianLink").mouseleave(function(){
        t = setTimeout( hidePersian, 500 );
    });

$("#persianMenu").mouseleave(function(){
    t = setTimeout( hidePersian, 500 );
});

});

function hidePersian() {
    $("#persianMenu").hide();
}
