$(document).ready(function(){
	//勋章下拉菜单				   
	$(".ss").click(function(){
			$(".hide").toggle(500);
	});
	//侧下拉菜单
	$(".toggle p").hide();
    $(".toggle div").click(function(){
     $(".toggle p").not($(this).next()).hide();
     $(".toggle div").not($(this).next()).removeClass("current");
     $(this).next().slideToggle(500);
     $(this).toggleClass("current");
   });
   $("#tab_nav1").find("li").each(function(i){
		$(this).mouseover(function(){
			//$("#tab_nav1 li").removeClass("hover");
			//$(this).addClass("hover");
			/*
			$("#tab_nav1").find("li").each(function(i){
				$("#tab_nav1 li").removeClass("nav_"+i);										
			});
			$(this).addClass("nav_"+i);
			*/
			$("#tab_main1 ul").hide();
			$("#target"+i).show();
		});
	});
});

function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    } catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}  


function SetHome(obj,vrl)
{
    try
    {
            obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
    }
    catch(e){
            if(window.netscape) {
                    try {
                            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
                    } 
                    catch (e) { 
                            alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
                    }
                    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                    prefs.setCharPref('browser.startup.homepage',vrl);
             }
    }
}

function CheckBrowser(){

    var html = '';
    if(window.ActiveXObject){
        html = "<li><a href='javascript:void(0);' onclick='SetHome(this,window.location)' style='cursor:hand'>设为首页</a></li>";

    }//else if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1){


    //}else if((typeof document.implementation != "undefined") && (typeof document.implementation.createDocument != "undefined") && (typeof HTMLDocument != "undefined")){


    //}else if(navigator.userAgent.toLowerCase().indexOf("opera") != -1){


    //}

    document.write(html);

}

function checkHiError(hierr) {
	if (hierr.errorid != undefined) {
		var errhtml = "<div style=\"font-size:16px;text-align:center;margin:2em;\">"
			+hierr.errormessage+"</div>";
		if (hierr.redirect != undefined) {
			errhtml += "<div style=\"text-align:center;\">即将跳转至：<a href=\""+hierr.redirect+"\">"+hierr.redirect+"</a></div>";
			errhtml += "<script>setTimeout(function(){window.location=\""+hierr.redirect+"\";}, 3000)<\/script>";
		}
		stBox = $.weeboxs.open(errhtml, {title:"出错啦", showButton:false, width:640, height:160});
		return true;
	}
}



function parsedate(s) {
	/(\d+)\-(\d+)\-(\d+)\s*(\d*):?(\d*)/.exec(s);
	var m1 = (RegExp.$1 && RegExp.$1 > 1899 && RegExp.$1 < 2101) ? parseFloat(RegExp.$1) : today.getFullYear();
	var m2 = (RegExp.$2 && (RegExp.$2 > 0 && RegExp.$2 < 13)) ? parseFloat(RegExp.$2) : today.getMonth() + 1;
	var m3 = (RegExp.$3 && (RegExp.$3 > 0 && RegExp.$3 < 32)) ? parseFloat(RegExp.$3) : today.getDate();
	var m4 = (RegExp.$4 && (RegExp.$4 > -1 && RegExp.$4 < 24)) ? parseFloat(RegExp.$4) : 0;
	var m5 = (RegExp.$5 && (RegExp.$5 > -1 && RegExp.$5 < 60)) ? parseFloat(RegExp.$5) : 0;
	/(\d+)\-(\d+)\-(\d+)\s*(\d*):?(\d*)/.exec("0000-00-00 00\:00");
	return new Date(m1, m2 - 1, m3, m4, m5);
}


function event_lab(id){
    $("#lab_1").removeClass("hover");
    $("#lab_2").removeClass("hover");
    $("#lab_"+id).addClass("hover");
    $("#youbeisay").hide();
    $("#eventmember").hide();
    if(id == 1){
        $("#youbeisay").show();
    }

    if(id == 2){
        $("#eventmember").show();
    }
}

function deFans(fuid) {
	if (confirm("确定移除该粉丝？")) {
		var options = {
				url : makeurl('friend', 'removeFans', {'fuid':fuid}),
				dataType : 'json',
				success : function(data) {
					$("#friendiv_"+fuid).hide(true);
				}
		};
		$.ajax(options);
	}
}

