﻿/*
 * Pomoho UI
 *
 * Copyright (c) 2007 sorrycc@gmail.com (pomoho.com)
 * Date: 2007-10-29
 */

(function ($){
	var Pui=window.Pui={
		init:function (){
			baseurl='http://www.pomoho.com/do/';
			document.write('<div style="overflow:hidden;height:0;"><img src="http://static.pomoho.com/themes/site/200708/images/public/msg_btn.gif" /><img src="http://static.pomoho.com/themes/site/200708/images/public/msg_close.gif" /><img src="http://static.pomoho.com/themes/site/200708/images/public/msg_page.gif" /></div>');
			_user={
				uid:0,nick:'',spacename:'',newmsg:0
			};
			_is_login=false;
			var n=this.cookie('LoginInfo');
			if(n){
				var arr=n.split('$***$');
				_user={
					uid:arr[0].replace('LoginInfo=',''),nick:arr[1],spacename:arr[2],newmsg:0
				};
				_is_login=true;
				if(Pui.cookie('NewMsgCount'+_user.uid)){
					_user.newmsg=Pui.cookie('NewMsgCount'+_user.uid);
					msg='unread';
					
				}else {
					msg=(_user.newmsg==0)?'empty':'unread';
					
				}
			}
			//解决IE6不缓存超链接中背景图片的BUG
			try {
				document.execCommand('BackgroundImageCache', false, true);
			} catch(e) {}
		},
		initUser:function (){
			this.init();
			
		},
		initManage:function (id){
			if(typeof(id)!='undefined'&&_user.uid!=parseInt(id))document.write('<style type="text/css">.is_login { display:none; }</style>');
			
		},
		cookie:function (name,value,options){
			if(typeof(value)!='undefined'){
				options=options||{
					
				};
				if(value===null){
					value='';
					options.expires=-1;
					
				}var expires='';
				if(options.expires&&(typeof(options.expires)=='number'||options.expires.toUTCString)){
					var date;
					if(typeof(options.expires)=='number'){
						date=new Date();
						date.setTime(date.getTime()+(options.expires*24*60*60*1000));
						
					}else {
						date=options.expires;
						
					}expires='; expires='+date.toUTCString();
					
				}var path=options.path?'; path='+options.path:'';
				var domain=options.domain?'; domain='+options.domain:'';
				var secure=options.secure?'; secure':'';
				document.cookie=[name,'=',escape(value),expires,path,domain,secure].join('');
				
			}else {
				var cookieValue=null;
				if(document.cookie&&document.cookie!=''){
					var cookies=document.cookie.split(';');
					for(var i=0;i<cookies.length;i++){
						var cookie=jQuery.trim(cookies[i]);
						if(cookie.substring(0,name.length+1)==(name+'=')){
							cookieValue=unescape(cookie.substring(name.length+1));
							break;
							
						}
					}
				}return cookieValue;
				
			}
		},
		loadScript:function (url,options){
			var setting={
				random:true
			};
			if(options){
				$.extend(setting,options);
				
			}var f=document.createElement('script');
			f.type='text/javascript';
			var d=new Date();
			if(setting.random){
				if(url.match(/.*\?./)){
					url=url+'&random='+d.getTime()+parseInt(Math.random()*10000);
					
				}else {
					url=url+'?random='+d.getTime()+parseInt(Math.random()*10000);
					
				}
			}f.src=url;
			$('head')[0].appendChild(f);
			
		},
		callback:function (msg){
			alert(msg);
			
		},
		wFlash:function (options){
			var setting={
				url:'',w:0,h:0
			};
			if(options){
				$.extend(setting,options);
				
			}var s='';
			s+='';
			s+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+setting.w+'" height="'+setting.h+'">';
			s+=' <param name="movie" value="'+setting.url+'" />';
			s+=' <param name="quality" value="high" />';
			s+=' <param name="allowScriptAccess" value="always" />';
			s+=' <param name="wmode" value="transparent" />';
			s+=' <embed wmode="transparent" src="'+setting.url+'" quality="high" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+setting.w+'" height="'+setting.h+'"></embed>';
			s+='</object>';
			document.write(s);
			
		},
		ui:function (){
			return {
				bookmark:function (title,url){
					if($.browser.msie){
						window.external.AddFavorite(url,title);
					}else if($.browser.mozilla){
						window.sidebar.addPanel(title,url,'');
					}
				},setHome:function(url){
			        try{
		                document.body.style.behavior='url(#default#homepage)';
		                document.body.setHomePage(url);
			        }
			        catch(e){
		                if(window.netscape) {
	                        try{
	                            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
								var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
								prefs.setCharPref('browser.startup.homepage','http://www.pomoho.com');
	                        }
	                        catch(e) { 
	                            alert("不好意思，此操作被浏览器拒绝……\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'\n或者直接在选项中设置首页。多谢支持爆米花的产品。");
	                        }
		                 }
			        }
				},gettime:function (){
					var time=new Date();
					var t_year=($.browser.msie)?time.getYear():String(time).split(" ")[3];
					var t_time=($.browser.msie)?String(time).split(" ")[3].substr(0,5):String(time).split(" ")[4].substr(0,5);
					var f_time=t_year+"-"+parseInt(time.getMonth()+1)+"-"+time.getDate()+" "+t_time;
					return f_time;
					
				},setServerTime:function (time){
					_servertime=time;
					
				},loadServerTime:function (){
					Pui.loadScript("http://www.pomoho.com/do/time/echo_second.aspx");
				}
			};
			
		}(),
		pos:{
			elementTop:function (element){
				var y=0;
				for(var e=element;e;e=e.offsetParent)y+=e.offsetTop;for(e=element.parentNode;e&&e!=document.body;e=e.parentNode)if(e.scrollTop)y-=e.scrollTop;return y;
			}
		}
	};
	Pui.init();
	Pui.showData=function (json){
		var path={
			user:['.t_login span','.c_friend span','.c_fans span','.c_view span','.c_video span','.c_flower span'],video:['.c_view span','.c_review span','.c_bookmark span'],special:['.c_video span','.c_view span','.c_rss span','.t_update span','.t_length span'],combo:['.d_video span','.d_collect span','.d_topic span','.d_menber span','.d_album span','.d_mvvideo span'],combo_handle:['.c_num','.c_num_m']
		};
		var path_n={
			user:['.d_time_login span','.d_friend span','.d_fans span','.d_view span','.d_video span','.d_flower span'],video:['.d_view span','.d_review span','.d_bookmark span'],special:['.d_video span','.d_view span','.d_rss span','.d_update span','.d_length span'],combo:['.d_video span','.d_collect span','.d_topic span','.d_menber span','.d_album span','.d_mvvideo span']
		};
		$('.t_login').html('最近登录：<span></span>');		for(var i=0,length=json.length;i<length;i++){
			var type=json[i].type,id=json[i].id,data=json[i].data,wrap='#'+type+'_'+id;
			if(!$(wrap)[0])continue;
			for(j=0;j<path[type].length;j++){
				if($(wrap+' '+path[type][j])[0]){
					$(wrap+' '+path[type][j])[0].innerHTML=data[j];
					
				}else if($(wrap+' '+path_n[type][j])[0]){
					$(wrap+' '+path_n[type][j])[0].innerHTML=data[j];
					
				}
			}
		}
	};
	$.fn.toggleShow=function (options){
		var o={
			el:'.mUser',cls:'current'
		};
		if(options)$.extend(o,options);
		return $(this).each(function (){
			$(this).find(o.el).mouseover(function (){
				if($(this).attr('class').indexOf(o.cls)!=-1)return ;
				$(this).parent().find('.'+o.cls).removeClass(o.cls);
				$(this).addClass(o.cls);
				
			});
			
		});
		
	};
	$.fn.tab=function (){
		var t_timer=null;
		var delay=150;
		return this.each(function (){
			$(this).find("dt").hover(function (){
				t_current=this;
				clearTimeout(t_timer);
				t_timer=setTimeout("$.changeTab(t_current)",delay);
				
			},function (){
				clearTimeout(t_timer);
			}).find('a').click(function(){
				$(this).blur();
				return false;
			});
			
		});
		
	};
	jQuery.extend({
		mousepos:function (e){
			var d=document.documentElement,b=document.body;
			return [e.pageX||(d.scrollLeft||b.scrollLeft)+e.clientX,e.pageY||(d.scrollTop||b.scrollTop)+e.clientY];
			
		},stopBubble:function (e){
			e?e.stopPropagation():window.event.cancelBubble=true;
			
		},changeTab:function (e){
			$(e).parent().find(".ac").toggleClass("ac").next().toggle();
			$(e).blur().toggleClass("ac").next().toggle();
			
		}
	});
	
})(jQuery);

