jQuery(document).ready(function(){

	jQuery("ul.dropdown li").dropdown();

});

jQuery.fn.dropdown = function() {

	jQuery(this).hover(function(){
		jQuery(this).addClass("hover");
		jQuery('> .dir',this).addClass("open");
		jQuery('ul:first',this).css('visibility', 'visible');
	},function(){
		jQuery(this).removeClass("hover");
		jQuery('.open',this).removeClass("open");
		jQuery('ul:first',this).css('visibility', 'hidden');
	});

}

function AJAX_page_details(id_page)
{				
	jQuery("#AJAX_page_details").load("/templates/test/ajax/AJAX_page_details.php", { id_page: id_page, sid: Math.random() }, function() {
		jQuery("#AJAX_page_details").modal({
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.data.hide();
					dialog.container.fadeIn('fast', function () {
						dialog.data.slideDown('fast');
					});
				});
			},
			onClose: function (dialog) {
				dialog.data.fadeOut('fast', function () {
					dialog.container.slideUp('fast', function () {
						dialog.overlay.fadeOut('fast', function () {
							$.modal.close();
						});
					});
				});
			}
		});
	});
}

function AJAX_update_list_menu(level,value)
{
	try
	{
		if (value.substring(0,3)=="f_")
		{								
			jQuery("#AJAX_update_list_menu_"+level).load("/templates/test/ajax/AJAX_update_list_menu.php", { level: level, id_folder: value.substring(3), sid: Math.random() } );
			document.getElementById('update_list_menu_id').value = value.substring(3);
			document.getElementById('update_list_menu_element').value = "folder";
		}
		else if (value.substring(0,3)=="p_")
		{
			document.getElementById('update_list_menu_id').value = value.substring(3);
			document.getElementById('update_list_menu_element').value = "page";	
		}
	}
	catch (e)
	{
		// Do nothing
	}
}

function AJAX_update_list_menu_go()
{
	// When nothing is selected go to home
	if (document.getElementById('update_list_menu_element').value == "folder" && document.getElementById('update_list_menu_id').value == 333)
	{
		window.location = "index.php";
	}
	// Go to folder
	else if (document.getElementById('update_list_menu_element').value == "folder")
	{
		window.location = "index.php?element="+document.getElementById('update_list_menu_element').value+"&id="+document.getElementById('update_list_menu_id').value;
	}
	// Go to page
	else if (document.getElementById('update_list_menu_element').value == "page")
	{
		AJAX_page_details(document.getElementById('update_list_menu_id').value);
	}
}
