﻿window.onresize = doReSize;
window.onload = doReSize;
function doReSize() {
	$("#smoothmenu-ajax").attr("class", "ddsmoothmenu");
}

ddsmoothmenu.init({
	mainmenuid : "smoothmenu-ajax",
	orientation : 'h',
	classname : 'ddsmoothmenu',
	customtheme : ["#1c5a80", "#18374a"], // override default menu CSS
	// background values? Uncomment:
	// ["normal_background",
	// "hover_background"]
	contentsource : ["smoothcontainer", basePath + "menu.html"]
		// contentsource: ["smoothcontainer",
		// "index/getNavItem.action?divClass=smartmenu"] //"markup" or
		// ["container_id", "path_to_menu_file"]
	});
// 更多事件itemType 1 栏目 2内容 3文章 4链接 5功能 6图片 7视频
function goToUrl(itemType, itemId, itemPid, createHtml, src) {
	if (itemType == 4) {
		window.location.href = src;
	} else if (itemType == 2) {
		window.location.href = basePath + "html/itemInfor_" + itemId + "_"
				+ createHtml + ".html";
	} else if (itemType == 3) {
		window.location.href = basePath + "html/listArticle_" + itemType + "_"
				+ itemId + "_" + itemPid + "_" + createHtml + ".html";
	} else if (itemType == 5) {
		window.location.href = src;
	} else if (itemType == 6) {
		window.location.href = basePath + "html/listArticle_" + itemType + "_"
				+ itemId + "_" + itemPid + "_" + createHtml + ".html";
	} else if (itemType == 7) {
		window.location.href = basePath + "html/listArticle_" + itemType + "_"
				+ itemId + "_" + itemPid + "_" + createHtml + ".html";
	}
}

function more(itemType, itemId, itemPid, createHtml) {
	if (itemType == 6) {
		window.location.href = basePath + "html/listArticle_" + itemType + "_"
				+ itemId + "_" + itemPid + "_" + createHtml + ".html";
	} else if (itemType == 7) {
		window.location.href = basePath + "html/listArticle_" + itemType + "_"
				+ itemId + "_" + itemPid + "_" + createHtml + ".html";
	} else {
		window.open("html/listArticle_" + itemType + "_" + itemId + "_"
				+ itemPid + "_" + createHtml + ".html");
	}
}

function changeItemPath(itemId) {
	var itemName = $("#itemid-" + itemId).text();
	var itemPath = $('#itempath').text().split(">>");
	var newItemPath = "";
	for (var i = 0; i < itemPath.length - 1; i++) {
		newItemPath += itemPath[i] + ">>";
	}
	newItemPath += itemName;
	$('#itempath').text(newItemPath);
}

// 显示文章列表page
function showArticleListPage(currentPage, itemId) {
	var itemType = $("#itemid-" + itemId).attr('itemtype');
	var str = "";

	var param = {
		currentPage : currentPage,
		pageSize : 20,
		itemId : itemId,
		pageWay : 1
	};
	if (itemType == 6 || itemType == 7) {
		param.pageSize = 9;
		param.itemId =itemId;
		param.pic = true;
	}
	$.post(basePath + "/index/showArt.action", param,
			function(data, textStatus) {
				if (itemType == 6 || itemType == 7) {// picList FlvList
					$(data.artList).each(function(i, v) {
						str += "<div class='video'><a  href='";
						if (v.articleSrc == '') {
							str += basePath + "html/article_" + v.itemId + "_"
									+ v.itemId + "_" + v.articleId + "_"
									+ v.createHtml + ".html";
						} else {
							str += "javascript:otherUrl(\"" + v.articleSrc
									+ "\");";
						}
						str += "' target='_blank' title='" + v.articleTitle
								+ "'><img width='160px' height='100px' src='"
								+ basePath + v.articlePicTitle + "' /><br>"
								+ getChars(v.articleTitle, 12) + "</a></div>";
					});
					str += "<div class='clear'></div>";
				} else {// articleList
					$(data.artList).each(function(i, v) {
						str += "<li><span class='act'>"
								+ v.articleAddDate.split(" ")[0]
								+ "</span>·<a  href='";
						if (v.articleSrc == '') {
							str += basePath + "html/article_" + v.itemId + "_"
									+ v.itemId + "_" + v.articleId + "_"
									+ v.createHtml + ".html' target='_blank'";
						} else {
							str += "javascript:;' onclick='otherUrl(\""
									+ v.articleSrc + "\");'";
						}
						str += " title='" + v.articleTitle + "'>"
								+ getChars(v.articleTitle, 35) + "</a></li>";
					});
				}

				$("#articleList").html(str);
				$("#pager").pager({
							pagenumber : data.pager.currentPage,
							pagecount : data.pager.totalPages,
							itemId : itemId,
							buttonClickCallback : showArticleListPage
						});
			}, "json");
}