Pui.header1 = {
	init:function(){
		this.Main();
	},
	Main: function(){
		//$('#Search .iBtn').hover(function(){//搜索按钮悬停效果
		//	$(this).css('background-position','-90px -141px');
		//},function(){
		//	$(this).css('background-position','-69px -141px');
		//});
		//this.OnLoad();
		this.SelectEvents();
		this.showMore();
	},
	OnLoad: function(){
		var defalt_val = '搜一下';
		$('#SearchInput').val(defalt_val).focus(function(){//搜索框
			var val = $(this).val();
			if(val == defalt_val){
				$(this).val('');
			}
		}).blur(function(){
			var val = $(this).val();
			if(val == ''){
				$(this).val(defalt_val);
			}
		});
	},
	//模拟Select上的点击事件
	SelectEvents: function(){
		$('body').click(function(){
			if( $('#SelDiag').css('display') != 'none' ){//点击Body自动收回
				$('#SelDiag').slideUp('fast');
			}
		});
		/*$('.btnSel a').toggle(function(){//选择箭头上的点击事件
			$('#SelDiag').show('fast');
			this.blur();
			return false;
		}, function(){
		    $('#SelDiag').hide('fast');
		    this.blur();
			return false;
		});*/
		$('.btnSel a').click(function(){
			if( $('#SelDiag').css('display') != 'none' ){
				$('#SelDiag').slideUp('fast');
			}
			else{$('#SelDiag').slideDown('fast');}
			return false;
		});
		$('#SelDiag1').click(function(){//弹出Div上的点击事件，以下4项
			Pui.header1.SelectDiag('video',$(this));
			this.blur();
			return false;
		});
		$('#SelDiag2').click(function(){
			Pui.header1.SelectDiag('user',$(this));
			this.blur();
			return false;
		});
		$('#SelDiag3').click(function(){
			Pui.header1.SelectDiag('subject',$(this));
			this.blur();
			return false;
		});
	},
	//弹出Div上的点击事件过程
	SelectDiag: function(searchType,href){
		$('#SearchType').val(searchType);
		$('#SelDiag').css('display','none');
		$('#Selected').text($(href).text());
		$('#SearchT').focus();
	},
	showMore:function(){
		$('#Menu li:last a').click(function(){
			if($('.morelist').css('display')!='none'){$('.morelist').css('display','none');;$('#Menu li:last a strong').html('▼');}
			else{$('.morelist').css('display','block');$('#Menu li:last a strong').html('▲');}
			return false;
		});
		$('body').click(function(){
			$('.morelist').css('display','none');
			$('.morelist').css('display','none');;$('#Menu li:last a strong').html('▼');
		});
	},
	//搜索表单提交事件过程
	DoSearch: function(o){
		var val = $(o).find('#SearchInput').val();
		if(val==''||val=='搜一下'){
			alert('对不起，关键词不能为空，请重新输入');
			$('#SearchInput').focus();			
			return false;
		}else{
			var sdi = o.searchDomain;
			var sd = "http://search.pomoho.com";
			if(sdi != undefined && sdi.value != ""){
				sd = sdi.value;
			}
			var key = encodeURIComponent(val);
			var url = sd+"/"+ o.searchType.value +"search.aspx?_keyword="+key;
			if (document.location.hostname.indexOf("search.pomoho.com") != -1) 
			{
				document.location.href = url;
			}
			else
			{
				window.open(url, 'search');
			}
			return false;
		}
	},
	Search:function(val) {
		if(val==''){		
			return false;
		}else{
			var sd = "http://search.pomoho.com";
			var key = encodeURIComponent(val);
			var url = sd+"/videosearch.aspx?_keyword="+key;
			if (document.location.hostname.indexOf("search.pomoho.com") != -1) 
			{
				document.location.href = url;
			}
			else
			{
				window.open(url, 'search');
			}
			return false;
		}
	}
};


