
var Typee="model";
var banben="";
var fengge="";
var shoucang="";
var key="";
var Class="";
var page_size="";
var page_count="";
var page=1;
function mystop() {
        if (!!(window.attachEvent && !window.opera))
        { document.execCommand("stop"); }
        else
        { window.stop(); }
}
function add(key,value)
{
	document.getElementById(key).value = value;
	class_ar=value;
	document.getElementById("form1").submit();
}
function get_top(value)
{
	jsclaerItemtoSelect("banben");
	jsclaerItemtoSelect("fengge");
	jsAddItemToSelect("banben","所有","0");
	jsAddItemToSelect("fengge","所有","0");
	$.getJSON("get.json?type="+value+"&pos=1",
	function(data) {
	var tt="";
	for(var i=0;i<data.length;i++){
		if(data[i].Class==1){
			jsAddItemToSelect("banben",data[i].name,data[i].id);
		}else{
			jsAddItemToSelect("fengge",data[i].name,data[i].id);
		}
	}
	}
	);
}
function get_tree(value)
{
$.getJSON("get.json?type="+value+"&pos=2",
	function(data) {
		var tt="";
		d = new dTree('d');
		d.add(0,-1,'资源列表',"JavaScript:set_Class(0)");
		for(var i=0;i<data.length;i++){
			d.add(data[i].id,data[i].cengji,data[i].file,"JavaScript:set_Class("+data[i].id+")");
		}
		document.getElementById("treeview").innerHTML=d;
	});
}
function set_Class(e){
	Class=e;
	document.getElementById('iframe1').contentWindow.document.getElementById('Class').value=Class;
	if(e!="0"){
		for (var i in d.aNodes){
			if(d.aNodes[i].pid==e){
				Class+=","+(d.aNodes[i].id);
			}
			if(d.aNodes[i].id==e){
				try{d.o(i);}catch(e){}
			}
		}
	}else{Class="";}
	document.getElementById("class").value=Class;
	document.getElementById("page").value=1;
	get_item(get_());
}
function get_item(obj){
	var txt = "";
	$.getJSON("get.json?pos=3", obj, function (data) {

		if (data.info.page !== "0") {
			document.getElementById("listview").innerHTML = "";
			document.getElementById("page").value = data.info.page;
			document.getElementById("page_size").value = data.info.page_size;
			document.getElementById("page_count").value = data.info.page_count;

			document.getElementById("xinxi").innerHTML = "共" + data.info.items_count + "条记录 每页" + data.info.page_size + "条 共" + data.info.page_count + "页";
			

	            for (var i = 0; i < data.items.length; i++) {

	                txt += "<div class=\"picbox\"><span><a href=\"" + (data.items[i].pic) + "&p=l\" class=\"highslide\" onclick=\"return hs.expand(this)\">  <img  height=\"200\" width=\"200\" src=\"" + (data.items[i].pic) + "\" alt=\"\" title=\"ID:" + (data.items[i].id) + "  名字:" + (data.items[i].name) + "\" /> </a><div class=\"highslide-caption\">id:" + (data.items[i].id) + "<br>名字:" + (data.items[i].name) + "<br>关键字:" + (data.items[i].Info) + "</div></span><br><div class=\"downname\"><a target=\"_blank\"  href=\"" + (data.items[i].file) + "\">" + (data.items[i].name) + "</a></div></div>";
	         
			}

			txt += "<div style=\"clear: both;\"/>";
			 //$("#listview").append(txt);
			document.getElementById("listview").innerHTML = txt;
			

		} else document.getElementById("listview").innerHTML = "<div>没有找到相关素材</div>";
	    });
}
function get_(){
	//banben=get_select_value("banben");
	//fengge=get_select_value("fengge");
	shoucang=get_select_value("shoucang");
	key=encodeURI(document.getElementById("key").value);
	Class=document.getElementById("class").value;
	
	page_size=document.getElementById("page_size").value;
	page_count=document.getElementById("page_count").value;
	page=document.getElementById("page").value;
	var t="type="+Typee+
		//"&banben="+	banben+
		//"&fengge="+	fengge+
		"&shoucang="+ shoucang+
		"&key="+ key+
		"&Class="+ Class+
		"&page_size="+page_size+
		"&page_count="+page_count+
		"&page="+ page;
	return (t);
}
function submit_post(){
	console.log(Typee);
	console.log(Class);
	window.scrollTo(0,0);
	get_tree(Typee);
	//get_top(Typee);
	get_item(get_());
}

