//判断是否为遨游
function IsMaxthon(){
	try{
		window.external.max_version;
		return true;
	}
	catch(ex){
		return false;
	}
}
//判断遨游的版本号
function maxthonVersion(){  
	if(window.external && window.external.max_version);{
		return window.external.max_version.substr(0,1);
	}
	return undefined;
}



jQuery(function($) {
	var youTong = {
		//未登录之焦点图切换
		nLFimg : function(){
			var leftMenu = jQuery('.nLsLeft');//左按钮
			var rightMenu = jQuery('.nLsRight');//右按钮
			var fathDiv = jQuery('.nLSlide ul');//偏移Div
			var sTime = 600;//动画时长
			var jTime = 5000;//轮播间隔
			var sWidth = fathDiv.find('li').eq(0).width();//偏移量
			var nCount = fathDiv.find('li').length;//图片数量
			var nWidth = (nCount-1) * sWidth;//当前容器宽度
			var xVar = 0;//临时计数变量
			rightMenu.live('click',function(){
				if(xVar >= 0 && xVar <= nCount - 2){
					xVar++;
					doAct();
				}
				else return;
			});
			leftMenu.live('click',function(){
				if(xVar > 0 && xVar <= nCount - 1){
					xVar--;
					doAct();
				}
				else return;
			});
			function autoSlide(){
				if(xVar >= 0 && xVar <= nCount - 2){
					xVar++;
					doAct();
				}
				else{
					xVar = 0;
					doAct();
				}
			}
			var doRun = window.setInterval(autoSlide,jTime);
			function doAct(){
				fathDiv.animate({
					'left' : -(xVar * sWidth) + 'px'
				},sTime);
			}
			fathDiv.hover(
				function(){
					window.clearInterval(doRun);
					fathDiv.stop();
					doAct();
				},
				function(){
					doRun = window.setInterval(autoSlide,jTime);
				}
			);
		},
		//相册专辑切换
		contListTab : function(){
			var tempObj = jQuery('div.contList').find('div.menu').find('span');
			var tempNum;
			tempObj.click(function(){
				jQuery('div.contList').children('div:not(.menu)').css('display','none');
				jQuery(this).siblings().removeClass('on');
				jQuery(this).addClass('on');
				tempNum = tempObj.index(jQuery(this));
				switch(tempNum){
					case 0 :jQuery('div.contList').children('div.list').slideDown('slow');break;
					case 1 :jQuery('div.contList').children('div.cover').slideDown('slow');break;
					default:alert('tempNum error');
				}
			});
		},
		gFbannSlid : function(){
			var tempObj = jQuery('div.bannSlidMenu a');
			var tempNum = 0;
			var tempLength = tempObj.length;
			var tempTime = 5000;
			var doInterval;
			tempObj.click(function(){
				window.clearInterval(doInterval);
				doInterval = window.setInterval(slideCycle,tempTime);
				tempNum = tempObj.index(jQuery(this));
				jQuery(this).siblings().removeClass('on');
				jQuery(this).addClass('on');
				jQuery('div.gFbanSmarty ul').animate({
					'left' : - (tempNum * 650)
				});
			});
			function slideCycle(){
				tempNum ++;
				if(tempNum >= tempLength) tempNum = 0;
				tempObj.removeClass('on');
				tempObj.eq(tempNum).addClass('on');
				jQuery('div.gFbanSmarty ul').animate({
					'left' : - (tempNum * 650)}
				);
			}
			doInterval = window.setInterval(slideCycle,tempTime);
		},
		AlternateRows : function(tempObj,color){
			tempObj.css('background-color','#' + color);
		},
		groupImaster : function(){
			var tempObj = jQuery('div.groupImaster li');
			tempObj.hover(function(){
				jQuery(this).css('background-color','#e0f5ff');
				jQuery(this).find('span.right').css('display','inline');
			},function(){
				jQuery(this).css('background-color','');
				jQuery(this).find('span.right').css('display','none');
			});
		},
		textTipIn : function(tempObj){
			var tempText = tempObj.val();
			if(tempText == '查找好友'){
				tempObj.val('');
			}
		},
		textTipOut : function(tempObj){
			var tempText = tempObj.val();
			if(tempText.length <= 0){
				tempObj.val('查找好友');
			}
		},
		repeatNum : function(){
			var tempTextarea = jQuery('#mood_message');
			var tempNum = jQuery('#repeatNum');
			var tempLength;
			tempTextarea.keyup(function(){
				tempLength = 140 - tempTextarea.val().length;
				tempNum.html(tempLength);
			});
		},
		repeatNumComm : function(){
			var tempTextarea = jQuery('#comment_message');
			var tempNum = jQuery('#repeatNum');
			var tempLength;
			tempTextarea.keyup(function(){
				tempLength = 140 - tempTextarea.val().length;
				tempNum.html(tempLength);
			});
		},
		repeatNumDoing : function(){
			var tempTextarea = jQuery('#message');
			var tempNum = jQuery('#repeatNum');
			var tempLength;
			tempTextarea.keyup(function(){
				tempLength = 140 - tempTextarea.val().length;
				tempNum.html(tempLength);
			});
		},
		repeatDoMSG : function(){
			var tempTextarea = jQuery('#doMSG');
			var tempNum = jQuery('#repeatNum');
			var tempLength;
			tempTextarea.keyup(function(){
				tempLength = 140 - tempTextarea.val().length;
				tempNum.html(tempLength);
			});
		},
		groupSite : function(tempObj){
			var tempHtml = new String;
			tempHtml += '<div class="gStip png">';
			tempHtml += '<div class="gSleft"><div class="head"><img src="../image/ytImg/headNone.jpg"></div><a href="#"></a></div>';
			tempHtml += '<div class="gSinfo">Test Text</div>';
			tempHtml += '</div>';
			var gStip = new Object;
			
			tempObj.mouseenter(function(){
				jQuery(this).after(tempHtml);
				gStip = jQuery('div.gStip');
				gStip.css({
					'top':tempObj.offset().top - (gStip.height()),
					'left':tempObj.offset().left - (tempObj.width()/2)
				});
				gStip.mouseleave(function(){
					jQuery(this).empty().remove();
				});
			});
		},
		limitImg : function(tempDiv,tempWidth,tempHeight){
			var _img = tempDiv.find('img');
			_img.each(function(){
				if(jQuery(this).width() >= tempWidth){
					jQuery(this).css({'width' : tempWidth});
				}
				if(jQuery(this).height() >= tempHeight){
					jQuery(this).css({'height' : tempHeight});
				}
			});
		},
		csPop : function(){
			//显示
			jQuery('.popEdit').live('click',function(){
				jQuery('div.cs_edit_pop').fadeIn('fast');
			});
			
			//定位
			var popDiv = jQuery('.cs_edit_pop');
			var popDiv_width = popDiv.outerWidth();
			var popDiv_height = popDiv.outerHeight();
			popDiv.css({
				'margin-left' : -(popDiv_width/2),
				'margin-top' : -(popDiv_height/2)
			});
			
			//切换
			var clickDiv = jQuery('div.cepc_title').find('span');
			clickDiv.live('click',function(){
				var _this = jQuery(this);
				var _thisIndex = clickDiv.index(_this);
				
				clickDiv.removeClass('on');
				clickDiv.eq(_thisIndex).addClass('on');
				
				jQuery('div.cep_cont').find('div.cepc_cont').hide();
				jQuery('div.cep_cont').find('div.cepc_cont').eq(_thisIndex).show();
			});
			
			//选择
			var chsDiv = jQuery('div.cepc_conty').find('li');
			chsDiv.live('click',function(){
				var _this = jQuery(this);
				_this.siblings().each(function(){
					jQuery(this).find('b').removeClass('on');
				});
				_this.find('b').toggleClass('on');
			});
			//关闭
			var _close = jQuery('div.cep_title').find('b');
			_close.live('click',function(){
				jQuery('div.cs_edit_pop').fadeOut('fast');
			});
		},
		tipNos : function(){
			var tNid = jQuery('img[popuid]');
			var tipNos = jQuery('div.tipNos');
			tNid.mouseover(function(){
				tipNos.show();
				var _this = jQuery(this).parent();			
				var uid = jQuery(this).attr('popuid');
				jQuery.get("ajax/childpop.php", {uid:uid}, function (html) {
					tipNos.html(html);
					var tempObj = tipNos.find('li');
					var tempLen = tempObj.length;
//					if(tempLen == 1){
//						tempObj.find('div.head').addClass('floatleft');
//						tempObj.append('<div class="floatleft tNo" style="margin-left:6px;"></div>');
//						jQuery('div.tNo').append(tempObj.find('a'));
//						tempObj.css('text-align','left');
//					}
				});
				tNid.mousemove(function(e){
					var oEvent = e || window.event;
					var dScrollH = jQuery(document).scrollTop();
					tipNos.css({
						'top' : oEvent.clientY + dScrollH + 15,
						'left' : oEvent.clientX + 15
					});
				});
			});
			tNid.mouseout(function(){
				tipNos.hide();
			});
		},
		searchNewB : function(cDiv,xDiv){
			cDiv.live('click',function(){
				xDiv.slideToggle('fast');
			});
		}
	}
	//doIt
	youTong.nLFimg();
	youTong.contListTab();
	youTong.gFbannSlid();
	youTong.groupImaster();
	youTong.AlternateRows(jQuery('div.gFmoreGroup').find('div.cont').find('li:odd'),'e0f5ff');
	youTong.AlternateRows(jQuery('div.gFmyGroup').find('div.cont').find('li:odd'),'e0f5ff');
	jQuery('.ySearch').focusin(function(){youTong.textTipIn(jQuery(this));});
	jQuery('.ySearch').focusout(function(){youTong.textTipOut(jQuery(this));});
	youTong.repeatNum();
	youTong.repeatNumComm();
	youTong.repeatNumDoing();
	youTong.repeatDoMSG();
	youTong.groupSite(jQuery('.groupSite'));
	youTong.limitImg(jQuery('div.limitImg'),100,70);
	youTong.csPop();
	youTong.tipNos();
	youTong.searchNewB(jQuery('.yZhu'),jQuery('.nZhu'));
});