/***** pui.header_v2 ***************************************************/

$(function(){Pui.header1.init();})/*ransiwei 20090508*/
Pui.header=Pui.header_v2 = Pui.newSH = {
	init:function(){//是否登录
		_user = { uid:0, nick:'onemax', spacename:'', newmsg:0};
		_is_login = false;
		var n = Pui.cookie('LoginInfo');
		if (n) {
			var arr = n.split('$***$');
			_user = { uid:arr[0].replace('LoginInfo=', ''), nick:arr[1], spacename:arr[2], newmsg:0,spaceurl:arr[3] };
			_is_login = true;
			this.islogin();
		}else{
			this.unlogin();
		};
		this.doSearch();
		this.router();
	},
	router:function(){
			var pageType = "";
			var n = null;
  		var bodyID = document.body.id.toLowerCase();
  		var hostName = window.location.hostname;
  		if ( bodyID != "" )
  		{	
  			if( bodyID == "b-index" )
  			{
  					pageType = "index";
  					n = Pui.cookie('router');
  			}
  			else
  			{
  				if ( bodyID.lastIndexOf('-') > 1  && bodyID.indexOf('-index') > 2)
					{
						pageType = bodyID.substr(bodyID.indexOf('b-')+2,bodyID.indexOf('-index')-2);
						if(pageType=="car")
						{
			   			pageType="auto";
						}
						n = Pui.cookie('router');
					}
				}
  		}
  		
			if (n != null) {
				 if( n == "router=true" ) 
				 { 
				  	if( pageType == "index" ){
				  		 window.location = "http://pomoho.gogochannel.com/" ; 
				  	}
				  	else
				  	{
				  		 window.location = "http://pomoho.gogochannel.com/"+pageType ; 
				  	}
				 }
			}
	},
	checkrouter:function(){
			var pageType = "";
  		var bodyID = document.body.id.toLowerCase();
  		var hostName = window.location.hostname;
  		if ( bodyID != "" )
  		{	
  			if( bodyID == "b-index" )
  			{
  					pageType = "index";
  					Pui.loadScript("http://www.pomoho.com/do/interfaces/router.aspx?pagetype="+pageType+""); 
						this.router();
  			}
  			else
  			{
  				if ( bodyID.lastIndexOf('-') > 1  && bodyID.indexOf('-index') > 2)
					{
						pageType = bodyID.substr(bodyID.indexOf('b-')+2,bodyID.indexOf('-index')-2);
						if(pageType=="car")
						{
			   			pageType="auto";
						}
						Pui.loadScript("http://www.pomoho.com/do/interfaces/router.aspx?pagetype="+pageType+""); 
						this.router();
					}
				} 
				if(document.location.hash == "#test")
				{ 	
						alert("bodyID="+bodyID+",pageType="+pageType);
				}
			}
	},
	unlogin:function(){
		var str='';
		str+='<li class="s"><a target="_blank" class="f" title="返回首页" href="http://www.pomoho.com/">返回首页</a></li>';
		str+='<li class="s"><a class="f" title="登录" href="javascript:Pui.header.loginfo()">登录</a></li>';
		str+='<li class="s logout"><a class="f" title="注册" href="http://www.pomoho.com/ui/reg.aspx" target="_blank">注册</a></li>';
		$("#TopNav").html(str);
		
	},
	islogin:function(){
		var t_time=this.localTime();
		var str='';
		str+='<ul><li class="s3 upLoad"><a href="http://www.pomoho.com/upload/" target="_blank">上传视频</a></li></ul>';
		str+= '<ul id="TopNav">';
		str+= '<li class="s" >'+t_time+'，<a class="user" target="_blank" href="http://home.pomoho.com/'+_user.spaceurl+'.shtml" title="'+_user.nick+'" >'+Pui.header.SetString(_user.nick,10)+'</a></li>';
		str+= '<li class="s"><a class="count" title="你的帐户" href="http://www.pomoho.com/manage/index.aspx" target="_blank" >帐户</a>';
		str+= '   <div class="d s3">';
		str+= '     <ul>';
		str+= '       <li><a class="d_item" title="我的视频" href="http://www.pomoho.com/manage/managevideo.aspx" target="_blank" >我的视频</a></li>';
		str+= '       <li><a class="d_item" title="我的订阅" href="http://www.pomoho.com/manage/subscribevblog.aspx" target="_blank" >我的订阅</a></li>';
		str+= '       <li><a class="d_item" title="我的收藏" href="http://www.pomoho.com/manage/managevideo.aspx?type=favs" target="_blank" >我的收藏</a></li>';
		str+= '       <li><a class="d_item" title="我的相册" href="http://www.pomoho.com/manage/managealbum.aspx" target="_blank" >我的相册</a></li>';
		str+= '     </ul>';
		str+= '     <div class="m1"><a title="更多管理" href="http://www.pomoho.com/manage/index.aspx" target="_blank" >更多..&nbsp;&nbsp;</a></div>';
		str+= '   </div>';
		str+= ' </li>';
		str+= ' <li class="s"><a class="msg" title="你的消息" href="http://www.pomoho.com/manage/messagelist.aspx?type=1" target="_blank" >消息</a><span>(0)</span>';
		str+= '   <div class="d s2">';
		str+= '     <div class="title"><div class="d_video">主题</div><div class="d_author">消息来源</div></div>';
		str+= '     <ul>';
		str+= '     </ul>';
		str+= '     <div class="m"><a title="全部消息" href="http://www.pomoho.com/manage/messagelist.aspx?type=1" target="_blank" >全部消息&gt;&gt;</a></div>';
		str+= '   </div>';
		str+= ' </li>';

		str+= ' <li class="logout"><a title="退出登录" href="http://www.pomoho.com/ui/logout.aspx?AfterLoginReturnURL='+window.location+'" >退出</a></li>';
		str+= ' </ul>';
		$("#L").removeClass().html(str);
		this.SH();
		Pui.loadScript("http://notice.pomoho.com/loadmessage2.0.aspx");
	},
	SH:function(){
		var tim;	
    	$("#TopNav .s").hover(function(){
			$(this).siblings().find(".d").hide();
    		$(this).find(".d").show();
    		clearTimeout(tim);
		},function(){
    		tim=setTimeout(overDiv,500);
    		function overDiv(){
    		$("#TopNav").find(".d").slideUp();
		}
		});
    },
    localTime:function(){
		var time = new Date();
		var hour = time.getHours();
		var t_time = ($.browser.msie) ? String(time).split(" ")[3].substr(0,5) : String(time).split(" ")[4].substr(0,5);
		switch (hour){
			case 0:	case 1:	case 2:	case 3:	case 4:	case 5:	case 6:	case 7:
				t_time='早上好';
				break;
			case 8:	case 9:	case 10:case 11:
				t_time='上午好';
				break;
			case 12:
				t_time='中午好';
				break;
			case 13:case 14:case 15:case 16:case 17:
				t_time='下午好';
				break;
			case 18:case 19:case 20:case 21:case 22:case 23:
				t_time='晚上好';
				break;
		}
		return  t_time;
      },
      Msginit:function(jsonMsg){
	     	//var jsonMsg=[6,{msgtitle:"标题",msgtype:1,msgid:454},{msgtitle:"标题",msgtype:2,msgid:454},{msgtitle:"标题",msgtype:3,msgid:454},{msgtitle:"标题",msgtype:2,msgid:454},{msgtitle:"标题",msgtype:1,msgid:454}];
	        var str='';
	        var len=jsonMsg.length;
	        if(len<=1) 
	        {
	        	var str='<li style="width:100%">您还没有消息</li>';
	        }else{
		        for(var i=1;i<=len-1;i++)
		        {
		        	var msgtypename;
			        	switch(jsonMsg[i].msgtype)
			        {
			        	case 1:
							msgtypename="站内消息"
							break;
						case 2:
							msgtypename="系统消息"
							break
						case 3:
							msgtypename="公告"
							break
					}
			        str+= '<li id="msg'+i+'">';
					if(jsonMsg[i].msgtype!=3){
				    str+= '<div class="d_video"><a title="'+jsonMsg[i].msgtitle+'" href="http://www.pomoho.com/manage/readmessage.aspx?receiveid='+jsonMsg[i].msgid+'&rettype=1" target="_blank" >'+jsonMsg[i].msgtitle+'</a></div>';
					}else{
				    str+= '<div class="d_video"><a title="'+jsonMsg[i].msgtitle+'" href="http://www.pomoho.com/manage/readmessage.aspx?bulletinid='+jsonMsg[i].msgid+'&rettype=1" target="_blank" >'+jsonMsg[i].msgtitle+'</a></div>';
					}

				    str+= '<div class="d_author">'+msgtypename+'</div>';
				    str+= '<a class="d_close" title="删除消息" href="javascript:Pui.header.Msgdel('+jsonMsg[i].msgid+','+jsonMsg[i].msgtype+','+i+')" ></a> </li>';
			     }
			}     
	         $("#TopNav .s2 ul").html(str);
	        $("#TopNav .s2").parent().find("span").html("("+jsonMsg[0]+")");      
    },
    Msgdel:function(msgid,msgtype,num){
			$("#msg"+num).remove();												        	      		
  		    var Msgurl="http://notice.pomoho.com/readmessage.aspx?messageID="+msgid+"&Userid="+_user.uid+"&messageType="+msgtype;
  		    Pui.loadScript(Msgurl);
  		     var num=parseInt($("#TopNav .s2").parent().find("span").html().substr(1))-1;
  		     if (num<=0) num=0;
  		     $("#TopNav .s2").parent().find("span").html("("+num+")"); 
    },
    doSearch:function(e){
			if (typeof(s)!='undefined') return
				else s=1;
    		$("#goSearch").click(function(){
				var values=$.trim($("#searchGame").val());
					if(!values) {
						alert("关键字不能为空");
						$("#searchGame").focus();
					}else{
						var param=encodeURIComponent(values.replace(/[\/_]/g,' '));
						var url="http://search.pomoho.com/videosearch.aspx?_keyword="+param;
						window.open( url, 'search' ); 
					}
			});
    },
    /******add for login*******************/
    logDiv:function(sType, sTarget, sUrl, callback){
		var str='';
		if($.browser.msie && String($('body').attr('id')) == 'B-Upload'){
			str+='';
		}else{
			if($.browser.msie){
				str+='<iframe id="zhezhao"></iframe>';
			}else{
				str+='<div id="zhezhao"></div>';
			}
		}
		str+='	<div id="Prompt" class="prompt">';
		str+='		  <div class="k log_v">';
		str+='		    <div class="meat">';
		str+='		      <div class="close"><img alt="关闭" src="http://static01.pomoho.com/themes/site/default/images/games/close.gif" width="16" height="16" /></div>';
		str+='		      <h3></h3>';
		str+='		      <p class="p2">您的帐号：';
		str+='		        <input id="uidName" type="text" onkeyup="Pui.header.submitF(event)" />';
		str+='		      </p>';
		str+='		      <p class="p2">登录密码：';
		str+='		        <input id="uidPwd" type="password" onkeyup="Pui.header.submitF(event)" />';
		str+='		        <a href="http://www.pomoho.com/ui/findpassword.aspx" target="_blank">忘记密码</a></p>';
		str+='		      <p class="pbt">';
		str+='		        <input id="btnlog" class="log" type="submit" value="登录" />';
		str+='		        <input id="reg" class="log" type="button" value="注册" />';
		str+='		      </p>';
		str+='		    </div>';
		str+='		  </div>';
		str+='		</div>';
		$("body").prepend(str);
		
        if($.browser.msie && String($('body').attr('id')) == 'B-Upload'){
        	Pra.ui.overlay();
      	 }else{
      	 	if($.browser.msie){
				var cw = window.frames['zhezhao'];
				cw.document.open();  
				cw.document.write('<style type="text/css">body{background:#000;}</style>');   
				cw.document.close();
			}
		}

		$("#Prompt .close img").bind("click",Pui.header.closeDiv);
		$("#btnlog").click(function(){
			Pui.header.login(sType, sTarget, sUrl, callback);
		});
		$("#reg").click(function(){
			window.open('http://www.pomoho.com/ui/reg.aspx');
		});	
	},
	showLogDiv:function(sType,sTarget,sUrl, callback){
			if(String($('body').attr('id')) == 'B-Upload'){
				Pui.header.logDiv(sType,sTarget,sUrl, callback);
			}else if(!$("#Prompt").length){
				Pui.header.logDiv(sType,sTarget,sUrl, callback);
			}
			var doc=document;
			var docElement=doc.documentElement;
			var sHeight=docElement.clientHeight;
			var dH=docElement.scrollHeight>sHeight?docElement.scrollHeight:sHeight;
			var scH=docElement.scrollTop>=0?(docElement.scrollTop+sHeight/2):sHeight;
			var h=scH-$("#Prompt").height()/2;
			var w=docElement.clientWidth/2-$("#Prompt").width()/2;
			$("#zhezhao").height(dH).show();
			$("#Prompt").css({top:h,left:w});
	},
	loginfo:function(sType,sTarget,sUrl, callback){
			Pui.header.showLogDiv(sType,sTarget,sUrl, callback);
			$("#Prompt").show();
			$("#Prompt .k")[0].className="k log_v";
			$('#uidName').focus();//2008-9-11 21:59:45 By SMbey0nd	
			if(document.attachEvent){
				document.attachEvent('onkeyup',Pui.header.EXC);
			}else{
				document.addEventListener('keyup',Pui.header.EXC,false)
			}															
	},
    loginfo2:function(callback, sType, sTarget, sUrl){
			this.loginfo(sType, sTarget, sUrl, callback);
	},
	loginfo2_callback:function(json) {
	    window.location.href = "http://www.pomoho.com/manage/index.aspx";
	},
	submitF:function(e){
		var event = window.event || e;
		if(event.keyCode==13)
			$("#btnlog").click();
	},
	EXC:function(e){
		var event = window.event || e;
		if(event.keyCode==27)
			Pui.header.closeDiv();
	},
	login:function(sType,sTarget,sUrl,callback){
			var userName=$.trim($("#uidName").val());
				var pwd=$("#uidPwd").val();
				
				if(userName==''||pwd==''){
					alert("用户名或者密码不能为空");
				}else{
					if(sType||sUrl){
						Pui.ui.logDiagAjax(userName, pwd, sType, sTarget, sUrl, callback);
					}else{
						Pui.header.logAjax(userName, pwd, callback);
					}
				}

	},	
	closeDiv:function(){
			if($.browser.msie && String($('body').attr('id')) == 'B-Upload'){
	        	Pra.ui.overlay();
	        }else if(String($('body').attr('id')) == 'B-Upload'){
				$("#zhezhao").remove();
			}else{
				$("#zhezhao").hide();
			}
			$("#Prompt").hide();
	},
	logAjax:function(userName, pwd, callback){
			var urlRoot = window.location.hostname;
			var urlString=window.location.toString ().toLowerCase();
			var urlstr;
			if(urlString.indexOf("video.pomoho.com/")==-1){
				urlstr="/do/interfaces/sendajaxreq.aspx";
			}else{
				urlstr="/sendajaxreq.aspx";
			}

			$.ajax({
		    url:"http://" + urlRoot + urlstr,//根目录放置sendajaxreq.aspx
		    //url:"http://www.pomoho.com/do/interfaces/sendajaxreq.aspx",
		    dataType: "xmlDocument",
		    type:"post",
		    data: "action=http://www.pomoho.com/ui/logindo.aspx&form_name="+userName+"&form_password="+pwd+"&type=gamelogin&random="+Math.random(),
		    error: function(){ alert('可能网络问题,登录失败,请重试!');Pui.header.closeDiv(); },
		    success: function(result){
		    	var userlog=eval(result);
		   		 //1表示登录成功,-1表示登录帐号不存在,-2表示用户名或者密码错误,-3表示用户名或者密码为空
				switch (parseInt(userlog[0].stat)){
				case -1:
					alert("登录帐号不存在");
					break;
				case -2:
					alert("用户名或者密码错误,请重试");
					break;	
				case 1:
					Pui.header.cookie('UserInfo',userlog[1].UserInfo,{path:'/',domain:'.pomoho.com',expires: 1/6 });	
					Pui.header.cookie('LoginInfo',userlog[2].LoginInfo,{path:'/',domain:'.pomoho.com',expires: 1/6 });
					var urlString = window.location.toString().toLowerCase();
					if(urlString.indexOf("pomoho.com/combo")!=-1&&(typeof(flag)=='undefined'||flag==null))
					{
						window.location.reload();
						return
					}
					Pui.header.init();
					if( String($('body').attr('id')) == 'B-Upload' && document.getElementById("hid_n").value=="true" && (typeof(flag)=='undefined'||flag==null) )
					{
						document.getElementById("FrameUpload").contentWindow.Pui.upload.unite('GoTo2');
						document.getElementById("FrameUpload").contentWindow.start_upload(
							document.getElementById("FrameUpload").contentWindow.$('#file1').val(),
							document.getElementById("FrameUpload").contentWindow.$('#uploadForm_Title').val()
						);
						if(document.getElementById("FrameUpload").contentWindow.$('#hid_ver').val() == 'family'){
							document.getElementById("FrameUpload").contentWindow.$('#Upload_2 .s4').addClass('none');
							document.getElementById("FrameUpload").contentWindow.$('#Upload_2 .s5').addClass('none');
							$('#Layout_1').height('650px');
						}else{
							$('#Layout_1').height('700px');
						}
					}
					if(typeof(flag)=='undefined'||flag==null)
						Pui.header.closeDiv();	//flag=1:转发给好友,flag=2:收藏,flag=3:加为好友,flag=4:加入社团
					else if(flag==1)
						{
							Pui.user.haveFriend();
							flag=null;
						}
					else if(flag==2)
						{
							Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=2&imdbid=" + flvid);
							flag=null;
							Pui.header.closeDiv();
						}
					else if(flag==3)
						{
							f_addfriend(_userid);
							flag=null;
							Pui.header.closeDiv();
						}
					else if(flag==4)
						{
							flag=null;
							Pui.header.closeDiv();
							f_comboInterFace(addPram.otype,addPram.atype,addPram.comboid,_user.uid);
							Pui.header.closeDiv();
						}
					else if(flag==5)
						{
							flag=null;
							Pui.ReUrl(pathUrl);
							Pui.header.closeDiv();
						}		
					else if(flag==6)
						{
							flag=null;
							Pui.header.closeDiv();
							DoMovieAction(_subjectID,_emitStatus );
						}
					if ('undefined' != typeof(callback)) {
					    callback();
					}
					break;
				default:
					alert("系统错误,请重试，错误代码："+userlog[1].ErrMsg);
					Pui.header.closeDiv();
				}
		 	}
		});	
	},
	
	cookie: function(name, value, options) {
		if (typeof(value) != 'undefined') {
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString();
			}
			var path = options.path ? '; path=' + options.path : '';
			var domain = options.domain ? '; domain=' + options.domain : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', name+'='+value, expires, path, domain, secure].join('');
			} else {
				var cookieValue = null;
				if (document.cookie && document.cookie != '') {
					var cookies = document.cookie.split(';');
					for (var i = 0; i < cookies.length; i++) {
						var cookie = jQuery.trim(cookies[i]);
						if (cookie.substring(0, name.length + 1) == (name + '=')) {
							cookieValue = unescape(cookie.substring(name.length + 1));
							break;
						}
					}
				}
				return cookieValue;
			}
		},
		SetString:function (str,len)
		{
			var strlen = 0;
			var s = "";
			for(var i = 0;i < str.length;i++)
			{
			        if(str.charCodeAt(i) > 128)
			         strlen += 2;
			        else
			        strlen++;
			        s += str.charAt(i);
			        if(strlen >= len)
			        return s;
			}
			return s;
		}
	};

