﻿// ----------------------------- js 文件  ---------------------------------------//


var W = screen.width; //取得屏幕分辨率宽度
var H = screen.height; //取得屏幕分辨率高度

function M(id) {
    return document.getElementById(id); //用M()方法代替document.getElementById(id)
}
function MC(t) {
    return document.createElement(t); //用MC()方法代替document.createElement(t)
};
//判断浏览器是否为IE
function isIE() {
    return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}
//取得页面的高宽
function getBodySize() {
    var bodySize = [];
    with (document.documentElement) {
        bodySize[0] = (scrollWidth > clientWidth) ? scrollWidth : clientWidth; //如果滚动条的宽度大于页面的宽度，取得滚动条的宽度，否则取页面宽度
        bodySize[1] = (scrollHeight > clientHeight) ? scrollHeight : clientHeight; //如果滚动条的高度大于页面的高度，取得滚动条的高度，否则取高度
        bodySize[2] = clientHeight; //取页面高度
    }
    return bodySize;
}
//创建遮盖层
function popCoverDiv() {
    if (M("cover_div")) {
        //如果存在遮盖层，则让其显示 
        M("cover_div").style.display = 'block';
    } else {
        //否则创建遮盖层
        var coverDiv = MC('div');
        document.body.appendChild(coverDiv);
        coverDiv.id = 'cover_div';
        with (coverDiv.style) {
            position = 'absolute';
            background = '#000000';
            left = '0px';
            top = '0px';
            var bodySize = getBodySize();
            width = bodySize[0] + 'px'
            height = bodySize[1] + 'px';
            //	 width = bodySize[0] + 'px'

            zIndex = 0;
            if (isIE()) {
                filter = "Alpha(Opacity=0)"; //IE逆境
            } else {
                opacity = 0;
            }
        }
    }
}

function getLT(_w, _h) {
    var de = document.documentElement;

    // 获取当前浏览器窗口的宽度和高度  
    // 兼容写法，可兼容ie,ff  
    var w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    var h = (de && de.clientHeight) || document.body.clientHeight;

    // 获取当前滚动条的位置  
    // 兼容写法，可兼容ie,ff  
    var st = (de && de.scrollTop) || document.body.scrollTop;

    var topp = 0;
    if (h > _h)
        topp = (st + (h - _h) / 2);
    else
        topp = st;

    var leftp = 0;
    if (w > _w)
        leftp = ((w - _w) / 2);

    // 左侧距，顶部距  
    return [leftp, topp];
}  


//让登陆层显示为块 
function showpopdiv() {
    var popdiv = M("popdiv");
    popdiv.style.display = "block";
}

//设置DIV层的样式
function change() {
    var popdiv = M("popdiv");
    popdiv.style.position = "absolute";
    popdiv.style.border = "1px solid #CCCCCC";
    popdiv.style.background = "#ffffff";
    var i = 0;
//    var bodySize = getBodySize();
//    popdiv.style.left = (bodySize[0] - widthdiv) / 2 + "px";
    //    popdiv.style.top = "450px";

    var re = getLT(widthdiv, heightdiv);
    popdiv.style.left = re[0] + "px";
    popdiv.style.top = re[1] + "px";

    popdiv.style.width = widthdiv + "px";
    popdiv.style.height = heightdiv + "px";

    popChange(i);
}
//让DIV层大小循环增大
function popChange(i) {
    var popdiv = M("popdiv");
//    var bodySize = getBodySize();
//    popdiv.style.left = (bodySize[0] - widthdiv) / 2 + "px";
//    popdiv.style.top = "450px";

    var re = getLT(widthdiv, heightdiv);
    popdiv.style.left = re[0] + "px";
    popdiv.style.top = re[1] + "px";

    popdiv.style.width = widthdiv + "px";
    popdiv.style.height = heightdiv + "px";
    if (i <= 10) {
        i++;
        setTimeout("popChange(" + i + ")", 10); //设置超时10毫秒
    }
}
//打开DIV层
function itsopen() {   
    change();
    showpopdiv();
//    popCoverDiv();
    //void(0);//不进行任何操作,如：<a href="#">aaa</a>
    //		location.href = "#top";
}
//关闭DIV层
function close() {
    M('popdiv').style.display = 'none';
//    M("cover_div").style.display = 'none';
    void (0);
}

