var globalPage = 1;
function getContent(url,container,func,data,obj,append){
	data = data ? data : 'ajax=1';
	if(obj) url = $(obj).attr('href');
	
	if(append) $(window).unbind('scroll');
	if(append && !$('#right_new').hasClass('loading')){
		$("#right_new").append("<div id='loadingDiv' style='clear:both;width:100%;height:40px;background:url(templates/default/img/loading.gif) no-repeat center;'></div>");
	}
	var option = {
		url:url,
		data:data,
		type:'post',
		success:function(data){
			$('#loadingDiv').remove();
			$(container).removeClass('loading');
			if(data){
				if($.isFunction(func))
					data = eval(func+"("+data+")");
				if(!append)
					$(container).attr("innerHTML",data);
				else{
					$(container).append(data);
					$(window).bind('scroll',function(){
						if(scrollBottom()){
							globalPage++;
							getContent(url,container,'','p='+globalPage,'',1);
						}
					});
				}
			}else{
				$(window).unbind('scroll');
			}
		}
	}
	$.ajax(option);
	return false;
}
function _showsubnav(a){
	var curA = $(a).parent('span').parent('div').next('div.newsubnav');
	if(curA[0].style.display=='none') $('.left_menu_new .newsubnav').slideUp("slow");
	$(curA).slideToggle('slow',function(){
		if($('#right_new').height()<($('.intro_left_margin').height()-20))
			$('#left_new').height($('.intro_left_margin').height()-50);
		else
			$('#left_new').height($('.right_new').height());
	});
	
	return false;
}
function _check(name,value){
	var regex = {
		'require'  : /.*/, //匹配任意字符，除了空和断行符
		'email'    : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,  //电子邮件
		'phone'    : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/, //固定电话
		'mobile'   : /^((\(\d{2,3}\))|(\d{3}\-))?(13|15)\d{9}$/,  //移动手机号码
		'url'      : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,  //url地址
		'currency' : /^\d+(\.\d+)?$/,  //货币
	    'number'   : /\d+$/,           //纯数字
	    'zip'      : /^[1-9]\d{5}$/,
	    'qq' 	   : /^[1-9]\d{4,12}$/,       //QQ号码
	    'integer'  : /^[-\+]?\d+$/,           //整数
	    'double'   : /^[-\+]?\d+(\.\d+)?$/,   //双整型
	    'english'  : /^[A-Za-z]+$/,           //纯英文字符
		'string'   : /^[A-Za-z_]+[0-9_a-zA-Z]*$/,    //以英文开头的英文和数字组成的字符串
		'ip' 	   : /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/, //ip地址
		'card'     : /^(\d{14}|\d{17})(\d|[xX])$/,   //匹配身份证
		'birth'    : /^\d{4}.{1}\d{1,2}.{1}\d{1,2}/  //匹配生日
	};
	var pattern = regex[name]?regex[name]:'require';
	var reg = new RegExp(pattern);
	return reg.test(value);
}
var _globalScrollId = '';
var globalTimeObjBar = null;
function picScroll(id){
	if(id==_globalScrollId){
		return false;
	}
	clearAuto();
	var len = $(id+' .newIndexManList').length;
	if(len<2)
		return false;
	var $showbox = $(id);
	var $pre = $('.newNext');
	var $next = $('.newPrev');
	
	if(id!=_globalScrollId && globalTimeObjBar){
		unBindObj($next);
		unBindObj($pre);
		//unBindObj($showbox);
	}
	_globalScrollId = id;
	autoSlide();
	clearFun($next);
	clearFun($pre);
	//clearFun($showbox);
	$next.bind('click',function(){
		if (!$showbox.is(':animated')) {
			var $curDiv = $(id+' .currentIndexMan');
			var $nextDiv = $(id+' .currentIndexMan').next('div.newIndexManList');
			$nextDiv.show();
			$showbox.animate({
	                left: '-=' + 245
	            }, 500,'',function(){
	            	$(this).css({left:0});
	            	$curDiv.hide();
	            	$curDiv.removeClass('currentIndexMan');
	            	$curDiv.clone().appendTo($(id));
	            	$curDiv.remove();
	            	$nextDiv.addClass('currentIndexMan');
	        });
		}
	});
	$pre.bind('click',function(){
		if (!$showbox.is(':animated')) {
			var $curDiv = $(id+' .currentIndexMan');
			var allIndexDiv = $(id+" .newIndexManList");
        	var preDiv = allIndexDiv[len-1];
        	$(preDiv).show();
        	$(preDiv).addClass('currentIndexMan');
        	$(preDiv).clone().prependTo($(id));
        	$(preDiv).remove();
        	$showbox.css({left:'-245px'});
        	$showbox.animate({
	                left: '+=' + 245
	            }, 500,'',function(){
	            	$(this).css({left:0});
	            	$curDiv.hide();
	            	$curDiv.removeClass('currentIndexMan');
            });
		}
	});
	
	function autoSlide(){
        $next.trigger('click');
        globalTimeObjBar = setTimeout(autoSlide,3000);
    }
	
	function clearFun(elem){
		$(elem).bind('mouseover',function(){
			clearAuto();
		}).bind('mouseout',function(){
			autoSlide();
		});
	}
	
	function clearAuto(){
		if(globalTimeObjBar){
			window.clearTimeout(globalTimeObjBar);
			globalTimeObj = null;
		}
	}
	
	function unBindObj(elem){
		$(elem).unbind('click');
		$(elem).unbind('mouseover');
		$(elem).unbind('mouseout');
	}
}

