/***********jquery.lazyload.min.js begin************/

(function($,window,document,undefined){var $window=$(window);$.fn.lazyload=function(options){var elements=this;var $container;var settings={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:window,data_attribute:"original",skip_invisible:true,appear:null,load:null,placeholder:"http://icon.90sheji.com/images/lz.gif"};function update(){var counter=0;elements.each(function(){var $this=$(this);if(settings.skip_invisible&&!$this.is(":visible")){return}if($.abovethetop(this,settings)||$.leftofbegin(this,settings)){}else{if(!$.belowthefold(this,settings)&&!$.rightoffold(this,settings)){$this.trigger("appear");counter=0}else{if(++counter>settings.failure_limit){return false}}}})}if(options){if(undefined!==options.failurelimit){options.failure_limit=options.failurelimit;delete options.failurelimit}if(undefined!==options.effectspeed){options.effect_speed=options.effectspeed;delete options.effectspeed}$.extend(settings,options)}$container=(settings.container===undefined||settings.container===window)?$window:$(settings.container);if(0===settings.event.indexOf("scroll")){$container.bind(settings.event,function(){return update()})}this.each(function(){var self=this;var $self=$(self);self.loaded=false;if($self.attr("src")===undefined||$self.attr("src")===false){if($self.is("img")){$self.attr("src",settings.placeholder)}}$self.one("appear",function(){if(!this.loaded){if(settings.appear){var elements_left=elements.length;settings.appear.call(self,elements_left,settings)}$("<img />").bind("load",function(){var original=$self.attr("data-"+settings.data_attribute);$self.hide();if($self.is("img")){$self.attr("src",original)}else{$self.css("background-image","url('"+original+"')")}$self[settings.effect](settings.effect_speed);self.loaded=true;var temp=$.grep(elements,function(element){return !element.loaded});elements=$(temp);if(settings.load){var elements_left=elements.length;settings.load.call(self,elements_left,settings)}}).attr("src",$self.attr("data-"+settings.data_attribute))}});if(0!==settings.event.indexOf("scroll")){$self.bind(settings.event,function(){if(!self.loaded){$self.trigger("appear")}})}});$window.bind("resize",function(){update()});if((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)){$window.bind("pageshow",function(event){if(event.originalEvent&&event.originalEvent.persisted){elements.each(function(){$(this).trigger("appear")})}})}$(document).ready(function(){update()});return this};$.belowthefold=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=(window.innerHeight?window.innerHeight:$window.height())+$window.scrollTop()}else{fold=$(settings.container).offset().top+$(settings.container).height()}return fold<=$(element).offset().top-settings.threshold};$.rightoffold=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=$window.width()+$window.scrollLeft()}else{fold=$(settings.container).offset().left+$(settings.container).width()}return fold<=$(element).offset().left-settings.threshold};$.abovethetop=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=$window.scrollTop()}else{fold=$(settings.container).offset().top}return fold>=$(element).offset().top+settings.threshold+$(element).height()};$.leftofbegin=function(element,settings){var fold;if(settings.container===undefined||settings.container===window){fold=$window.scrollLeft()}else{fold=$(settings.container).offset().left}return fold>=$(element).offset().left+settings.threshold+$(element).width()};$.inviewport=function(element,settings){return !$.rightoffold(element,settings)&&!$.leftofbegin(element,settings)&&!$.belowthefold(element,settings)&&!$.abovethetop(element,settings)};$.extend($.expr[":"],{"below-the-fold":function(a){return $.belowthefold(a,{threshold:0})},"above-the-top":function(a){return !$.belowthefold(a,{threshold:0})},"right-of-screen":function(a){return $.rightoffold(a,{threshold:0})},"left-of-screen":function(a){return !$.rightoffold(a,{threshold:0})},"in-viewport":function(a){return $.inviewport(a,{threshold:0})},"above-the-fold":function(a){return !$.belowthefold(a,{threshold:0})},"right-of-fold":function(a){return $.rightoffold(a,{threshold:0})},"left-of-fold":function(a){return !$.rightoffold(a,{threshold:0})}})})(jQuery,window,document);

/***********jquery.lazyload.min.js end************/


