﻿// QQ交流层控制鼠标拖动，定位位置 
var _move=false;//移动标记
// 右下角弹出层位置控制
var _move_to=0;// 判断滚动条是否被拖动
var _move_min=false;// 判断弹出层是否为最小化
var _move_max=false;// 判断弹出层是否为最大化

$(function() {                           
    $("#divStayTopleft tr:nth-child(3),#divStayTopleft tr:nth-child(4)").mousedown(function(e){
            _move=true;
            $(this).css({cursor:'move'});
        });
    $(document).mousemove(function(event){
        if(_move){            
            var x=event.pageX-30;//移动时根据鼠标位置计算控件左上角的绝对位置
            var y=event.pageY-150;
            $("#divStayTopleft").css({top:y,left:x});//控件新位置
        }
    }).mouseup(function(){
        _move=false;
    });

    // 右下角弹出提示层
	$(window).load(function(){
	    // 右下角弹出层
	    if(!judgeIE_Firefox_Opera())// 非ie6
	    {
		    $("div[id=newnotice]").css({right:"0px",bottom:"1px"});
		    $("div[id=newnotice]").slideDown(2300);
		}
		else// ie6
		{
		    $("div[id=newnotice]").css({right:"0px",bottom:"1px",position:"absolute"});
		    $("div[id=newnotice]").slideDown(2300);
		}
		
		// 新的autocomplete		
        var curPageName = location.href.replace("http://www.airjipiao.com/index_test1.aspx", "").replace("http://www.airjipiao.com/", "").replace("http://www.airjipiao.com", "").replace("http://airjipiao.com/index_test1.aspx", "").replace("http://airjipiao.com/", "");
        var curPage = curPageName.substr(curPageName.indexOf("=")).replace("=", "");
        if (curPage == "com" || curPage=="") {
            document.getElementById("suggest2").style.width = 285;
            $("#txtStartCity,#TopSearch1_txtStartCity,#TicketSearch1_txtStartCity,#TopSearchStudent1_txtStartCity").suggest(commoncitys2, { hot_list: commoncitys2, dataContainer: '#txtStartCity_3word', onSelect: function() { $("#txtToCity").click(); }, attachObject: '#suggest' });
            $("#txtToCity,#TopSearch1_txtToCity,#TicketSearch1_txtToCity,#TopSearchStudent1_txtToCity").suggest(citys1, { hot_list: commoncitys1, dataContainer: '#txtToCity_3word', attachObject: "#suggest2" });
        }
        else {
            document.getElementById("suggest2").style.width = 285;
            $("#txtStartCity,#TopSearch1_txtStartCity,#TicketSearch1_txtStartCity,#TopSearchStudent1_txtStartCity").suggest(citys, { hot_list: commoncitys, dataContainer: '#txtStartCity_3word', onSelect: function() { $("#txtToCity").click(); }, attachObject: '#suggest' });
            $("#txtToCity,#TopSearch1_txtToCity,#TicketSearch1_txtToCity,#TopSearchStudent1_txtToCity").suggest(citys1, { hot_list: commoncitys1, dataContainer: '#txtToCity_3word', attachObject: "#suggest2" });
        }		
		/*setTimeout(function(){$("div[id=newnotice]").slideUp("slow")},10000);*/
	}).scroll(function(){
	    // 定位QQ交流层位置固定
        fixQQDiv();	
        // 右下角弹出层位置固定
        fixNewNoticeDiv();         
        _move_to++;    
	}).resize(function(){
	    // 右下角弹出层
	    if(!judgeIE_Firefox_Opera())// 非ie6
	    {
		    $("div[id=newnotice]").css({"bottom":""});
		    $("div[id=newnotice]").css({right:"0px",bottom:$(event.target).scrollTop()-$("div[id=newnotice]").scrollTop()});	
		}
		else// ie6
		{
		    // 不处理
		}
	});
    
    // 最小化		
	$("label[id=tomin]").click(function(){
	    if(!judgeIE_Firefox_Opera())// 非ie6
        {	
		    $("div[id=noticecon]","div[id=newnotice]").slideUp(2300);
		}
		else// ie6
		{
		    // 滚动条被拖动了
		    if(_move_to!=0)
		    {
		        $("div[id=noticecon]","div[id=newnotice]").slideUp(2300);
	            var newnotice=document.getElementById("newnotice");
                newnotice.style.top=String( parseInt( document.documentElement.scrollTop)+(window.screen.availHeight/2.2-newnotice.style.height-1)+230)+"px";		        
		    }
		    else // 滚动条未被拖动
		    {
		        $("div[id=noticecon]","div[id=newnotice]").slideUp(2300);
		    }
		}
		_move_min=true;// 弹出层最小化
		_move_max=false;
	});
	
	// 最大化
	$("label[id=tomax]").click(function(){
	    if(!judgeIE_Firefox_Opera())// 非ie6
        {	
		    $("div[id=noticecon]","div[id=newnotice]").slideDown("slow");
		}
		else// ie6
		{
		    // 滚动条被拖动了
		    if(_move_to!=0)
		    {
		        $("div[id=noticecon]","div[id=newnotice]").slideDown("slow");
	            var newnotice=document.getElementById("newnotice");
                newnotice.style.top=String( parseInt( document.documentElement.scrollTop)+(window.screen.availHeight/2.2-newnotice.style.height-1))+"px";		        		        
		    }
		    else // 滚动条未被拖动
		    {
		        $("div[id=noticecon]","div[id=newnotice]").slideDown("slow");
		    }		    
		}		
		_move_max=true;// 弹出层最大化
		_move_min=false;
	});
	
	// 定位QQ交流层位置固定
	function fixQQDiv()
	{
	    try
	    {
	        var divStayTopleft=document.getElementById("divStayTopleft");
	        var qqbox=document.getElementById("qqbox");
	        divStayTopleft.style.top=String( parseInt( document.documentElement.scrollTop)-parseInt(qqbox.style.top))+"px";	    
	    }
	    catch(Error)
	    {
	    }
	}
	// 初次加载页面时右下角弹出层位置固定
	function fixNewNoticeDiv()
	{
	    try
	    {   if(!judgeIE_Firefox_Opera())// 非ie6
	        {
	            var newnotice=document.getElementById("newnotice");
	            newnotice.style.top=String( parseInt( document.documentElement.scrollTop)+(window.clientHeight-newnotice.style.height-1))+"px";
	        }
	        else// ie6
	        {
	            // 判断弹出层当前是否已经最小化
	            if(_move_min==true)// 已经是最小化
	            {
	                var newnotice=document.getElementById("newnotice");
                    newnotice.style.top=String( parseInt( document.documentElement.scrollTop)+(window.screen.availHeight/2.2-newnotice.style.height-1)+230)+"px";		        
	            }
	            else// 最大化
	            {
    	            var newnotice=document.getElementById("newnotice");
                    newnotice.style.top=String( parseInt( document.documentElement.scrollTop)+(window.screen.availHeight/2.2-newnotice.style.height-1))+"px";
	            }
	        }
	    }
	    catch(Error)
	    {
	    
	    }
	}
			
	// 判断当前浏览器版本是否是ie6
	function judgeIE_Firefox_Opera()
	{
        var isIE=!!window.ActiveXObject;
        var isIE6=(isIE) && (!window.XMLHttpRequest);	    
        if(isIE)
        {
            if(isIE6)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
	}
	
	$("label[id=toclose]").click(function(){
		$("div[id=newnotice]").css('display','none');
	});
        
    // 限制单行字符个数，溢出部分加上省略号
    $("div[id='jipiao_wendabottom'] ul li a,div[id='jipiao_zixunbottom'] ul li a,div[id='jipiao_chuxingbottom'] ul li a").each(function(){
        var maxwidth=15;
        if($(this).text().length>maxwidth)    
        {       
            $(this).text($(this).text().substring(0,maxwidth)+'...');
        }
    });
    $("#jipiao_jiebanbottom table tr td:nth-child(3),#jipiao_jiebanbottom table tr td:nth-child(2)").each(function(){
        var maxwidth=5;
        if($(this).text().length>maxwidth)    
        {       
            $(this).text($(this).text().substring(0,maxwidth)+'...');
        }
    });
    $("div[class='jipiao_arightbottom'] ul li a,div[class='jipiao_brightbottom'] ul li a,div[class='jipiao_crightbottom'] ul li a").each(function(){
        var maxwidth=30;
        if($(this).text().length>maxwidth)    
        {       
            $(this).text($(this).text().substring(0,maxwidth)+'...');
        }
    });
    
});
           