function tabShowHide(showId,hideId){
	if($(showId).css('display')=='none'){
		$('.newIndexLeft .newTitle div').each(function(){
			if($(this).hasClass('newCurrent')){
				$(this).addClass('oldCurrent');
				$(this).removeClass('newCurrent');
			}else{
				$(this).removeClass('oldCurrent');
				$(this).addClass('newCurrent');
			}
		});
		$(showId).show();
		$(hideId).hide();
		picScroll(showId);
	}
}

function scrollBottom(){
	var winHeight = $(window).height();  //当前窗口可见高度
	var docHeight = $(document).height();//当前文档高度，包括可见和不可见部分
	if(docHeight>winHeight){//若文档高度大于可见高度，则存在滚动条
		var top = document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop; //当前滚动条距顶部距离
		if(top>=docHeight-winHeight-140)//说明已经滚动到底部了
			return true;
	}
	return false;
}

var globalScroolTopsDoc = null
var globalScroolTopsYoung = null
function scrollTops(id,t){
	var len = $(id+' .scltoplist').length;
	if(len>=2){
		var $curObj = $(id+' .curscltop');
		var $nextObj = $curObj.next('.scltoplist');
		$nextObj.removeClass('sclhidden');
		$nextObj.addClass('curscltop');
		$(id).animate({
			top:'-=125'
		},500,'',function(){
			$(this).css({top:'15px'});
			$curObj.removeClass('curscltop');
			$curObj.addClass('sclhidden');
			$curObj.clone().appendTo($(this));
			$curObj.remove();
		});
	}
	if(t=='y')
		globalScroolTopsYoung = setTimeout('scrollTops("'+id+'","'+t+'")',3000);
	else
		globalScroolTopsDoc = setTimeout('scrollTops("'+id+'","'+t+'")',3000);
}

function bindObjs(id,t){
	$(id).bind('mouseover',function(){
		if(t=='y') window.clearTimeout(globalScroolTopsYoung);
		else window.clearTimeout(globalScroolTopsDoc);
	}).bind('mouseout',function(){
		if(t=='y') globalScroolTopsYoung = setTimeout('scrollTops("'+id+'","'+t+'")',3000);
		else globalScroolTopsDoc = setTimeout('scrollTops("'+id+'","'+t+'")',3000);
	})
}
var _globalColorNum = 0;
function effWord(container){
	var color = ['#FF0000','#0000FF'];
	_globalColorNum = _globalColorNum>1 ? 0 : _globalColorNum;
	$(container).css({color:color[_globalColorNum]});
	_globalColorNum++;
	setTimeout("effWord('"+container+"')",500);
}

function focusAdFunc(pics,id){
	var links = '#|#|#|#';
	var texts = '|||';
	var focus_width=1000
    var focus_height=164
    var text_height=0
    var swf_height = focus_height+text_height;
	 var flashCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/hotdeploy/flash/swflash.cab#version=6,0,0,0" width="'+ focus_width +'" height="'+ swf_height +'">';
     flashCode = flashCode + '<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="js/focus2.swf"><param name="quality" value="high"><param name="bgcolor" value="#F0F0F0">';
     flashCode = flashCode + '<param name="menu" value="false"><param name=wmode value="transparent">';
     flashCode = flashCode + '<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'">';
     flashCode = flashCode + '<embed wmode="transparent" src="js/focus2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ focus_width +'" height="'+ swf_height +'" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'"></embed>';
     flashCode = flashCode + '</object>';
     $(id).attr('innerHTML',flashCode);
}

var _globalHideCurrent = false;
var _globalClearout = null;
function __slideDown(a,id){
	var div = $("#firstSubList_"+id);
	if(div.length<=0) return;
	$(div).unbind('mouseover').unbind('mouseout');
	var h = $(div).height();
	var w= $(div).width();
	_globalHideCurrent = false;
	if(!$(a).hasClass('current')){
		$(a).addClass('current');
		_globalHideCurrent = true;
	}
	var p = $(a).position();
	if(w>72){
		p.left = p.left-(w-72)/2;
	}
	$(div).css({left:p.left+"px",width:w+"px",height:h+"px"});
	$("#firstSubList_"+id+" div").css({position:'absolute',lef:p.left+'px',width:w+"px",height:h+"px"});
	$(div).slideDown(400);
	$(div).bind('mouseover',function(){
		if(_globalClearout){
			window.clearTimeout(_globalClearout);
			_globalClearout = null;
		}
	}).bind('mouseout',function(){
		_globalClearout=setTimeout(function(){
			if(_globalHideCurrent)$(a).removeClass('current');
			$(div).slideUp(100);
		},100);
	});
	$(a).unbind('mouseout');
	$(a).bind('mouseout',function(){
		_globalClearout=setTimeout(function(){
			if(_globalHideCurrent)$(a).removeClass('current');
			$(div).slideUp(100);
		},100);
	});
}