$(window).load(function(){
    $("img.lazy").lazyload({
        effect: "show",
        threshold : 300, 
        placeholder : "http://js.ooopic.com/2015/image/lz.gif"
    });
});

/*搜索or收藏*/
$(function(){
    //导航部分切换
    $(".secord-nav-box .secord-nav-a").hover(function(){
        $(this).addClass("current").parent(".secord-nav-box").siblings().children(".secord-nav-a").removeClass("current");
        $(this).siblings(".thrid-nav").show().parent(".secord-nav-box").siblings().children(".thrid-nav").hide();

    });
    $(".secord-nav-box,.thrid-nav").mouseleave(function(){
        $('.thrid-nav').hide();
        $(".secord-nav-box").children(".secord-nav-a").removeClass("current");
    });


    //头部固定
    var animateFlag = 1;
    $(document).scroll(function () {
        var scrollTop = $(document).scrollTop();
        if (scrollTop > 200) {
            $("#fixed-head").css('display', 'block');
            if (animateFlag) {
                animateFlag = 0;
                $("#fixed-head").stop();
                $("#fixed-head").animate({
                    'top': '0px'
                }, 500);
            }
        } else {
            $("#fixed-head").css('display', 'none');
            if (animateFlag == 0) {
                animateFlag = 1;
                $("#fixed-head").stop();
                $("#fixed-head").animate({
                    'display': 'none',
                    'top': '-60px'
                }, 500);
            }
        }
    });


    pageLoad();
    //点击收藏
    $('.collect').live('click',function(){
        var _this = $(this);
        var h = $(this);
        var f = h.offset().left;
        var d = h.offset().top;
        var picid = $(this).attr('picid');
        var is58pic = $(this).attr('isfrom');
        if ($(this).hasClass('cancle-collect')) {//取消收藏
            $("#coll-prompt").css({
                top: d + "px",
                left: f - 5 + "px",
                position: "absolute"
            }).show().animate({
                top: "-=80px"
            }, 200);
            $("#coll-prompt").css('z-index',10);
            $("#coll-prompt .sure").attr('data-id', $(this).attr('picid'));
            $("#coll-prompt .sure").attr('picid', picid);
        } else { //收藏

            if (!(picid > 0)) {
                alert('收藏失败');
            }
            $.ajax({
                type: 'get',
                jsonp: 'callback',
                dataType: 'jsonp',
                url: 'http://tj.ooopic.com/api/api.2013.php?action=sc&picid=' + picid+'&classid='+is58pic,
                success: function (data) {
                    if (data.data == 1) {
                        $('.addjian[picid='+picid+']').html(parseInt($('.addjian[picid='+picid+']').html())+1);
                        $(".coll-success").css({
                            top: d + "px",
                            left: f - 5 + "px",
                            position: "absolute"
                        }).show().animate({
                            top: "-=65px"
                        }, 200);
                        setTimeout(function () {
                            $(".coll-success").hide();
                        }, 1000);
                        _this.addClass('cancle-collect').text('取消收藏');

                    } else if (data.data == -1) {
                        $(".coll-login").css({
                            top: d + "px",
                            left: f - 5 + "px",
                            position: "absolute"
                        }).show().animate({
                            top: "-=65px"
                        }, 200);
                        //显示新版登录
                        //newLogin();
                        setTimeout(function () {
                            $(".coll-login").hide();
                        }, 1000);
                    }
                }
            });

        }

    });

    //确定取消收藏
    $('#coll-prompt').on('click', '.sure', function () {
        $('#coll-prompt').hide();
        //var picid = $('#coll-prompt').attr('picid');
        var picid = $(this).attr('picid');
        var h = $('.collect[picid="' + picid + '"]');
        var f = h.offset().left;
        var d = h.offset().top;

        h.text('收藏').removeClass('cancle-collect');
        $(".coll-cancel").css({
            top: d + "px",
            left: f - 5 + "px",
            position: "absolute"
        }).show().animate({
            top: "-=5px"
        }, 200);
        setTimeout(function () {
            $(".coll-cancel").hide();
        }, 1000);
        cancleScPic(picid);
    });

    function cancleScPic(picid) {
        if (!(picid > 0)) {
            alert('取消收藏失败');
        }
        $.ajax({
            type: 'get',
            jsonp: 'callback',
            dataType: 'jsonp',
            url: 'http://tj.ooopic.com/api/api.2013.php?action=canclesc&picid=' + picid,
            success: function (data) {
                $('.addjian[picid='+picid+']').html(parseInt($('.addjian[picid='+picid+']').html())-1);
            }
        });
    }

    //取消
    $('#coll-prompt').on('click', '.cancle', function () {
        $('#coll-prompt').hide();
    });
    

    //if($('.isfrom').attr('name')!='index'){
        $(document).on('click',function(e){
            e.stopPropagation();
            $('.hot_list').hide();
        });

        $('.header .search_btn').click(function(){
            goSearch(0,$('.header .search-input'));
        });
        $('.fixed-header .search_btn').click(function(){
            goSearch(0,$('.fixed-header .search-input'));
        });

        $(".search-input").on('click',function(e){
            $(this).attr('placeholder','');
            return false;
        });

        $(".header .search-input,.fixed-header .search-input").focus(function(e){
            var data = $(this).attr('data');
            e.stopPropagation();
            $(this).css('color','black');
            if($('.'+data+' .hot_list').find('a').size()>0){
                $('.'+data+' .hot_list').show();
            }

            getHotWord(data);

            var nowplace=-1;
             $(this).on('keyup', function (e) {
                    var _this = $(this);
                    if (e.keyCode == "38" || e.keyCode == "40") {
                            var count = $('.'+data+' .hot_list').find('a').size()-1;
                            if(e.keyCode=="38"){
                               if(nowplace=="-1" || nowplace=="0"){
                                    nowplace=count;
                                }else{
                                    nowplace=nowplace-1;
                                }
                            }else{
                                if(nowplace==count){
                                    nowplace=0;
                                }else{
                                    nowplace=nowplace+1;
                                }
                            } 
                            var isval = $('.'+data+' .hot_list').find('.sokeyup_1').eq(nowplace).find('.sokeyup_2').eq(0).html();
                            $(".search-input").val(isval);
                            $('.'+data+' .hot_list').find('.sokeyup_1').eq(nowplace).css('background','rgb(235, 235, 235)').siblings().css('background','rgb(255, 255, 255)');
                            return false;

                    } else if (e.keyCode == "13") {
                        goSearch(0, _this);
                        return false;
                    }
                    getHotWord(data);
                    return false;
              })
        })


        $(".search-input").on('blur',function(e) {
             $(this).css('color','#b2b2b2');
        })

        function getHotWord(str){
            var timeout;
            var val = $("."+str+" .search-input").val();
            if (val != '') {
                clearTimeout(timeout);
                timeout = setTimeout(function(){
                    $.ajax({
                        url: 'http://so.ooopic.com/cueWord.php',
                        type: 'GET',
                        jsonp: 'callback',
                        dataType: 'jsonp',
                        data: {kw: val},

                        success: function(data){
                            if(data==""){
                                $('.'+str+' .hot_list').css('display','none');
                            }else{
                                $('.'+str+' .hot_list').html('').css('display','block').append(data);
                            }
                        }
                    });
                },500);
            }
        }

        function goSearch(type, kwID) {
            var from = arguments[0];
            var kw;
            kw = kwID.val();
            defaultkw = kwID.attr('defaultv');

            if (kw == '') {
                alert("请输入要查找的关键词");
                kwID.focus();
                return false;
            } else {
                kw = encodeURI(kw);
                var r = new Date();
                r = r.getTime();
                var url = "http://so.ooopic.com/jumpkid.php?kw=" + kw + "&r=" + r + "&lx=keywordid&callback=?";
                $.getJSON(url, function (date) {
                    date = date.split('|');
                    if (date[0] > 0) {
                        if (date[1] == -15) {
                            location.href = "http://so.ooopic.com/sousuo/" + date[0] + "/";
                            return false;
                        } else {
                            location.href = "http://so.ooopic.com/search-" + date[2] + "-" + date[1] + "-0_0____0_ooo_0_1_0.html";
                            return false;
                        }
                    } else {
                        location.href = "http://so.ooopic.com/search-" + kw + "-" + type + "-______oo__.html";
                        return false;
                    }
                });
            }
        }
    //}



        //访问顶部
        $("#back-ToTop").bind("click", function(){
            var _this = $(this);
            $('html,body').animate({ scrollTop: 0 }, 500 ,function(){});
            return false;
        });

})