if(!Pui.msg){Pui.msg={}}
Pui.msg.readMessageHandler=function(a){
	var a=/pomoho.com\/manage\/readmessage.aspx/;
	var b=window.location.href.toString();
	if(a.test(b)){
		alert("操作成功！")
	}else{
	}
}
//by xiangmz@2009/03/05
function f_routerCallBack(redirectUrl)
	{
		if ( redirectUrl != "false" ) 
		{ 
			window.location = redirectUrl ;
		} 
	} 
function f_isRouter(type) 
	{ 
		Pui.loadScript("http://www.pomoho.com/do/interfaces/router.aspx?pagetype='"+type+"'"); 
	}

//图片按比例自适应
function Img(im)
{
    ImgCls.Obj = ( im && typeof im == 'object' ) ? im : document.getElementById(im) ;
    return ImgCls ;
}
var ImgCls =
{
    Obj : null ,
    Resize : function ( nWidth , nHeight )
    {
        var w , h , p1 , p2 ;
        p1 = nWidth / nHeight ;
        p2 = ImgCls.Obj.width / ImgCls.Obj.height ;

        w = 0 ; h = 0 ;
        if( p1 < p2 )
        {
            w = nWidth ;
            h = nWidth * ( 1 / p2 ) ;
        }
        else
        {
            h = nHeight ;
            w = nHeight * p2 ;
        }
        ImgCls.Obj.width  = w ;
        ImgCls.Obj.height = h ;
		ImgCls.Obj.style.marginTop=(nHeight-h)/2+'px';
    },
    ResizedByWH : function ( nWidth , nHeight )
    {
        ImgCls.Obj.width  = nWidth ;
        ImgCls.Obj.height = nHeight ;
    },
    ResizedByWidth : function ( nWidth )
    {
        var p = nWidth / ImgCls.Obj.width ;
        ImgCls.Obj.width  = nWidth ;
        ImgCls.Obj.height = parseInt ( ImgCls.Obj.height * p ) ;
    },
    ResizedByHeight : function ( nHeight )
    {
        var p = nHeight / ImgCls.Obj.height ;
        ImgCls.Obj.height  = nHeight ;
        ImgCls.Obj.width = parseInt ( ImgCls.Obj.width * p ) ;
    },
    ResizedByPer : function ( nWidthPer , nHeightPer )
    {
        ImgCls.Obj.width  = parseInt(ImgCls.Obj.width * nWidthPer / 100) ;
        ImgCls.Obj.height = parseInt(ImgCls.Obj.height * nHeightPer / 100) ;
    }
}
$(function(){
function autoThumb(path,w,h){
$(path).each(function(i){
var preldimg=new Image();
preldimg.onload=function(){Img($(path)[i]).Resize(w,h);preldimg=null;}
preldimg.src=$(path)[i].src;
});
}
autoThumb('.mainshow ul:first img',100,75);
autoThumb('.mainshow ul.boke img',80,80);
});

