﻿
//控制左侧内容栏的移动
function SubContentMove(_topDistance)
{
    var topDistance=_topDistance;               
    
    $(document).ready(function() {
        var moveContentHeight=$(".mainMoveContent").height();
        var rightHeight=$(".mainRight").height();

        if((jQuery.browser.mozilla || jQuery.browser.safari) && $(document).scrollTop()<=topDistance)$(".mainMoveContent").css("top",topDistance+"px");
        
        var checkAnimateComplete=function(){
            
            if($(document).scrollTop()<=topDistance )
                $(".mainMoveContent").animate({top:"0"},{duration:"normal",easing:"linear"});
        }                        
        $(window).scroll( function() {  
               
            if(jQuery.browser.version=="6.0" && jQuery.browser.msie)
            {             
                //IE6        
                if($(document).scrollTop()>topDistance )
                {

                    //if($(".mainMoveContent").is(":animated"))
                    $(".mainMoveContent").stop();

                    var moveTarget= $(document).scrollTop()-topDistance+"px";
                    if( $(document).scrollTop()-topDistance+moveContentHeight>=rightHeight)
                    {
                        moveTarget=rightHeight-moveContentHeight;
                    }
                    
                        $(".mainMoveContent").animate({top:moveTarget},{complete:checkAnimateComplete,duration:"normal",easing:"linear"}); 
                }
            }else{                
                    
                var reachTop=false;
                if($(document).scrollTop()>topDistance)
                {
                    $(".mainMoveContent").css("position","fixed");
                }
                else{
                    
                    $(".mainMoveContent").css("position","absolute");
                    reachTop=true;
                }                
                
                
                if(jQuery.browser.safari){
                    rightHeight=$(".mainRight").height();
                    moveContentHeight=$(".mainMoveContent").height();
                }                
                if($(document).scrollTop()+moveContentHeight>=rightHeight+topDistance)
                {                
                    $(".mainMoveContent").css("top",rightHeight+topDistance-($(document).scrollTop()+moveContentHeight)+"px");
                }
                else
                {
                    $(".mainMoveContent").css("top","0px");
                }
                if((jQuery.browser.mozilla || jQuery.browser.safari) && reachTop)$(".mainMoveContent").css("top",topDistance+"px");
                
                
            }            
            
        } );
        
    });
}



function onClickGoTop(){ 
    //gotop函数
    $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');// Opera 的补丁
    $body.animate({scrollTop: 0}, 1000); 
    return false;// 返回false可以避免在原链接后加上#
}


