﻿//www.so138.com All rights reserved
/// <reference path="jquery-1[1].2.6-vsdoc.js" />



var so138 = {};


$(document).ready(function() {


    $("#search_btn").click(function() {

        var keystr = encodeURIComponent($(".search_key").val());
        window.location = "/so/f138.aspx?vfw=" + keystr;
        return false;

    });

    //搜索框回车提交搜索
    $(".search_key").keydown(
      function(event) {

          if (event.keyCode == 13) {
              if ($.trim($(".search_key").val()).length > 0) {
                  var keystr = encodeURIComponent($(".search_key").val());
                  window.location = "/so/f138.aspx?vfw=" + keystr;
                  return false;
              }
          }
      });

    $("#search_video_pager a").click(function() {

        $(".search-video-list").load($(this).attr("href"), { r: new Date().getTime() }, function() {
            //$(this).fadeIn();
        });

        return false;

    });



    $("#search_res_pager a").click(function() {

        $(".search-res-list").load($(this).attr("href"), { r: new Date().getTime() }, function() {
            //$(this).fadeIn();
        });

        return false;

    });


    $(so138).bind("onlogin", function() {

        alert("onlogin");

    });

});





jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


jQuery.fn.center = function() {
    var w = $(window);
    this.css({ "top": (w.height() - this.height()) / 2 + w.scrollTop() + "px", "left": (w.width() - this.width()) / 2 + w.scrollLeft() + "px" });
    return this;
}





//pop_window = function(url) {


//    $("#pop_window .html_content").load("/view/video_collection.aspx?video_id=" + $("#video_id").val() + "&r=" + new Date().getTime()), function() {
//        alert("++");
//    };

//}



$(document).ready(function() {

    //评论
    $("#video_comment").click(function() {

        alert($("#video_id").val());

    });


    //收藏





    $("##.nice_time").each(function() {


        var time1 = new Date($.trim($(this).text()));
        var time2 = new Date();

        var nice_time;


        var ticks = (time2 - time1) / 1000;



        if (ticks < 30) {

            nice_time = ticks + "秒之前";

        } else {

            ticks = Math.round(ticks / 60);

            if (ticks < 60) {
                nice_time = ticks + "分钟之前";
            } else {

                ticks = Math.round(ticks / 24);

                if (ticks < 24) {
                    nice_time = ticks + "分钟之前";
                } else {

                    ticks = Math.round(ticks / 30);

                    if (ticks < 30) {
                        nice_time = ticks + "天之前";
                    } else {
                        nice_time = ticks + "很久很久以前";
                    }

                }


            }

        }



        $(this).html(nice_time).show();

    });



});