//加载背景图片
/*window.onload=function(){$('#B-Index').css('background','url(http://static01.pomoho.com/themes/site/default/images/index_v2.0/back.jpg) no-repeat center top');}*/
//将escape转换加密方式

var initIndex={
	init:function(){
		this.addNum();
		this.deEscape('.hotsearch li a');
	},
	addNum:function(){
	$('#Main .hotsearch li').each(
		function(i){
			$('<span>'+[i+1]+'</span>').prependTo($('#Main .hotsearch li')[i]);
			}							  
	);
	this.borderLine(6);
	},
	deEscape:function(a){
		$(a).each(function(){
		var norUrl=$(this).attr('href').split('_keyword=')[0]
		var norKey=unescape($(this).attr('href').split('_keyword=')[1]);
		$(this).attr('href',norUrl+'_keyword='+encodeURIComponent(norKey));								   
		});	
	},
	borderLine:function(liNum){
		var ulNum=$('.mainshow ul').length;
		for(var i=0;i<ulNum;i++){
			var liT=$('.mainshow ul:eq('+i+') li').length;
			if(liT<liNum){
				$('.mainshow ul:eq('+i+')').width(760);
			}
			else{
				var li_line=parseInt(liT/liNum);
				for(var j=0;j<li_line;j++){
					$('#Main .mainshow ul:eq('+i+') li:eq('+((j+1)*liNum-1)+')').css('margin-right',0);
				}
			}
		}
		$('.mainshow ul').css({'border-bottom':'1px solid #dadada','width':'760px'});
		$('.mainshow ul:last').css('border','none');
	}
}
$(function(){initIndex.init();});