/**
 * JavaScript Document
 */
var nlastTab = $("#Tab");

/**
 * 设置鼠标覆盖时的样式
 */
function ngoTab(ntabN, nconID) {
    if (nlastTab)
        nlastTab.className = "td";

    if (ntabN) {
        ntabN.className = "navc";
        nlastTab = ntabN;
    }

    if (nconID) {
        $(function() {
            $('#loadtype').load('/ajax/hotTalk.php?id=' + nconID);
        })
    }
}

$(function() {
    $('#Tab').mousemove();
    $('#rband').click(function() {
        $('#fun').hide();
        $('#Brand').show();
        $('#rband').attr('class', 'lfun');
        $('#lfun').attr('class', 'rband');
    });

    $('#lfun').click(function() {
        $('#Brand').hide();
        $('#fun').show();
        $('#rband').attr('class', 'rband');
        $('#lfun').attr('class', 'lfun');
    });

    $('#maqup').mouseover(function() {
        maqup();
    }).mouseout(function() {

        clearInterval(maqsup)
    });

    $('#maqdown').mouseover(function() {
        maqdown();
    }).mouseout(function() {

        clearInterval(maqsdown)
    });

    ngo(1);
    net = setInterval(cha, 5000);//首页联播速度5秒
    $('#add').mousemove(function() {
        clearInterval(net)
    }).mouseout(function() {

        net = setInterval(cha, 5000);
    });

    lnTag(1);
    newsad(412, 'index_r2_c4.jpg');
	
    $('.login_top').load('/ajax/auth.php');
	
    $('.nav').mouseout(function() {
        $("#Tab").mousemove();
    })

    $.get('/ajax.php?act=ref&url=' + document.referrer);
    $("img").each(function(i) {
        if ($(this).attr('src') == '')
            this.src = "/images/nopic.jpg";
    });
})

var a = 1;
function cha() {
    if (a >= 7) {
        a = 1;
    } else {
        a++;
    }

    ngo(a);
}

function ngo(id) {
    var obj = $('#add');

    for (i = 1;i <= 7;i++) {
        var nlas = $("#ad" + i);
        var tab = $("#adt" + i);

        if (i == id) {
            if (obj && nlas)
                obj.html(nlas.html());

            anim(i);

            if (tab)
                tab.attr('class', 'ad');

            if (tab)
                tab.html('0' + i + '.' + tab.attr('title'));
        } else {
            if (tab)
                tab.attr('class', 'adb');

            if (tab)
                tab.html('0' + i);
        }
    }
}

function anim(i) {
    var obj = $('#add');

    switch (i) {

    case 1:

        if (obj)
            obj.hide();

        if (obj)

obj.animate( {height: 'show', opacity: 'show'}, "slow");
        break;

    case 2:

        if (obj)
            obj.fadeOut("show");

        if (obj)

obj.animate( {top: 100, opacity: 'show'}, "slow");
        break;

    case 3:

        if (obj)
            obj.slideUp("slow");

        if (obj)

obj.animate( {left: '+200px', opacity: 'show'}, "slow");
        break;

    case 4:

        if (obj)
            obj.hide();

        if (obj)

obj.animate( {right: 'show', opacity: 'show'}, "slow");
        break;

    case 5:

        if (obj)

obj.animate( {top: 'hide', opacity: 'hide'}, "slow");

        if (obj)
            obj.fadeIn("slow").show();

        break;

    case 6:
        if (obj)
            obj.hide();

        if (obj)
            obj.slideDown("slow");

        break;

    default:
        if (obj)
            obj.hide();

        if (obj)

obj.animate( {left: 'show', opacity: 'show'}, "slow").show();
    }
}

//向上滚动
var speed = 50; //滚动速度
function up() { //当滚动至demo1与demo2交界时
    if (document.getElementById('maq2').offsetTop - document.getElementById('com').scrollTop <= 0) {
        document.getElementById('com').scrollTop -= document.getElementById('maq1').offsetHeight //跳到最顶端
    } else {
        document.getElementById('com').scrollTop++;
    }
}

//向下滚动
function down() {
    if (document.getElementById('maq1').offsetTop - document.getElementById('com').scrollTop >= 0) {
        //document.getElementById('com').scrollTop+=document.getElementById('maq2').offsetHeight;
    } else {
        document.getElementById('com').scrollTop--;
    }
}

function maqup() {
    maqsup = setInterval(up, speed);
}

function maqdown() {
    maqsdown = setInterval(down, speed);
}

function lnTag(id) {
    $('#left_news').load('ajax.php?act=ln&id=' + id);
}

function newsad(id, bg) {
    $('#newsad').load('ajax.php?act=newsad&id=' + id + '&abc=' + Math.random());
    $('#tt').css('background-image', 'url(www/image/' + bg + ')');
}

function showmy(id) {
    $.get('/ajax.php?act=show&id=' + id, function(date) {
        alert(date)
    });
}