function ChangeClass(sId) {
    if (document.getElementById(sId) != null) {
        if (document.getElementById(sId).style.display == 'none') {
            document.getElementById(sId).style.display = "block";
        }
        else {
            document.getElementById(sId).style.display = "none";
        }
    }
}

function ChangeNavOver(sId) { document.getElementById(sId).style.display = "block"; }

function ChangeNavOut(sId) { document.getElementById(sId).style.display = "none"; }


//-------------------------------------关闭展开end  ---------------------------------------  //


function menuFixB() {
    if (document.getElementById("navb") != null) {
        var sfEls = document.getElementById("navb").getElementsByTagName("li");
        for (var i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function () {
                this.className += (this.className.length > 0 ? " " : "") + "sfhover";
            }
            sfEls[i].onMouseDown = function () {
                this.className += (this.className.length > 0 ? " " : "") + "sfhover";
            }
            sfEls[i].onMouseUp = function () {
                this.className += (this.className.length > 0 ? " " : "") + "sfhover";
            }
            sfEls[i].onmouseout = function () {
                this.className = this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
            }
        }
    }
}

function menuFixC() {
    var sfEls = document.getElementById("navc").getElementsByTagName("li");
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function () {
            this.className += (this.className.length > 0 ? " " : "") + "sfhover";
        }
        sfEls[i].onMouseDown = function () {
            this.className += (this.className.length > 0 ? " " : "") + "sfhover";
        }
        sfEls[i].onMouseUp = function () {
            this.className += (this.className.length > 0 ? " " : "") + "sfhover";
        }
        sfEls[i].onmouseout = function () {
            this.className = this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
        }
    }
}

// --------------------------------------下拉导航end ------------------------------- //

function bgComplete() {
    $("#container").show();
    menuFixB();
    menuFixC();
    //    s();
}
// --------------------------------------下拉导航end ------------------------------- //
// --------------------------------------背景图加载 ------------------------------- //
var s = function () {
    var interv = 6000; //切换间隔时间
    var interv2 = 10; //切换速速
    var opac1 = 100; //文字背景的透明度
    var source = "fade_focus" //图片容器id
    //获取对象
    function getTag(tag, obj) { if (obj == null) { return document.getElementsByTagName(tag) } else { return obj.getElementsByTagName(tag) } }
    function getid(id) { return document.getElementById(id) };
    var opac = 0, j = 0, t = 63, num, scton = 0, timer, timer2, timer3; var id = getid(source); id.removeChild(getTag("div", id)[0]); var li = getTag("li", id); var div = document.createElement("div"); var title = document.createElement("div"); var span = document.createElement("span"); var button = document.createElement("div"); button.className = "zzbutton"; for (var i = 0; i < li.length; i++) { var a = document.createElement("a"); a.innerHTML = i + 1; a.onclick = function () { clearTimeout(timer); clearTimeout(timer2); clearTimeout(timer3); j = parseInt(this.innerHTML) - 1; scton = 0; t = 63; opac = 0; fadeon(); }; a.className = "zzb1"; a.onmouseover = function () { this.className = "zzb2" }; a.onmouseout = function () { this.className = "zzb1"; sc(j) }; button.appendChild(a); }
    //控制透明度
    function alpha(obj, n) { if (document.all) { obj.style.filter = "alpha(opacity=" + n + ")"; } else { obj.style.opacity = (n / 100); } }
    //控制焦点按钮
    function sc(n) { for (var i = 0; i < li.length; i++) { button.childNodes[i].className = "zzb1" }; button.childNodes[n].className = "zzb2"; }
    title.className = "num_list"; title.appendChild(span); alpha(title, opac1); id.className = "zzd1"; div.className = "zzd2"; id.appendChild(div); id.appendChild(title); id.appendChild(button);
    //渐显
    var fadeon = function () { opac += 5; div.innerHTML = li[j].innerHTML; span.innerHTML = getTag("img", li[j])[0].alt; alpha(div, opac); if (scton == 0) { sc(j); num = -2; scrolltxt(); scton = 1 }; if (opac < 100) { timer = setTimeout(fadeon, interv2) } else { timer2 = setTimeout(fadeout, interv); }; }
    //渐隐
    var fadeout = function () { opac -= 5; div.innerHTML = li[j].innerHTML; alpha(div, opac); if (scton == 0) { num = 2; scrolltxt(); scton = 1 }; if (opac > 0) { timer = setTimeout(fadeout, interv2) } else { if (j < li.length - 1) { j++ } else { j = 0 }; fadeon() }; }
    //滚动文字
    var scrolltxt = function () { t += num; span.style.marginTop = t + "px"; if (num < 0 && t > 3) { timer3 = setTimeout(scrolltxt, interv2) } else if (num > 0 && t < 62) { timer3 = setTimeout(scrolltxt, interv2) } else { scton = 0 } };
    fadeon();
}