/*底部*/
function pageLoad(){
    var endT=new Date();
    var endTime=endT.getTime();
    obj.loadTime=(endTime-beginTime)/1000;
    $("#opentime").html(" " + obj.loadTime + "");
}

function PVTJ(){
    $.getJSON("http://tj.ooopic.com/index.php?m=pagePVTJ&picid="+obj.picid+"&exeCode="+obj.exeCode+"&exeTime="+obj.exeTime+"&loadCode="+obj.loadCode+"&loadTime="+obj.loadTime+"&kid="+obj.kid+"&bigclassid="+obj.bigclassid+"&smallclassid="+obj.smallclassid+"&page="+obj.page+"&callback=?&time="+(new Date()).getTime());

    if(isHasParam()){
       return false;
    }
    // 百度统计
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?6260fe7b21d72d3521d999c79fe01fc7";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
    $("img[src='http://eiv.baidu.com/hmt/icon/21.gif']").hide();

    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?5b1cb8ea5bd686369a321f1c5e6408b6";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
    var countshu = $('#wrap').attr('count');
    if(countshu!=0){
        (function(){
            var bp = document.createElement('script');
            bp.src = '//push.zhanzhang.baidu.com/push.js';
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(bp, s);
        })();
    }
    ////360搜索自动收录JS代码
    //var code360 = document.createElement("script");
    //code360.src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?"+obj.code360:"https://jspassport.ssl.qhimg.com/11.0.1.js?"+obj.code360;
    //var d360 = document.getElementsByTagName("script")[0];
    //d360.parentNode.insertBefore(code360, d360);
    //var _t360 = _t360 || [];
    //(function() {
    //    var code360 = document.createElement("script");
    //    code360.src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?"+obj.code360:"https://jspassport.ssl.qhimg.com/11.0.1.js?"+obj.code360;
    //    var d360 = document.getElementsByTagName("script")[0];
    //    d360.parentNode.insertBefore(code360, d360);
    //})();

    //360搜索自动收录JS代码
    var code360 = document.createElement("script");
    code360.setAttribute("id","sozz");
    code360.src = (document.location.protocol == "http:") ? "http://s2.qhimg.com/static/ab77b6ea7f3fbf79.js?"+obj.code360:"http://s2.qhimg.com/static/ab77b6ea7f3fbf79.js?"+obj.code360;
    var d360 = document.getElementsByTagName("script")[0];
    d360.parentNode.insertBefore(code360, d360);

}

function CateLoadTJ(exeCode,loadCode){
    $.getJSON("http://tj.ooopic.com/index.php?m=pagePVTJ&picid="+obj.picid+"&exeCode="+exeCode+"&exeTime="+obj.exeTime+"&loadCode="+loadCode+"&loadTime="+obj.loadTime+"&kid="+obj.kid+"&bigclassid="+obj.bigclassid+"&smallclassid="+obj.smallclassid+"&page="+obj.page+"&callback=?&time="+(new Date()).getTime());
}
function PageLoadTJ(exeCode,loadCode,page){
    $.getJSON("http://tj.ooopic.com/index.php?m=pagePVTJ&picid="+obj.picid+"&exeCode="+exeCode+"&exeTime="+obj.exeTime+"&loadCode="+loadCode+"&loadTime="+obj.loadTime+"&kid="+obj.kid+"&bigclassid="+obj.bigclassid+"&smallclassid="+obj.smallclassid+"&page="+page+"&callback=?&time="+(new Date()).getTime());
}

function isHasParam()    {
    var href = window.location.href;
    if(href.indexOf("Track")>0){
        return false;
    }else if(href.indexOf("?")>0){
        return true;
    }else{
        return false;
    }
}