var Class = {
//创建类
 create : function () {
  return function () {
   this.initialize.apply(this, arguments);
  };
 }
};
var getA = function (a) {
//转换数组
 return a ? Array.apply(null, a) : new Array;
};
var getE = function (id) {
//获取对象
 return document.getElementById(id);
};
var Try = {
//检测异常
 these : function () {
  var returnValue, arg = arguments, lambda, i;
 
  for (i = 0 ; i < arg.length ; i ++) {
   lambda = arg[i];
   try {
    returnValue = lambda();
    break;
   } catch (exp) {}
  }
 
  return returnValue;
 }
 
};
Object.extend = function (a, b) {
//追加方法
 for (var i in b) a[i] = b[i];
 return a;
};
Object.extend(Object, {
 addEvent : function (a, b, c, d) {
 //添加函数
  if (a.attachEvent) a.attachEvent(b[0], c);
  else a.addEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
  return c;
 },
 
 delEvent : function (a, b, c, d) {
  if (a.detachEvent) a.detachEvent(b[0], c);
  else a.removeEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
  return c;
 },
 
 reEvent : function () {
 //获取Event
  return window.event ? window.event : (function (o) {
   do {
    o = o.caller;
   } while (o && !/^\[object[ A-Za-z]*Event\]$/.test(o.arguments[0]));
   return o.arguments[0];
  })(this.reEvent);
 }
 
});
Function.prototype.bind = function () {
//绑定事件
 var wc = this, a = getA(arguments), o = a.shift();
 return function () {
  wc.apply(o, a.concat(getA(arguments)));
 };
};

function openIframe(title,url,width,height){
	try{
		ymPrompt.win({
			title:title,
			message:url,
			width:width || 400,
			height:height || 300,
			handler:function(){
				
			},
			iframe:true,
			maxBtn:true,
			minBtn:true,
			showShadow:true,
			useSlide:true
		});
	}catch(err){
	}
}

function dynContent(data){
	for(var i=0;i<data.length;i++){
		var rows = data[i].rows;
		for(var j=0;j<rows.length;j++){
			var row = rows[j];
			CDrag.database.add({
		     	id:row.id,
		 		title:row.title,
		 		className:row.title,
		 		src:"",
		 		type:row.contenttype,
		 		configs:row.configs
		     });
		}
	}
	for(var i=0;i<data.length;i++){
		var cols = data[i].cols;
		var rows = data[i].rows;
		for(var j=0;j<rows.length;j++){
			var row = rows[j];
			$('#'+cols).append('<div class="block_content" id="'+row.id+'"></div>');
			var channel = getChannel(row.contenttype);
			if(row.contenttype == "newscontent"){//特别处理
				$('#'+row.id).append(channel.buildContent(row));
			}else{
				$.getJSON(
					path+'/ajax/static2dync/syncData.do',
					channel.buildParams(portal_id,row),
					function(json){
						$('#'+json.cb.block_id).append(channel.buildContent(json));
					},
					false
				);
			}
		}
	}
}

function doBarSearch(){
	var kw = $('#kwords').val();
	if(kw != ""){
		window.location.href = path+'/content/search/index.jsp?keywords='+escape(escape(kw));
	}else{
		alert("关键字不能为空！");
	}
}
//初始化动态菜单
var initMenu = function(){
	$.getJSON(
		path+'/portal/dynlayout/DynLayout.do',
		{
			method:'menu',
			portal_id:'',
			t:new Date().toString()
		},
		function(json){
			var menus = json;
			for(var i=menus.length-1;i>=0;i--){
				$('#menu_cont').append([
					'<li class="menu_li" onmouseover="this.className=\'menu_li_over\';" onmouseout="this.className=\'menu_li\';" onclick="menuClick(\''+menus[i].id+'\',\''+menus[i].url+'\',\''+menus[i].linktype+'\');">',
					'<div class="menu_dyn">',
					'<div class="cn">',
					menus[i].name,
					'</div><div style="font-size:8px;">',
						menus[i].desc,
					'</div></div></li>'
				].join(''));
			}
		}
	);
};
