﻿jQuery(function(){
	jQuery(".navigation UL .firstLevel").mouseover(function(){
		var menu = this;
		var submenu = jQuery(menu).children("UL");
		submenu.css('left', '10px');
		jQuery(menu).addClass("sfhover");
		
		jQuery(".navigation UL LI.firstLevel").each(function(index, elem){
			if(menu != elem)
			{
				var el = jQuery(elem).children("UL");
				el.css('left', '-9110px');
				jQuery(elem).removeClass("sfhover");
			}
 		});
	});
	jQuery(".navigation UL LI.firstLevel").mouseleave(function(){
		var menu = this;
		var submenu = jQuery(menu).children("UL");
		submenu.css('left', '-9110px');
		jQuery(menu).removeClass("sfhover");
	});
	
	//login dialog
	jQuery( ".menuLoginContent" ).dialog({
		autoOpen: false,
		width:350,
		height: 250,
		modal: true,
		draggable: false,
		buttons: {
				"登录网站": function() {
								if(jQuery("#userName").val()==""){
									alert("请输入用户名！");
									return false;
								}
								if(jQuery("#password").val()==""){
									alert("请输入密码！");
									return false;
								}
								if(jQuery("#j_captcha_response").val()==""){
									alert("请输入验证码！");
									return false;
								}
								if(jQuery("#remUserName").attr("checked") == "checked")
								{
									jQuery.cookie("username", jQuery("#userName").val(), {expires: 30, path: "/"});
								}else{
									jQuery.cookie("username", null, {path: "/"});
								}
								jQuery("#loginForm").submit();
							},
				"用户注册": function() {location.href = jQuery("#indexRegLink").val();}
		}
	});
	jQuery(".navigation UL LI.indexLogin img").click(function(){
		if(jQuery.cookie("username") != null)
		{
			jQuery("#userName").val(jQuery.cookie("username"));
			jQuery("#remUserName").attr("checked", "checked");
		}
		jQuery( ".menuLoginContent" ).dialog("open");
	});
});

var jqalert = function(obj)
{
	jQuery("body").find(".jq_alert_div").remove();
	jQuery("body").append("<div class='jq_alert_div' title='提示'><p style='word-wrap:break-word; overflow:hidden;'>" + obj + "</p></div>");
	jQuery(".jq_alert_div").dialog({
		modal: true,
		buttons: {
			"确认": function() {
				jQuery( this ).dialog( "close" );
			}
		}
	});
	if ( jQuery.browser.msie && jQuery.browser.version == '6.0') {
		 jQuery(".jq_alert_div").bgiframe();
	}
};

var jqconfirm = function(obj, callback)
{
	jqconfirm.reslut = false;
	jQuery("body").find(".jq_confirm_div").remove();
	jQuery("body").append("<div class='jq_confirm_div' title='请您确认以下信息'><p style='word-wrap:break-word; overflow:hidden;'>" + obj + "</p></div>");
	jQuery(".jq_confirm_div").dialog({
		modal: true,
		buttons: {
			"确认": function() {
				jQuery( this ).dialog( "close" );
				callback();
			},
			"取消": function() {
				jQuery( this ).dialog( "close" );
			}
		}
	});
};

/**
 * 
 */
(function($){
	var methods = {
		init: function(options) {
			var opts = $.extend({}, $.fn.jqconfirm.defaults, options);  
			return this.each(function(i, o){
				var $this = $(this);
				$(o).attr({title: opts.title});
				$(o).html("<p>" + opts.msg + "</p>");
				
				$(o).dialog({
					modal: true,
					width: opts.width,
					height: opts.height,
					buttons: opts.buttons
				});
			});
		},
		close: function() {
			$(this).dialog('close');
		}
	};
	
	$.fn.jqconfirm = function(method){
		if ( methods[method] ) {
			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
		    return methods.init.apply( this, arguments );
		} else {
		    $.error( 'Method ' +  method + ' does not exist on jqconfirm' );
		}    
	};
	
	// 插件的defaults    
	$.fn.jqconfirm.defaults = {    
		title: '',    
		msg: '',
		width: '300px',
		height: 'auto',
		buttons: {
			'OK': function() {
				return;
			},
			'Cancel': function() {
				return;
			}
		}
	}; 
})(jQuery);