// ----------------------------------------首页图片切换end ------------------------------- //
//-----------------------------------------背景大图显示-----------------------------------//
var bodyPageURL = window.location.toString().toLowerCase();
if (bodyPageURL.indexOf("/about/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_About.jpg')";
}
else if (bodyPageURL.indexOf("/buyhouse/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_BuyHouse.jpg')";
}
else if (bodyPageURL.indexOf("/tenancy/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_Tenancy.jpg')";
}
else if (bodyPageURL.indexOf("/news/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_News.jpg')";
}
else if (bodyPageURL.indexOf("/mservice/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_Service.jpg')";
}
else if (bodyPageURL.indexOf("/investor/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_Investor.jpg')";
}
else if (bodyPageURL.indexOf("/recruit/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_Recruit.jpg')";
}
else if (bodyPageURL.indexOf("/worktogether/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_WorkTogether.jpg')";
}
else if (bodyPageURL.indexOf("/hr/") > -1 || bodyPageURL.indexOf("/account/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_HR.jpg')";
}
else if (bodyPageURL.indexOf("/society/") > -1) {
    document.body.style.backgroundImage = "url('/images/bgimg_SR.jpg')";
}
else if (bodyPageURL.indexOf("/biz/") > -1) {
    document.body.style.backgroundImage = "url('/images/bizbc.jpg')";
}
else if (bodyPageURL.indexOf("/residential/") > -1) {
    document.body.style.backgroundImage = "url('/images/zhuzaibc.jpg')";
}
else if (bodyPageURL.indexOf("/sinoservice/") > -1) {
    document.body.style.backgroundImage = "url('/images/servicbc.jpg')";
}
else {
    document.body.style.backgroundImage = "url('/images/bgimg_main01.jpg')";
}
//获取参数
function GetUrlString(domain) {
    var flagStr = "", flag = 0;
    var url = window.location.href;
    var paras = url.split("/");
    for (var str in paras) {
        if (flag == 1) {
            flagStr = paras[str];
            break;
        }
        if (paras[str].indexOf(domain) > -1) {
            flag = 1;
        } 
    }
    return flagStr;
}
$(document).ready(function () {

    //检查URL
    var domain = "sinooceanland.com";
    var check = GetUrlString(domain);
    if (check == "" || check == "zh-CN" || check == "en-US")
    { }
    else {
        window.location.href = "http://www." + domain;
    }
    //切换位置记录
    $("a").click(function () {
        var slt = 0;
        if (document.documentElement && document.documentElement.scrollTop) {
            slt = document.documentElement.scrollTop;
        }
        else if (document.body) {
            slt = document.body.scrollTop;
        }
        SetCookie("scrollTop", slt);
    });
    //背景大图显示
    setTimeout(bgComplete, 2000);
});