function changeItemPath(itemId) {
	var itemName = $("#itemid-" + itemId).text();
	var itemPath = $('#itempath').text().split(">>");
	var newItemPath = "";
	for (var i = 0; i < itemPath.length - 1; i++) {
		newItemPath += itemPath[i] + ">>";
	}
	newItemPath += itemName;
	$('#itempath').text(newItemPath);
}

// 文章查看次数
function articleLookNum(articleId) {
	var param = {
		id : articleId
	};
	$.post(basePath + "/index/lookNumArt.action", param,
			function(data, textStatus) {
				$("#looknum").html("查看次数: "+data.lookNum);
			}, "json");
}
function refreshCheckCode(div){
	$(div).html("<img  border='0' height='30' width='150' src='"+basePath+"CaptchaImg?rand="+ Math.random()+"'/>");
}
function itemInfor(itemId) {
	window.location.href = basePath + "html/itemInfor_" + itemId + "_1.html";
}
function otherUrl(url) {
	window.open(url);
}
function sendSearch(i) {
	var k = $("#keyword").val();
	// if (k == "") {
	// alert("请输入搜索关键字");
	// $("#keyword").focus();
	// } else {
	window.location.href = basePath + 'search.jsp?keyword=' + encodeURI(k);
	// }
}
function search(p, itemId) {
	var keyword = $('#searchText').val();
	if (keyword == '') {
		alert("请输入检索关键字...");
		$('#searchText').focus();
		return false;
	}
	var param = {
		currentPage : p,
		simpleFragmenterChars : 20,
		maxNumFragmentsRequired : 4,
		pageSize : 10,
		keyword : decodeURI($('#searchText').val())
	};
	var str = "";

	$.post(basePath + "index/search.action", param, function(data, textStatus) {
				$(data.list).each(function(i, v) {
					str += "<div class='searbt'><a  href='" + basePath
							+ "html/article_" + v.itemId + "_" + v.itemId + "_"
							+ v.articleId + "_" + v.createHtml
							+ ".html' target='_blank' title='" + v.articleTitle
							+ "'>" + getChars(v.articleTitle, 30)
							+ "</div><div class='searcon'><a  href='"
							+ basePath + "html/article_" + v.itemId + "_"
							+ v.itemId + "_" + v.articleId + "_" + v.createHtml
							+ ".html' target='_blank' >" + v.articleContext
							+ "..." + v.articleAddDate + "</a></div>";
				});
				$('#searchList').html(str);
				if (data.pager.totalPages > 1) {
					$("#pager").pager({
								pagenumber : p,
								pagecount : data.pager.totalPages,
								itemId : itemId,
								buttonClickCallback : search
							});
				};
			}, "json");
}
function getChars(str, size) {
	if (str.length > size) {
		return str.substring(0, size) + "...";
	}
	return str;
}
// 设为首页
function setHome(obj) {
	var url = window.location.href;
	try {
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(url);
	} 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', url);
		}
	}
}

// 加入收藏夹
function addFav() {
	if (document.all) {
		window.external.addFavorite(document.location.href, document.title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(document.title, document.location.href, "");
	}
}

function getQuerry(strname) {
	var hrefstr, pos, parastr, para, tempstr;
	hrefstr = window.location.href;
	pos = hrefstr.indexOf("?");
	var end = hrefstr.indexOf("#");
	if (end > 0) {
		parastr = hrefstr.substring(pos + 1, end);
	} else {
		parastr = hrefstr.substring(pos + 1);
	}
	para = parastr.split("&");
	tempstr = "";
	for (var i = 0; i < para.length; i++) {
		tempstr = para[i];
		pos = tempstr.indexOf("=");
		if (tempstr.substring(0, pos) == strname) {
			return tempstr.substring(pos + 1);
		}
	}
	return "";
}
