﻿try {
    $('a.media').media();
    var layerWin = document.getElementById("repalylayer");
    $("div.Win_overlay").css("height", document.documentElement.offsetHeight + "px");
    var ft = parseInt(document.documentElement.scrollTop + (document.documentElement.clientHeight - layerWin.offsetHeight) / 2);
    layerWin.style.top = ft + "px";
    var flag = 0;
    var speed = 10;
    var acc = 2;
    var ArticleID = $("#ArticleID").val();
} catch (e) { }

function move(){
var t=layerWin.style.top;
var top=parseInt(t.substring(0,t.length-2));
var myhigh=parseInt(document.documentElement.scrollTop+(document.documentElement.clientHeight-layerWin.offsetHeight)/2);
if(top<myhigh-speed){layerWin.style.top=top+speed+"px";}
else if(top>myhigh+speed){layerWin.style.top=top-speed+"px";}
setTimeout("move()",2);
}

function scall(){if(flag==0){move();flag=1;}}



function closerepaly(){
    $(layerWin).hide();
    $("div.Win_overlay").hide();
    
}

function Add(version) {
    if (typeof version == 'undefined') version = "";
    if($("#Content").val()==""||$("#Content").val()=="在此发表评论！"){
        alert("请输入评论内容");
        $("#Content").focus();
        return;
    }
    if($("#Content").val().length>5000){
        alert("评论内容过长");
        $("#Content").focus();
        return;      
    }
    var Info={};
    Info.Content = $("#Content").val();
    if ($("#hidename").length == 0) {
        Info.Hidename = false;
    }
    else {
        Info.Hidename = $("#hidename")[0].checked;
    }
    Info.ArticleID=ArticleID; 
    $.post("/ArticleComment.Add"+version+".data",Info,function(data){
        if(data=="ok"){
            alert("发表成功");
            location.reload();
        }else{
            alert(data);
        }
    })
}

function Support(ID){
    $.post("/ArticleComment.Support.data",{ID:ID,ArticleID:ArticleID},function(data){
        self.location.reload();
    })
}

function Del(ID){
    $.post("/ArticleComment.Del.data",{ID:ID,ArticleID:ArticleID},function(data){
     if(data=="ok"){
            alert("删除成功");
            self.location.reload();
        }else{
            alert(data);
        }        
    })
}

function Against(ID){
    $.post("/ArticleComment.Against.data",{ID:ID,ArticleID:ArticleID},function(data){
        self.location.reload();
    })
}

function Repaly(version) {
    if (typeof version == 'undefined') version = "";
    if($("#repalycontent").val()==""||$("#repalycontent").val()=="在此发表评论！"){
        alert("请输入评论内容");
        $("#repalycontent").focus();
        return;
    }
    var Info={};
    Info.Content=$("#repalycontent").val();
    //Info.hidename=$("#repalyhidename")[0].checked;
    Info.ArticleID=ArticleID;
    Info.ParentID=repalyid
    $.post("/ArticleComment.Add" + version + ".data", Info, function(data) {
        if(data=="ok"){
            alert("发表成功");
            location.reload();
        }else{
            alert(data);
        }
    })
}

function PreRepaly(id){
    repalyid=id;
    $(layerWin).show();
    $("#repalycontent").focus();
    $("div.Win_overlay").show();
}

window.onscroll = scall;

//处理图片宽度600
$(document).ready(function(){    
    $("#NewsContent img").each(function(i){ 
        if(this.width>600) 
        {
             
            this.height = this.height*((600.0)/this.width);
            this.width=600; 
        }
    }); 
}); 
