function addtomultiview(id) {
  var mv = getmultiviewdata();
  var ok = true;
  var dup = false;
  var i;
  for(i = 0;i < mv.length;i++) {
    if(mv[i].id == id) {
      dup = true;
      break;
    }
  }
  if(dup) {
    ok = confirm('You already have this clip on your multiview page. Click "OK" to add a duplicate or "Cancel" otherwise.');
  }
  if(ok) {
    mv[mv.length] = {'id':id};
    setmultiviewcookie(mv);
    updatemultiviewcount();
    //document.location = '/bollywood/videos/multiview/';
    alert('Video added.\nTo view your videos, click the Multiview link at the top of the page.');
  }
}

function setmultiviewcookie(mv) {
  var i;
  var cookie = '';
  for(i = 0;i < mv.length;i++) {
    if(cookie) {
      cookie += '|';
    }
    cookie += escape(mv[i].id);
    if(mv[i].x) {
      cookie += ':'+mv[i].x+','+mv[i].y+','+mv[i].w;
    }
  }
  var exp = new Date();
  exp.setTime(exp.getTime()+(1000*60*60*24*30));
  var newcookie = 'uvmv='+cookie+'; path=/; expires='+exp.toGMTString();
  document.cookie = newcookie;
}

function getcookie(n) {
  var cookiestring = document.cookie;
  var pairs = cookiestring.split(/;\s+/);
  var i;
  var res = '';
  for(i = 0;i < pairs.length;i++) {
    var pair = pairs[i].split(/=/);
    if(pair.length == 2) {
      if(pair[0] == n) {
        res = unescape(pair[1]);
        break;
      }
    }
  }
  return res;
}

function getmultiviewdata() {
  var cookie = getcookie('uvmv');
  var data = new Array();
  if(cookie) {
    var blocks = cookie.split('|');
    var i;
    for(i = 0;i < blocks.length;i++) {
      var fields = blocks[i].split(':');
      var vid = '';
      var x = null;
      var y = null;
      var w = null;
      if((fields.length > 0) && fields[0]) {
        vid = unescape(fields[0]);
        if((fields.length > 1) && fields[1]) {
          var coords = fields[1].split(',');
          if(coords.length == 3) {
            x = coords[0];
            y = coords[1];
            w = coords[2];
          }
        }
        data[data.length] = {'id':vid,'x':x,'y':y,'w':w};
      }
    }
  }
  return data;
}

function updatemultiviewcount() {
  var ob = document.getElementById('multiviewcount');
  if(ob) {
    var data = getmultiviewdata();
    var count = data.length;
    var html = '&nbsp;('+count+' video'+((count == 1) ? '' : 's')+' added)';
    ob.innerHTML = html;
  }
}

function showmoretext(id,b) {
  var ob = document.getElementById(id+'short');
  var ob2 = document.getElementById(id+'full');
  var ob3 = document.getElementById(id+'more');
  var ob4 = document.getElementById(id+'less');
  if(ob) {
    ob.style.display = b ? 'none' : 'inline';
  }
  if(ob2) {
    ob2.style.display = b ? 'inline' : 'none';
  }
  if(ob3) {
    ob3.style.display = b ? 'none' : 'inline';
  }
  if(ob4) {
    ob4.style.display = b ? 'inline' : 'none';
  }

}

function vidhover(classname) {
  if(!classname) {
    classname = 'vidlink';
  }
  if(typeof($) == 'function') {
    $("."+classname).hover(
      function() {
        if($(this).find(".wow").length == 0) {
          var html = '<span style="position: absolute;" class="wow">';
          var src = $(this).find("img").attr("src");
          var tmpsrc;
          for(i = 0;i < 3;i++) {
            tmpsrc = src;
            if(i != 1) {
              tmpsrc = src.replace(/[^\/]\.jpg$/,(i+1)+'.jpg');
            }
            html += '<img src="'+tmpsrc+'" width="72" height="54" class="img prev z'+i+'" style="position: absolute; z-index: '+((i == 1) ? 2 : 1)+'">';
          }
          html += '</span>';
          $(this).prepend(html);
        }
        var delay = 500;
        $(this).find(".prev").show().animate({left: "-14px", top: "-80px", width: "100px",height:"75px"},500).filter(".z0").animate({left: "-116px"},delay).end().filter(".z2").animate({left:"88px"},delay);
      },
      function() {
        $(this).find(".wow").remove();
      }
    );
  }
}