/**
 * 图片自动缩放
 * @param jqueryObj 图片jquery对象
 * @param width 容器宽度
 * @param height 容器高度
 * @param mode 0:居中, 1:短边拉伸, 2:长边拉伸
 * @param bgcolor 背景填充色，如 #fff
 */
function resizeImg(jqueryObj, width, height, mode, bgcolor) {
	var i = width / height;
	jqueryObj.parent().css('display', 'block').css('width', width+'px').css('height', height+'px').css('position', 'relative').css('overflow', 'hidden');
	if (bgcolor) jqueryObj.parent().css('background', bgcolor);
	jqueryObj.each(function() {
		var _self = $(this);
		_self.css('position', 'absolute');
		var imgloader = new Image();
		$(imgloader).load(function(){
			var tw = imgloader.width;
			var th = imgloader.height;
			var ti = tw / th;
			var rw = 0;
			var rh = 0;
			if (mode == 0) {
				if (ti > i) {
					if (tw > width) {
						rw = width;
						rh = Math.round(width / ti);
					} else {
						rw = tw;
						rh = th;
					}
				} else {
					if (th > height) {
						rw = Math.round(height * ti);
						rh = height;
					} else {
						rw = tw;
						rh = th;
					}
				}
			} else if (mode == 1) {
				if (ti > i) {
					rw = Math.round(height * ti);
					rh = height;
				} else {
					rw = width;
					rh = Math.round(width / ti);
				}
			} else if (mode == 2) {
				if (ti > i) {
					rw = width;
					rh = Math.round(width / ti);
				} else {
					rw = Math.round(height * ti);
					rh = height;
				}
			}
			_self.width(rw);
			_self.height(rh);
			_self.css('left', Math.round((width-rw)/2)+'px');
			_self.css('top', Math.round((height-rh)/2)+'px');
		}).attr('src', _self.attr('src'));
	});
}

function xmkurl(controller, action, args, entery, mode) {
	if (!mode) return makeurl(controller, action, args, entery);
	var url = '';
	if (entery == undefined) entery = "";
	if (mode == 1) {
		url = entery + "/" + controller + "/" + action + "/";
		if (args instanceof Object) {
			for (var k in args) {
				url += k + "/" + args[k] + "/";
			}
		}
	} else if (mode == 2) {
		url = entery + "index.php?c=" + controller + "&a=" + action;
		if (args instanceof Object) {
			for (var k in args) {
				url += "&" + k + "=" + args[k];
			}
		}
	} else if (mode == 3) {
		if (controller == undefined) controller = "index";
		if (action == undefined) action = "default";
		if (controller == "index" && action == "default") {
			url = "/";
		} else if (action == "default") {
			url = "/" + controller + "/";
		} else {
			url = "/" + controller + "/" + action + "/";
		}
		if (args instanceof Object) {
			for (var k in args) {
				
				url += k + "-" + args[k].replace("-", "~") + "-";
			}
			url += ".html";
		}
	}
	return url;
}

function xmasonry(opt) {
	opt = jQuery.extend({
		container : '#wallbox',
		itemSelector : '#wallbox .part',
		navSelector  : '#page-nav', 
		nextSelector : '#page-nav a',
		scroll : true
	}, opt);
	
	var container = $(opt.container);
	container.imagesLoaded(function(){
		container.masonry({
			itemSelector: opt.itemSelector
		});
	});

	if (opt.scroll) {
		container.infinitescroll({
			navSelector  : opt.navSelector, 
			nextSelector : opt.nextSelector,
			itemSelector : opt.itemSelector,
			loading: {
				msgText : '页面加载中，请稍候……',
				finishedMsg: '已无更多内容',
				img: SITE_URL.static+'/images/loadorange.gif'
			}
		},
		function( newElements ) {
			var newElems = $( newElements ).css({ opacity: 0 });
			newElems.imagesLoaded(function() {
				setTimeout(function() {
					newElems.animate({ opacity: 1 });
					container.masonry( 'appended', newElems, true );
				}, 500);
			});
		});
	}
}

function masonry_prepend(opt) {
	/*
	opt = jQuery.extend({
		container : '#wallbox',
		itemSelector : '#wallbox .part',
	}, opt);
	var container = $(opt.container);
	var items = $(opt.itemSelector);
	items.removeClass('masonry-brick').removeAttr('style');
	container.imagesLoaded(function(){
		container.masonry({
			itemSelector: opt.itemSelector
		});
	});
	*/
}