function submit_post2() {get_item(get_());}

function set_page(value){
	switch (value) {
		case 0:
			document.getElementById("page").value = "1";
			submit_post2()
			break;
			case -1:
			var t=parseInt(document.getElementById("page").value)-1;
			if (t>0) {
				document.getElementById("page").value=t;
				submit_post2()
			}
		break;
		case 1:
			var t=parseInt(document.getElementById("page").value)+1;
			if (t>0) {
				document.getElementById("page").value=t;
				submit_post2()
			}
		break;
		case 2:
			var t=parseInt(document.getElementById("page_count").value);
			if (t>0) {
				document.getElementById("page").value=t;
				submit_post2()
			}
		break;
		default:break;
	}
}

function type_sel(value){
	Typee=value;
	document.getElementById('iframe1').contentWindow.document.getElementById('Type').value=Typee;
	//set_select_value("banben",0)
	//set_select_value("fengge",0)
	set_select_value("shoucang",0)
	document.getElementById("page").value=1;
	document.getElementById("key").value="";
	document.getElementById("class").value="";
	submit_post();
}

function get_select_value(sel){
	try{
		var t =document.getElementById(sel);
		return selectValue=t.options[t.selectedIndex].value;
	}catch(e){return "0";}

}

function set_select_value(sel,sel_value){
	var t1 = document.getElementById(sel);
	for(i=0;i<t1.length;i++){
		if(sel_value==t1.options[i].value){
			t1.options[i].selected=true
		}
	}
}

function jsAddItemToSelect(objSelect, objItemText, objItemValue) {
	var t=document.getElementById(objSelect);
	var varItem = new Option(objItemText, objItemValue);
	t.options.add(varItem);
}

function jsclaerItemtoSelect(objSelect) {document.getElementById(objSelect).options.length = 0;} 

/** 翻页 */	   
var wheel_c=0;
function handle(delta){
	wheel_c++;
	if(wheel_c>1){
		wheel_c=0;
		var scrollTop = $(this).scrollTop();
		var scrollHeight = $(document).height();
		var windowHeight = $(this).height();
		if (delta > 0){
			if(scrollTop  == 0){
				set_page(-1);
				return;
			}
		}else{
　　			if(scrollTop + windowHeight == scrollHeight){
				set_page(1);return;
			}		
		}
	}
}

/** 翻页 */
function wheel(event){
	var delta = 0;
	if (!event) /* For IE. */
		event = window.event;
	if (event.wheelDelta) { 
		/* IE或者Opera. */
		delta = event.wheelDelta / 120;
		/** 在Opera9中，事件处理不同于IE*/
	if (window.opera)
		delta = -delta;
	} else if (event.detail) { 
	/** 兼容Mozilla. */
	delta = -event.detail / 3;
	}
	/** 如果 增量不等于0则触发 主要功能为测试滚轮向上滚或者是向下*/
	if (delta){
		
		handle(delta);return;
	}
}
 
function ld(){
	// var element = document.createElement("script");
	//element.src = "get.hbjs?dir=/highslide/highslide-with-gallery.js|/highslide/yulan.js";
	// document.body.appendChild(element);
	get_item(get_());
	get_tree(Typee);
	//get_top(Typee);
	/** 初始化 */
	if (window.addEventListener){
		/** Mozilla的基于DOM的滚轮事件 **/
		window.addEventListener("DOMMouseScroll", wheel, false);
		/** IE/Opera. */
		window.onmousewheel = document.onmousewheel = wheel;
	}
}


//上传

	
  	 function show()
   	 {
		var upd = document.getElementById('updiv');
		//var overd = document.getElementById('over');
   	     upd.style.display = "block";
   	     //overd.style.display = "block";
		document.getElementById('iframe1').contentWindow.document.getElementById('Type').value=Typee;
		document.getElementById('iframe1').contentWindow.document.getElementById('Class').value=Class;
    	}

   	 function hide()
   	 {
		var upd = document.getElementById('updiv');
		//var overd = document.getElementById('over');
   	     upd.style.display = "none";
   	     //overd.style.display = "none";
   	 }
