// JavaScript Document
var mouseSearchRadio = false;

function closeSearchField() {
    if (!mouseSearchRadio) {
        if ($(".searchRadio").css("display") == "block") {
            $(".searchRadio").slideToggle("slow");
        }
    }
}

$(function() {
    
	 var url = new String(window.location.pathname);
	 $(".tree li").each(function(){
		var href1 = $(this).find('a').attr('href');
		var index = href1.indexOf("?");
		if(index > 1)
		{
			var inodeFolder = href1.indexOf("inodeFolder");
			if(inodeFolder == -1)
			{
				href1 = href1.substring(0,index)
			}
		}
		if(url == href1)
		{
			var idLiv1Href = $(this).attr('id');
            $.cookie("liv1", idLiv1Href, { path: '/' });
		}
	 });
	 $(".tree li ul li").each(function(){
		var href2 = $(this).find('a').attr('href');
		var index = href2.indexOf("?");
		if(index > 1)
		{
			var inodeFolder = href2.indexOf("inodeFolder");
			if(inodeFolder == -1)
			{
				href2 = href2.substring(0,index)
			}
		}
		if(url == href2)
		{
			var idLiv2Href = $(this).attr('id');
			var idLiv1Padre = $(".tree li").attr('id');
            $.cookie("liv2", idLiv2Href, { path: '/' });
			$.cookie("sel", idLiv2Href, { path: '/' });
			$.cookie("liv1", idLiv1Padre, { path: '/' });
		}
	 });
	 $(".tree li ul li ul li").each(function(){
		var href3 = $(this).find('a').attr('href');
		var h = href3
		var index = href3.indexOf("?");
		if(index > 1)
		{
	              var inodeFolder = href3.indexOf("inodeFolder");
			if(inodeFolder == -1)
			{
			 href3 = href3.substring(0,index)
			if(url != "dotCMS/GalleryPhoto" || url != "/dotCMS/GalleryVideo")
			{
			   href3 = h
			   url = new String(window.location.pathname + window.location.search);
			}
                        }
		}
		if(url == href3)
		{
			var idLiv3Href = $(this).attr('id');
            $.cookie("liv3", idLiv3Href, { path: '/' });
			$.cookie("sel", idLiv3Href, { path: '/' });
			var idLiv2Href = $(this).parents("li").attr('id');
           $.cookie("liv2", idLiv2Href, { path: '/' });
			var idLiv1Padre = $(".tree li").attr('id');
			$.cookie("liv1", idLiv1Padre, { path: '/' });
		}
	 });
	
    $(".tree li").removeClass("lev2open"); //Remove any "active" class

        var x = $.cookie("liv1");
        $("#" + $.cookie("liv1")).addClass("lev2open"); //Add "active" class to selected tab

        $(".tree li ul li").removeClass("lev3open"); //Remove any "active"
        
        var y = $.cookie("liv2");
        $("#" + $.cookie("liv2")).addClass("lev3open"); //Add "active" class to selected tab
        $("#" + $.cookie("liv2")).addClass("sel"); //Add "active" class to selected tab

        $(".tree li ul li ul li").removeClass("sel"); //Remove any "active"
		$(".tree li ul li").removeClass("sel"); //Remove any "active"
        var z = $.cookie("liv3");
		var k = $.cookie("sel");
		$("#" + $.cookie("sel")).addClass("sel"); //Add "active" class to selected tab
		

});

$(document).ready(function() {
	
	
    var control2 = false;
    var control3 = false;
    $(".tree li").click(function() {
        $.cookie("liv1", null, { path: '/' });
        var idLiv1 = $(this).attr('id');
        $.cookie("liv1", idLiv1, { path: '/' });
        if (control2 != true)
        {
            $.cookie("liv2", null, { path: '/' });
			$.cookie("sel", null, { path: '/' });
        }
        if (control3 != true)
        {
            $.cookie("liv3", null, { path: '/' });
        }
    });

    $(".tree li ul li").click(function() {
        $.cookie("liv2", null, { path: '/' });
        var idLiv2 = $(this).attr('id');
        $.cookie("liv2", idLiv2, { path: '/' });
        control2 = true;
        if (control3 != true)
        {
            $.cookie("liv3", null, { path: '/' });
			$.cookie("sel", idLiv2, { path: '/' });
        }
		
    });
    $(".tree li ul li ul li").click(function() {
        $.cookie("liv3", null, { path: '/' });
        var idLiv3 = $(this).attr('id');
        $.cookie("liv3", idLiv3, { path: '/' });
        control3 = true;
		$.cookie("sel", idLiv3, { path: '/' });
    });

    $(".treeHeader li").click(function() {
        $.cookie("liv1", null, { path: '/' });
        var idLiv1 = $(this).attr('id');
        $.cookie("liv1", "liv" + idLiv1, { path: '/' });
        if (control2 != true)
        {
            $.cookie("liv2", null, { path: '/' });
			$.cookie("sel", null, { path: '/' });
        }
        if (control3 != true)
        {
            $.cookie("liv3", null, { path: '/' });
        }
    });

    $(".treeHeader li ul li").click(function() {
        $.cookie("liv2", null, { path: '/' });
        var idLiv2 = $(this).attr('id');
        $.cookie("liv2", "liv2" + idLiv2, { path: '/' });
        control2 = true;
        if (control3 != true)
        {
            $.cookie("liv3", null, { path: '/' });
			$.cookie("sel", "liv2" + idLiv2, { path: '/' });
        }
		
    });


    $("#searchField").click(function() {
        $(".searchRadio").slideToggle("slow");
    });
    $(".searchRadio").mouseenter(function() {
        mouseSearchRadio = true;
    })
    $("#searchField").mouseenter(function() {
        mouseSearchRadio = true;
    })
    $(".searchRadio").mouseleave(function() {
        mouseSearchRadio = false;
        setTimeout("closeSearchField()", 1);
    });
    $("#searchField").mouseleave(function() {
        mouseSearchRadio = false;
        setTimeout("closeSearchField()", 1);
    });
    MenuDx();
});

function MenuDx() {
    $('.lt6:eq(0)> ul').hide();
    $('.lt6:eq(0)>li > a').click(function() {
        if ($(this).parent('li').children('ul').size() > 0) {
            if ($(this).parent('li').hasClass('sel')) {
                $(this).next().slideToggle('normal');
                $(this).parent('li').removeClass('sel');
            }
            else
            {
                $(this).next().slideToggle('normal');
                $(this).parent('li').addClass("sel");
            }
        }
    });
}

function changeSize(size, objLink) {
    $(".textSize > a").removeClass("ts-active");
    $("body").css("font-size", size);
    $(objLink).addClass("ts-active");
}

function showTxt(id, objClass) {
    if ($('#' + id + '-full').css("display") == "none") {
        $('#' + id + '-prew').hide();
        $('#' + id + '-full').show();
        $(objClass).removeClass("prew");
        $(objClass).addClass("full");
        $(objClass).html('Chiudi')
    }
    else {
        $('#' + id + '-full').hide();
        $('#' + id + '-prew').show();
        $(objClass).removeClass("full");
        $(objClass).addClass("prew");
        $(objClass).html('Vedi tutto')
    }
}

