﻿$(document).ready(

    function() {
        $(".paihangbang dt").mouseover(function() {

            $(".paihangbang dt.move").attr("class", "");
            $(this).parent().find("dd").hide();
            $(this).next("dd").show();
            $(this).attr("class", "move");
        });

        var sourceKey = "热门搜索：贵妃椅 装饰柜 无框画";
        $('#key').click(function() {
            if (sourceKey == $('#key').val()) {
                $('#key').val('');
            }
        });


        $("#key").keypress(function(e) {
            if (e.keyCode == 13) {
                SearchFunc();
            }
        });

        $('#searchBtn').click(function() {
            SearchFunc();
        });


        function SearchFunc() {
            var key = $('#key').val();
            if (key == sourceKey) {
                alert("请输入内容");
                return false;
            } else {
                key = key.replace(new RegExp('-', 'g'), '^^');
                var url = "/products/0-0-0-0---" + key + "-0---1.html";
                window.location = url;
            }
        }


        $('#mY_left_Yellow,#mY_left_Blue,#mY_left_Green').mouseover(function(e) {

            var id = $(this).attr("id");
            var otherId = id.replace("left", "right");
            var group = id.split('_')[2];
            $('#' + otherId).attr("class", "rightout_" + group);
            $(this).attr("class", "lefton_" + group);
            $('.mainYellow_' + group + '_2').hide();
            $('.mainYellow_' + group + '_1').show();
        });

        $('#mY_right_Yellow,#mY_right_Blue,#mY_right_Green').mouseover(function(e) {
            var id = $(this).attr("id");
            var otherId = id.replace("right", "left");
            var group = id.split('_')[2];
            $('#' + otherId).attr("class", "leftout_" + group);
            $(this).attr("class", "righton_" + group);
            $('.mainYellow_' + group + '_1').hide();
            $('.mainYellow_' + group + '_2').show();
        });

        $('.btnFavorite').click(function() {
            var productId = $(this).attr('tip');
            var date = new Date();
            var options = {
                url: "/Product/Favorite",
                data: "id=" + productId + "&v=" + date.getSeconds(),
                type: "GET",
                dataType: "HTML",
                timeout: 10000,
                error: function() { alert("收藏失败") },
                success: function(message) { alert(message); }
            }
            $.ajax(options);
        });

        /*alert layer*/
        $(".mainleft_content").hover(function() {

            $(this).css("position", "relative");
            $('.tt', this).css("left", $(this).width()+8);
            $('.tt', this).show();
        },
                function() {
                    $(this).css("position", "static");
                    $('.tt', this).hide();
                }
            );

        /*exchange*/
        $('#mainGreyLA_left').mouseover(function(e) {
            $('#mainGreyLA_left').attr("class", "Grey_lefton");
            $('#mainGreyLA_right').attr("class", "Grey_rightout");
            $('.mainGreyLA_btA').hide();
            $('.mainGreyLA_bt').show();
        });
        $('#mainGreyLA_right').mouseover(function(e) {
            $('#mainGreyLA_right').attr("class", "Grey_righton");
            $('#mainGreyLA_left').attr("class", "Grey_leftout");
            $('.mainGreyLA_bt').hide();
            $('.mainGreyLA_btA').show();
        });

        /**************list page****************/
        var viewtype = 0;

        $('#squarebtn').click(function() {
            $('.channel-rightF').show();
            $('.channel-rightE').hide();
            $('#SquareModel').show();
            $('#listModel').hide();
            viewtype = 1;
            $.ajax({
                type: "GET",
                url: "/Product/ViewType",
                data: "viewtype=" + viewtype
            });
        });

        $('#listbtn').click(function() {
            $('.channel-rightE').show();
            $('.channel-rightF').hide();
            $('#SquareModel').hide();
            $('#listModel').show();
            viewtype = 0;
            $.ajax({
                type: "GET",
                url: "/Product/ViewType",
                data: "viewtype=" + viewtype
            });
        });

        $('#pageSubmit').click(function() {
            var pageValue = $('#txtPageValue').val();
            var pageTotal = $('#PageCount').val();
            if (pageValue == "") {
                alert("请输入页码!");
                return false;
            }
            if (isNaN(pageValue)) {
                alert("您输入的页码有误!");
                return false;
            }
            if (parseInt(pageTotal) < parseInt(pageValue)) {
                alert("您输入的页码大于当前页码");
                return false;
            }

            document.forms["FormPager"].submit();
            return true;
        });
    });

      