$(function() {
		   
	//===== Collapsible elements management =====//
	$('.exp').collapsible({
		defaultOpen: 'current',
		cookieName: 'navAct',
		cssOpen: 'active',
		cssClose: 'inactive',
		speed: 200
	});
	
	$('.opened').collapsible({
		defaultOpen: 'opened,toggleOpened',
		cssOpen: 'inactive',
		cssClose: 'normal',
		speed: 200
	});
	
	$('.closed').collapsible({
		defaultOpen: '',
		cssOpen: 'inactive',
		cssClose: 'normal',
		speed: 200
	});
	
	
	$('.goTo').collapsible({
		defaultOpen: 'openedDrop',
		cookieName: 'smallNavAct',
		cssOpen: 'active',
		cssClose: 'inactive',
		speed: 100
	});
	
	/*$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("smalldd"))
		$(".smallDropdown").slideUp(200);
	});*/
	
	//===== Tabs =====//
	$.fn.contentTabs = function(){
		$(this).find(".tab_content").hide();
		$(this).find("ul.tabs li:first").addClass("activeTab").show();
		$(this).find(".tab_content:first").show();
		
		$("ul.tabs li").click(function() {
			$(this).parent().parent().find("ul.tabs li").removeClass("activeTab");
			$(this).addClass("activeTab");
			$(this).parent().parent().find(".tab_content").hide();
			var activeTab = $(this).find("a").attr("href");
			$(activeTab).show();
			return false;
		});
	};
	$("div[class^=widget]").contentTabs();
	
	//===== Notification boxes =====//		   
	$(".hideit").click(function() {
		$(this).fadeTo(200, 0.00, function(){
			$(this).slideUp(300, function() {
				$(this).remove();
			});
		});
	});
	
	//===== UI dialog =====//
	$( "#dialog-customMenu" ).dialog({
		autoOpen: false,
		modal: true,
		buttons: {
			Ok: function() {
				var regexp = /^(?!_)(?!.*?_$)[a-zA-Z0-9_\/\u4e00-\u9fa5]+$/i,
					title = $("#titleCn").val(),
					url = $("#addMenu").attr("action");
				if ( !( regexp.test(title) ) ) {
					alert("中文名称不能为空且不能包含特殊字符！");
					return false;
				} else {
					$(".loading").show();
					$.post(url, $("#addMenu").serialize() ,function(data){
						if(data.success=='true'){
							//$(this).dialog("close");
							$(data.m).appendTo("#comsterMenu").hide().slideDown("fast");
							//alert(data.m);
							//$(".menuList .widget_content").slideUp("fast");
							//$(".menuList .widget_options").empty();
							//$(data).appendTo(".menuList .widget_options").hide().slideDown("fast");
							/*
							if ( bValid ) {
								$( "#users tbody" ).append( "<tr>" +
									"<td>" + name.val() + "</td>" + 
									"<td>" + email.val() + "</td>" + 
									"<td>" + password.val() + "</td>" +
								"</tr>" ); 
								$( this ).dialog( "close" );
							}
							*/
							setTimeout(function(){
								$(".loading").hide();
								$( "#dialog-customMenu" ).dialog( "close" );
							},500);
						}else{
							alert(data.m);
							//$("#dialogEditMenu").css("display","none");
						}
					},"json");
					return true;
				}
			}
		}
	});
	
	//===== Breadcrumbs =====//
	//$('#breadcrumbs').xBreadcrumbs();
	
});