function Video(video) {
  var me = this;
  me.fid = video.fid;
  me.uid = video.uid;
  me.fileName = video.fileName;
  me.fileSize = video.fileSize;
  me.width = video.width;
  me.height = video.height;
  me.createDate = new Date();
  me.createDate.setTime(video.createDate * 1000);
  me.mode = video.mode;
  me.title = video.title;
  me.description = video.description;
  me.category = video.category;
  me.featured = video.featured;
  me.vcode = video.vcode;
  me.duration = video.duration;
  me.originalFilename = video.originalFilename;
  me.disk = video.disk;
  me.url = video.url;
  me.flagged = video.flagged;
  me.thumbnailNo = video.thumbnailNo;
  me.ugid = video.ugid;
  me.uploadStatus = video.uploadStatus;
  me.viewCount = video.viewCount;
  me.viewCount24 = video.viewCount24;
  me.viewCount168 = video.viewCount168;
  me.lastViewDate = new Date();
  me.lastViewDate.setTime(video.lastViewDate * 1000);
  me.lastViewIp = video.lastViewIp;
  me.ratingCount = video.ratingCount;
  me.ratingSum = video.ratingSum;
  me.ratingAvg = video.ratingAvg;
  me.ratingCount24 = video.ratingCount24;
  me.ratingSum24 = video.ratingSum24;
  me.ratingAvg24 = video.ratingAvg24;
  me.ratingCount168 = video.ratingCount168;
  me.ratingSum168 = video.ratingSum168;
  me.ratingAvg168 = video.ratingAvg168;
  me.lastVoteDate = new Date();
  me.lastVoteDate.setTime(video.lastVoteDate * 1000);
  me.lastVoteIp = video.lastVoteIp;
  me.commentCount = video.commentCount;
  me.commentCount24 = video.commentCount24;
  me.commentCount168 = video.commentCount168;
  me.favouritedCount = video.favouritedCount;
  me.flagCount = video.flagCount;
  me.countersLastUpdated = new Date();
  me.countersLastUpdated.setTime(video.countersLastUpdated * 1000);
  me.tags = video.tags;
  me.comments = video.comments;
  me.userName = video.userName;
  me.categoryName = video.categoryName;
  me.ugName = video.ugName;
  me.chid = video.chid;
  me.chName = video.chName;
  me.own = video.own;
  me.playUrl = video.playUrl;
  me.categoryUrl = video.categoryUrl;
  me.userUrl = video.userUrl;
  me.usergroupUrl = video.usergroupUrl;
  me.stillUrls = video.stillUrls;
  me.isWideScreen = video.isWideScreen;
  me.embedWidth = video.embedWidth;
  me.toolbarHeight = video.toolbarHeight;

  me.getFCode = function() {
    return '' + me.disk + '.' + me.fid + '.' + me.uid + '.' + 1;
  }

  me.getPlayUrl = function() {
    return me.playUrl;
  }

  me.getDefaultThumbnailUrl = function() {
    return me.stillUrls[me.thumbnailNo - 1];
  }

  me.getThumbnailUrl = function(i) {
    return me.stillUrls[i - 1];
  }

  me.getStarsCount = function(interval) {
    var avg = 0;
    if (interval == 0) avg = me.ratingAvg;
    if (interval == 1) avg = me.ratingAvg24;
    if (interval == 2) avg = me.ratingAvg168;
    r = Math.round(avg*2) / 2;

    var avgStr = '0';
    if(r == 0.5) {
       avgStr = '05';
    } else {
      if(r != Math.round(r)) avgStr = 10*r;
      else avgStr = r;
    }
    return avgStr;
  }

  me.getStarsUrl = function(interval) {
    return 'images/rate/sfff' + me.getStarsCount(interval) + '.gif';
  }

  me.getCategoryUrl = function() {
    return me.categoryUrl;
  }

  me.getUserUrl = function() {
    return me.userUrl;
  }

  me.getUserName = function() {
    return me.userName;
  }

  me.getUploaderUrl = function() {
    //if (me.ugid == 1) return me.userUrl;
    //else return me.usergroupUrl; 
    return me.userUrl;
  }

  me.getUploaderName = function() {
    //if (me.ugid == 1) return userName;
    //else return ugName;
    return me.userName;
  }

  me.getFormattedDuration = function() {
    var h = Math.floor(me.duration / 3600);
    var d = me.duration % 3600;
    var m = Math.floor(d / 60);
    var s = d % 60;
    var durationstring = '';
    if(h > 0) {
      if(h < 10) durationstring += '0';
      durationstring += h + ':';
    }
    if(m < 10) durationstring += '0';
    durationstring += m + ':';
    if(s < 10) durationstring += '0';
    durationstring += s;
    return durationstring;
  }

  me.getFormattedDate = function() {
    var year = me.createDate.getYear();
    if(year < 1900) year += 1900;
    var month = me.createDate.getMonth() + 1;
    var day = me.createDate.getDate();
    var datestring = '' + year + '.';
    if(month < 10) datestring += '0';
    datestring += month + '.';
    if(day < 10) datestring += '0';
    datestring += day;
    datestring += '.';
    return datestring;
  }

  me.getFormattedViews = function(interval) {
    var number = 0;
    if (interval == 0) number = me.viewCount;
    if (interval == 1) number = me.viewCount24;
    if (interval == 2) number = me.viewCount168;
    var s = new String(number);
    var r = "";
    var c = 0;
    for (var i = s.length - 1; i >= 0; i--) {
      r = s.charAt(i) + r;
      c++;
      if (i != 0 && c != 0 && c % 3 == 0) r = " " + r;
    }
    return r;
  }

  me.getRoundedAvg = function(interval) {
    var avg = 0;
    if (interval == 0) avg = me.ratingAvg;
    if (interval == 1) avg = me.ratingAvg24;
    if (interval == 2) avg = me.ratingAvg168;
    return Math.round(100 * avg) / 100;
  }

  me.getRatingCount = function(interval) {
    if (interval == 0) return me.ratingCount;
    if (interval == 1) return me.ratingCount24;
    if (interval == 2) return me.ratingCount168;
  }

  me.getShortDescription = function(length) {
    if (length == undefined) length = 150;
    if (me.description.length <= length) return me.description;
    return me.description.substr(0, length - 4) + '... ';
  }

  me.getFullDescription = function() {
    return me.description;
  }

  me.getShortTagsArray = function(length) {
    if (length == undefined) length = 105;
    var tagsStringLength = 0;
    for (var i=0; i<me.tags.length; i++) {
      tagsStringLength += me.tags[i].tag.length;
      if (i != 0) tagsStringLength += 2;
      if (tagsStringLength > length) return me.tags.slice(0, i);
    }
    return me.tags;
  }

  me.getFullTagsArray = function() {
    return me.tags;
  }

  me.getTagUrl = function(i) {
    return me.tags[i].tagUrl;
  }

  me.getNewEmbedHeight = function(new_width) {
    if (me.isWideScreen) {
      return Math.round(new_width * 9 / 16) + me.toolbarHeight;
    } else {
      return Math.round(new_width * 3 / 4) + me.toolbarHeight;
    }
  }

  me.getNewEmbedWidth = function(new_height) {
    if (me.isWideScreen) {
      return Math.round((new_height - me.toolbarHeight) * 16 / 9);
    } else {
      return Math.round((new_height - me.toolbarHeight) * 4 / 3);
    }
  }

  me.getNewEmbedCode = function(new_width) {
    var new_height = me.getNewEmbedHeight(new_width);
    var embedCode = '<object width="'+new_width+'" height="'+new_height+'"><param name="movie" value="http://videa.hu/flvplayer.swf?v=' + me.vcode + '" /><param name="allowscriptaccess" value="always" /><param name="allowFullScreen" value="true" /><embed width="'+new_width+'" height="'+new_height+'" src="http://videa.hu/flvplayer.swf?v=' + me.vcode + '" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" /></object><br /><a href="' + me.playUrl + '" title="' + me.title + '">szólj hozzá: ' + me.title + '</a>';
    return embedCode;
  }

  me.getEmbedCode = function() {
    return me.getNewEmbedCode(me.embedWidth);
  }
}

