function OpenURL()
{
var url = chrome.i18n.getMessage("link");
	chrome.tabs.create(
		{
			url: url
		}
	);
}

function Version()
{
//Получить UserAgent браузера
var ua = navigator.userAgent.toLowerCase();
//"Вычленение" номера версии
var temp = ua.indexOf("chrome");
var chromeVersion = ua.substring(temp);
temp = chromeVersion.indexOf(" safari");
chromeVersion = chromeVersion.substring(7,temp);
//Разбиваем номер версии на 4 числа (избавляемся от точек)
var chromeVer = new Array();
chromeVer = chromeVersion.split(".");
/* Теперь номер версии выглядит так:
 * chromeVer[0] - первое число
 * chromeVer[1] - второе число
 * chromeVer[2] - третье число
 * chromeVer[3] - четвертое число
*/
var str = (chromeVer[0] + '.' + chromeVer[1] + '.' + chromeVer[2] + '.' + chromeVer[3]);
return str;
}

function Compare(a, b) {
	if (!a||!b) { return true };
	am = a.split(".");
	bm = b.split(".");
	if ((bm[2]*1>am[2]*1)||((bm[2]*1==am[2]*1)&&(bm[3]*1>am[3]*1))) {
		return true
	} else { return false }
}

function Update(){
	$.getJSON('http://download.my-chrome.ru/portable.json', {}, function(json){
	if (json) {
		if (Compare(localStorage["wsv"], json.win.sv)&&localStorage["nws"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.win.sv+' Stable for Windows');
			noti.show();
		};
		if (Compare(localStorage["wbv"], json.win.bv)&&localStorage["nwb"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.win.bv+' Beta for Windows');
			noti.show();
		};
		if (Compare(localStorage["wdv"], json.win.dv)&&localStorage["nwd"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.win.dv+' Dev for Windows');
			noti.show();
		};
		if (Compare(localStorage["wcv"], json.win.cv)&&localStorage["nwc"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.win.cv+' Canary for Windows');
			noti.show();
		};
		if (Compare(localStorage["wspv"], json.win.spv)&&localStorage["nwsp"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Portable Chrome '+json.win.cv+' for Windows');
			noti.show();
		};
		if (Compare(localStorage["lsv"], json.linux.sv)&&localStorage["nls"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.linux.sv+' Stable for Linux');
			noti.show();
		};
		if (Compare(localStorage["lbv"], json.linux.bv)&&localStorage["nlb"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.linux.bv+' Beta for Linux');
			noti.show();
		};
		if (Compare(localStorage["ldv"], json.linux.dv)&&localStorage["nld"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.linux.dv+' Dev for Linux');
			noti.show();
		};
		if (Compare(localStorage["msv"], json.mac.sv)&&localStorage["nms"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.mac.sv+' Stable for Mac OS');
			noti.show();
		};
		if (Compare(localStorage["mbv"], json.mac.bv)&&localStorage["nmb"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.mac.bv+' Beta for Mac OS');
			noti.show();
		};
		if (Compare(localStorage["mdv"], json.mac.dv)&&localStorage["nmd"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.mac.dv+' Dev for Mac OS');
			noti.show();
		};
		if (Compare(localStorage["mcv"], json.mac.cv)&&localStorage["nmc"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.mac.cv+' Canary for Mac OS');
			noti.show();
		};
		if (Compare(localStorage["csv"], json.cos.sv)&&localStorage["ncs"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.cos.sv+' Stable for Chromebook');
			noti.show();
		};
		if (Compare(localStorage["cbv"], json.cos.bv)&&localStorage["ncb"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.cos.bv+' Beta for Chromebook');
			noti.show();
		};
		if (Compare(localStorage["cdv"], json.cos.dv)&&localStorage["ncd"]) { 
			var noti = webkitNotifications.createNotification('icon48.png','Update','New Chrome '+json.cos.dv+' Dev for Chromebook');
			noti.show();
		};
		localStorage["wsv"] = json.win.sv;
		localStorage["wbv"] = json.win.bv;
		localStorage["wdv"] = json.win.dv;
		localStorage["wcv"] = json.win.cv;
		localStorage["lsv"] = json.linux.sv;
		localStorage["lbv"] = json.linux.bv;
		localStorage["ldv"] = json.linux.dv;
		localStorage["msv"] = json.mac.sv;
		localStorage["mbv"] = json.mac.bv;
		localStorage["mdv"] = json.mac.dv;
		localStorage["mcv"] = json.mac.cv;
		localStorage["csv"] = json.cos.sv;
		localStorage["cbv"] = json.cos.bv;
		localStorage["cdv"] = json.cos.dv;
		localStorage["yv"] = Version();
		localStorage["wspv"] = json.win.spv;
	};
	});
}