﻿jQuery(document).ready(function ($) {
    var ie = !$.support.cssFloat;
    //菜单
    $('.nav a').hide();
    if (ie) {
        $('.nav li').hover(function () {
            $('a', this).show();
        }, function () {
            $('a', this).hide();
        });
    }
    else {
        $('.nav li').hover(function () {
            //alert(00);
            $('a', this).stop(false, true).fadeIn(400);
        }, function () {
            $('a', this).stop(false, true).fadeOut(400);
        });
    }
    //#content高度
    function ConHeight(topMargin, bottomMargin) {
        var winHeight = $(window).height();
        var ConHeight = (winHeight - topMargin - bottomMargin) + 'px';
        $('#content').height(ConHeight);
        $('#content .rooms').height(parseInt(ConHeight) - 20 + 'px');
        $('.rooms_inner').height(parseInt(ConHeight) - 80 + 'px');
    }
    ConHeight(106, 0);
    $(window).resize(function () {
        ConHeight(106, 0);
        inner_width();
    });
    function inner_width() {
        var width = $('#content .wrapper').offset().left;
        if (width == 0)
            $('.main_content').css('width', $(window).width() - $('.rooms').width());
        else {
            var inner_width = 730 + $('#content .wrapper').offset().left;
            $('.main_content').css('width', inner_width);
        }
    }
    inner_width();
    //房间收缩 与 scroll 
    $('.rooms dl').eq(0).find('dd').css('display', 'block'); //初始化 第一个dl出现
    $('.rooms dt').click(function () {
        $(this).next('dd').stop(false, true).slideToggle();
    });
    $('#content').scroll(function () {
        $('.rooms').stop().animate({ top: $(this).scrollTop() }, 800);
    });

    //推荐房间滚动
    var $rooms = $('.recommend_rooms ul');
    $rooms.find('li:odd').css('background', '#f9f1ff');
    $rooms.find('li:even').css('background', '#fff');
    var drop_room = function () {
        var $room_last = $rooms.find('li').last();
        var room_height = $room_last.height();

        var $div = $('<div>').css('opacity', '0');

        var room_queue = [
            function () { $div.prependTo($rooms).animate({ height: room_height }, 600, function () { start_queue(); }); },
            function () { $room_last.appendTo($div); start_queue(); },
            function () { $div.animate({ opacity: 1 }, 1000, function () { start_queue(); }); },
            function () { $room_last.unwrap(); start_queue(); },
            function () { $('div:empty', '.recommend_rooms').remove(); }
        ]
        var start_queue = function () {
            $(document).dequeue('myQueue');
        }
        $(document).queue('myQueue', room_queue);
        start_queue();

    }
    var roomTimer = setInterval(drop_room, 5000);

    //checkbox
    $('.remember').toggle(function () {
        $('.check_box').addClass('check');
        $('.checkbox input').attr('checked', 'checked');
    }, function () {
        $('.check_box').removeClass('check');
        $('.checkbox input').attr('checked', '');
        $('.checkbox input').removeProp('checked');
    });

    //banner
    var $img = $('.img_banner img');
    var imgNum = $('.img_banner img').length;
    var imgWidth = 452;
    var nivoSlider = $('.nivoSlider');
    var $list = $('.nivo-controlNav a');
    var currentImg = 0;

    var changeImg = function () {
        //            $img.eq(currentImg).hide();
        $('.active').removeClass();
        currentImg++;
        imgTimer = setTimeout(changeImg, 5000);
        if (imgNum <= currentImg) currentImg = 0;
        {
            //            $img.eq(currentImg).fadeIn(800);
            $('#slider').stop(true, false).animate({ 'left': -currentImg * imgWidth }, 1000);
            $list.eq(currentImg).addClass('active');
        }
    }
    $list.click(function () {
        clearTimeout(imgTimer);
        $('.active').removeClass();
        $(this).addClass('active');
        currentImg = $(this).attr('rel');
        $('#slider').stop(true, false).animate({ 'left': -currentImg * imgWidth }, 1000);
        imgTimer = setTimeout(changeImg, 5000);
    });
    imgTimer = setTimeout(changeImg, 5000);

    //财富榜列表
    listNum = 0;
    $('.richness .list div').each(function () {
        $(this).css('backgroundPosition','0 '+'-'+listNum * 18+'px');
        listNum++;
    });
});


