Shadowbox.init({
	language: 'ru',
	adapter: 'mootools',
	skipSetup: true,
	players:  ['img']
});
window.addEvent('domready', function() {

	// включаем shadowbox
  var Shadowbox_options = {
    resizeDuration: 0.2,
    fadeDuration: 0.1,
    marginDuration: 0.03,
    viewportPadding: 10,
    handleOversize: 'resize',
    overlayOpacity: 0.5,
    viewportPadding: 5,
    autoDimensions: true,
  };

	list = $$(document.links);
  list = list.filter(function(item){
  	//if (item.hasClass('no')) return false;
    return item.href.test(/\.(jpe?g|png|gif|swf)$/)
  });
  if (list && list.length) {
		Shadowbox.setup(list, Shadowbox_options);
  }

  var myTips = new Tips('*[title]',{className: 'swtip'});

	var searchnode = $$('#sw_c3 .search')[0];
  if (!searchnode.value) {
  	searchnode.set('value', 'Фраза для поиска...').addEvent("focus", function() {
  		this.focused = true;
  		this.value = '';
  		this.style.color = '';
  	});
  }

	try {
  	var anch = window.location.toString().match(/#(.*)/)[1];
  } catch(ex) {}
  if (anch) {
		if (anch.match(/^comment/) && window.location.toString().match(/gallery/)) {
			var node;
			try {
				var node = $$('a[name="' + anch + '"]')[0];
			} catch(ex) {}
			if (!node) {
				alert('Комментарий уже удален');
			} else {
				node = node.getParent('table').getParent('table');
				node.setStyle('border', "2px solid lime").setStyle('background', 'yellow');

				window.addEvent('load', function() {

					node.set('tween', {link: 'chain'});
					node.tween('opacity', '0.2').tween('opacity', '1');

				});
			}
		}

  }

  if (window.location.toString().match(/news|comments/) || window.location.toString().match(/\.ru\/$/) ) {
  	$$('.vkshare').each(function(item) {
  		item.newsdata = item.get('rel').match(/(\d+);(.*)/);

  		var newsbody = item.getParent().getParent().getElement('.newsbody');
  		var img = "";
  		try {
  			img = newsbody.get('html').match(/src="(.*?\.(jpg|gif|png))"/)[1];
  			if (!img.match(/^http/)) {
  				img = "http://sonic-world.ru" + img;
  			}
  			if (img.match(/\/emotes\//)) img = '';
  		} catch(ex) {}

  		if (!img) img = "http://img51.imageshack.us/img51/7461/soniccisnormalr.jpg";

			item.set('html', VK.Share.button({
				url: "http://sonic-world.ru/comment.php?comment.news." + item.newsdata[1],
				title: item.newsdata[2],
				description: newsbody.get('text'),
				image: img,
				noparse: true
			}, {
				type: "round",
				text: "Поделиться"
			}));

  	});
  }


});


function AJAXDeleteMessage(node, link) {
	var rpc = null;

	if (document.all && navigator.userAgent.indexOf("Opera") <= -1) {
		rpc = new ActiveXObject("Msxml2.XMLHTTP");
	} else if (XMLHttpRequest)
		rpc = new XMLHttpRequest();
	if (rpc) {
		node.style.backgroundColor = "#FFEEEE";
		node.style.outline = "1px solid #FF6666";
		rpc.open('POST', link);
		rpc.onreadystatechange = function() {
			if (rpc.readyState == 4) {
				if (rpc.responseText) {
					node = document.id(node);
					node.tween('opacity', 0);
				}
			}
		}
		rpc.send("ajax=1");
		return false;

	} else return true;
}

function ColorizeNewComment(id) {
	if (node = document.getElementById('comment' + id))
		node.parentNode.parentNode.parentNode.parentNode.style.borderTop = "3px dashed #41d414";
}