function showPic(id, op) {
	jQuery.get('ajax/select_pic.php',{'op':op, 'id':id},function(html){
		jQuery('#show_pic_layer').html('').html(html);
	});
}

function selectFocus(obj){
	jQuery(obj).find('b').toggleClass('on')
}

function clearFocus(){
	jQuery('.cepc_conty1 li b.on').removeClass('on');
	hideMenu();
}

function submitFocus(){
	jQuery('.cepc_conty1 li b.on').each(function(){
		insertImage(jQuery(this).attr('value'));
	}).removeClass('on');
	hideMenu();
}

var navEvent = function () {
	jQuery('div.navGroup a[title=应用], div.navGroup a[title=个人主页]').bind('mouseover', function(){
		var title = jQuery(this).attr('title');
		var fDiv = jQuery('div.navGroup .showTipLMR');
		var sDiv;
		if (title == '应用')
			sDiv = jQuery('div.showTipLMR').eq(0);
		else
			sDiv = jQuery('div.showTipLMR').eq(1);
			
		fDiv.hide();
		sDiv.css({
			'top' : jQuery(this).offset().top + jQuery(this).height(),
			'left' : jQuery(this).offset().left
		});
		sDiv.show('fast');		
			
		sDiv.bind('mouseleave', function(){
			fDiv.hide();						
		});
		
	}) 
}

jQuery(function(document) {
	navEvent();
});
