// ==UserScript==
// @name           Vkontakte video downloader [updated 2010.01.20]
// @namespace      http://vkontakte.ru/video*
// @description    add button to download video from vkontakte.ru
// @include        http://vkontakte.ru/video*
// @copyright		2009, .DeV!L (http://www.x-code.name/)
// @author			.DeV!L
// ==/UserScript==

if ((/video[-]?(\d+)/.exec(window.location))||(/video(.*)\&id=(\d+)/.exec(window.location)))
{

    var allText = document.documentElement.innerHTML;
	var vars = {vtag:"",host:"",uid:"",vkid:"",md_title:"",md_author:"",folder_id:""}
	var varsStr = ""
	var src = "";
	for(v in vars){
		var val = allText.match(v + ":[ ]?'(.*?)'");
		if(val){
			vars[v] = val[1];
			varsStr += v + "=" + vars[v] + "&";
		}
	}
	if (vars.host.indexOf('vkadre') != -1){
		var link = 'http://'+vars.host+'/assets/videos/'+vars.vtag+vars.vkid+'.vk.flv';
	}else{
		var link = 'http://cs'+vars.host+'.vkontakte.ru/u'+vars.uid+'/video/'+vars.vtag+'.flv';
	}
	var cont = document.createElement("div");
	cont.setAttribute("style", "float:right");
    var addon=document.createElement("a");
    addon.setAttribute("href", link);
    addon.innerHTML="\u0421\u043A\u0430\u0447\u0430\u0442\u044C"; 
    cont.appendChild(addon);
	document.getElementById("bigSummary").appendChild(cont);
}