function Video(){
   
}
Video.prototype.draw = function(){
    
    
       
        Post('/index/video',{},function(json)
        {  
          var html = "";
           for(var i=0;i<json.length;i++)
           {
               html +='<div class="blockVideoShow"><a href="/video/index/video/'+json[i].id+'">\
        <div class="imgVideo" style="background: url(http://i2.ytimg.com/vi/'+json[i].imp+'/default.jpg) no-repeat;"></div></a>\
        <div class="title">'+json[i].title+'</div>\
        <div class="param">\
            <div class="showIconB">\
                <div class="icon"></div>\
                <div>'+json[i].look+'</div><div class="clear"></div>\
            </div>\
            <div class="clear"></div>\
        </div>\
    </div>';
           }
           html +='<div class="clear"></div>';
            window.document.getElementById('videoCB').innerHTML = html;

        },'json');    
    
    
};

Video.prototype.showAther=function()
{
   var Pager=publishPage;
   publishPage=publishPage+1;
   Post('/video/publish/page/'+Pager,{id:idVideo},function(json){
       var data=json.data;
       var n=data.length;
       var htm='';
       for(var i=0;i<n;i++)
       {
           htm+='<div class="block">\
        <a href="/video/index/id/'+data[i]['id']+'">\n\
                <div style="background: url(http://i2.ytimg.com/vi/'+data[i]['id']+'/default.jpg) no-repeat;" class="foto"></div>\
           <div class="text">\
               <div class="title">'+data[i]['title']+'</div>\
           </div>\
           <div class="clear"></div>\
        </a>\
     </div>';         
             
       }
       if(n>0)
       {
            if(!json.nextPage)
           {
                window.document.getElementById('pagerVideo').style.display='none';
                
           }
            window.document.getElementById('inVideosShow').innerHTML=htm;
       }
       else
       {
           window.document.getElementById('pagerVideo').style.display='none';
           
       }    
        
       
    },'json');
};

Video.prototype.showComment=function(allParam){
    var parUri='';
    if(allParam)
       parUri='/type/reload'; 
    
    Post('/video/comment'+parUri,{id:idVideo},function(json){
       var n=json.length;
       var htm='';
       window.document.getElementById('commentVideo').style.display='none';
       for(var i=0;i<n;i++)
       {
           htm+='<li>\
               <div class="contents">'+json[i]['text']+'</div>\
               <div class="nameUser">'+json[i]['nameUs']+'</div>\
            </li>';         
             
       }
       //alert(htm);
       
       window.document.getElementById('commentThis').innerHTML=htm;
       
        
    },'json');
};

Video.prototype.addComment=function (){
    var commentText=window.document.getElementById('comment').value;
    Post('/video/incomment',{id:idVideo,comment:commentText},function(json){
           if(json.ans==0)
           {
              window.document.getElementById('commentError').innerHTML=json.error; 
           }else
            {
                window.document.getElementById('comment').value='';
                Video.prototype.showComment(1);
            }
        },'json');
};

Video.prototype.textCounter=function( field, countfield ) {
  var maxlimit=500;
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );    
    return false;
  }
  else
  {
    //$(countfield).update();
    window.document.getElementById('counters').innerHTML=maxlimit - field.value.length;
  }
};

Video.prototype.showSearchResult=function()
{
    pageResultSearch=pageResultSearch+1;
    var searchText=window.document.getElementById('search').value;
    Post('/video/search',{search:searchText,typeQuery:'ajaxQuery',page:pageResultSearch},function(json){
           var n=json.length;
           if(n>0)
           {
               var html='';
               for(var i=0;i<n;i++)
               {
                   html+='<a href="/video/index/id/'+json[i]['id']+'">\
                            <div class="fotoBorders"><div class="foto" style="background: url(http://i2.ytimg.com/vi/'+json[i]['id']+'/default.jpg) no-repeat;"></div></div>\
                            <div class="text"><div class="title">'+json[i]['title']+'</div></div>\
                            <div class="clear"></div>\
                        </a>';
               }
               window.document.getElementById('searchResultBlock').innerHTML+= html;
           }
           else
           {
               window.document.getElementById('searchVideoPagers').style.display='none';               
           }    
        },'json');
   
};

var video = new Video();
