﻿$(document).ready(function() {


    // menu képek
    $(".menu li a img").css("display", "none");
    $(".menu li a").hover(
					function() {
					    $(this).find("img").css("display", "block");
					},
					function() {
					    $(this).find("img").css("display", "none");
					}
					);

    // cookie-s szín-téma választó
    $("body").addClass("zold");
    $("html").css("background", "#e6efc2");
    $(".themes li a").click(function() {
        var tema = $(this).attr("class");
        $("body").removeClass().addClass(tema);
    });
    ////        var sutemeny = $.cookie("sutemeny");
    ////        if (sutemeny) {
    ////            $("body").removeClass().addClass(sutemeny);
    ////        };
    ////        if (sutemeny == "zold") {
    ////            $("html").css("background", "#e6efc2");
    ////        };
    ////        if (sutemeny == "narancs") {
    ////            $("html").css("background", "#fbe3bf");
    ////        };
    ////        if (sutemeny == "bordo") {
    ////            $("html").css("background", "#e2c7c0");
    ////        };
    ////        if (sutemeny == "sotetszurke") {
    ////            $("html").css("background", "#ccc");
    ////        };

 

    // tooltip a tartalmakban
    xOffset = 5;
    yOffset = 30;
    $("a[href*='def'] + strong").addClass("tooltip");
    $("a[href*='def']").css("display", "none");
    $(".tooltip").each(function() {
        $(this).hover(function(e) {
            var def = $(this).prev("a[@href^='def']").html();
            $("body").append("<div class='tooltipbox'>" + def + "</div>");
            $(".tooltipbox").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px").show();
        },
					function() {
					    $(".tooltipbox").remove();
					});
    });
    $(".tooltip").mousemove(function(e) {
        $(".tooltipbox").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px");
    });

    // minden külső (http-vel kezdődő) link új ablakban nyílik meg
    $("a[href*='def']").click(function() {
        window.open(this.href); return false;
    });


    $("span.sendamessage").click(
    function() {
        $(".sendamessagePopUp").show();
    });



    $("div.PopUpClose").click(
    function() {
        $(".sendamessagePopUp").hide();
        $(".sendemailPopUp").hide();
        $(".MNBRight").css("position", "relative");
    });

    $("span.withtoolTip").mouseover(
    function() {
        $(this).children().show();
    });

    $("span.withtoolTip").mouseout(
    function() {
        $(this).children("div").hide();
    });

    $("div.szureslink").click(
    function() {
        if (!$("div.details").hasClass("active")) {
            $("div.details").addClass("active");
            $("div.details").show();
        }
        else {
            $("div.details").hide();
            $("div.details").removeClass("active");
        }
    });

    $("div.sharelink").click(
    function() {
        $("div.shareBox").show();
    });

    $(".sendemail").click(
    function() {
        $("div.sendemailPopUp").show();
        $(".MNBRight").css("position", "absolute");
    });


    $("div.addnew").click(
    function() {
        $("div.editopen").toggle();
    });



        $("div.showhide").click(
    function() {
        if (!$(this).hasClass("active")) {
            $("div.showhide").removeClass("active");
            $(this).addClass("active");
            $(this).next().show();
        }
        else {
            $(this).next().hide();
            $(this).removeClass("active");
        }

    });

    $(".SitemapItem").click(


        function() {
            if (!$(this).children("ul").hasClass("SitemapOpen")) {
                $(this).children("ul").addClass("SitemapOpen");
                $(this).children("span").text("+");
            }
            else {
                $(this).children("ul").removeClass("SitemapOpen");
                $(this).children("span").text("-");
            }

        });

    $(".searchResultListItem").click(

     function() {
         if (!$(this).children("div.searchResultListItemLead").hasClass("searchResultOpen")) {
             $(this).children("div.searchResultListItemLead").addClass('searchResultOpen');
             $(this).children("span").text("-");
         }
         else {
             $(this).children("div.searchResultListItemLead").removeClass('searchResultOpen');
             $(this).children("span").text("+");
         }
     });

     $(".versionbutton").click(

     function() {
         if (!$(this).next("div.versionwindow").hasClass("versionwindowOpen")) {
             $(this).next("div.versionwindow").addClass('versionwindowOpen');
         }
         else {
             $(this).next("div.versionwindow").removeClass('versionwindowOpen');
         }
     });

     $(".toolbaricon").click(

     function() {
         if (!$(this).next("div.editrowpro").hasClass("open")) {
             $(this).next('div.editrowpro').fadeIn('1000');
             $(this).next('div.editrowpro').addClass('open');
         }
         else {
             $(this).next('div.editrowpro').fadeOut('1000');
             $(this).next('div.editrowpro').removeClass('open');
         }
     });

     $(".versionbutton").mouseover(

     function() {
         $(this).addClass('hover');
     });

     $(".versionbutton").mouseout(

     function() {
         $(this).removeClass('hover');
     });

     //FONT SIZE

     var newSize = 1;
     var switchSize = '';
     var fSArr = '';
     var origHolder = $('body');

     $('li.fontSwitch').click(function(ev) {
         ev.preventDefault();

         fSArr = $.cookie("bodyFontSize") ? $.cookie("bodyFontSize").split('_') : "size_1".split('_');

         var origSize = parseInt(fSArr[1]);

         if ($(this).attr('id') == 'MNB_FontSizeUp') {
             if (origSize < 3) {
                 newSize += 1;
                 switchSize = 'size_' + newSize;
                 origHolder.removeClass('size_' + origSize).addClass('size_' + newSize);
             }
             else {
                 return false;
             }
         }
         else {
             if (origSize > 0) {
                 newSize -= 1;
                 switchSize = 'size_' + newSize;
                 origHolder.removeClass('size_' + origSize).addClass('size_' + newSize);
             }
             else {
                 return false;
             }
         }

         $.cookie("bodyFontSize", switchSize, { expires: 365 });
     });


});

function convertTitleToUriName()
{
    var regexp_a = /[áÁ]/g;
    var regexp_e = /[éÉ]/g;
    var regexp_i = /[íÍ]/g;
    var regexp_o = /[óöőÓÖŐ]/g;
    var regexp_u = /[úűÚŰ]/g;
    var regexp_sp = /\s/g;
    // Clean up the title		
	var url = $("#MNBTitleDiv input").val() 
		.toLowerCase(); // change everything to lowercase
    if (url == "") return;
	url = url.replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces
		.replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
	    .replace(regexp_a, "a")
        .replace(regexp_e, "e")
        .replace(regexp_i, "i")
        .replace(regexp_o, "o")
        .replace(regexp_u, "u")
		.replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
		.replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
		.replace(/^-+|-+$/g, "") // trim leading and trailing hyphens				
		; 
	$("#MNBNameDiv input").val(url);
}
