var currentradio = '';

function radio() {
	$.ajax({
		type: "GET",
		url: "/i/radio.php",
		cache: true,
   		dataType: "text",
		success: function(info) {
			info = String(info);
			if (info != currentradio) {
				informer = info.split("|");

				$('#radio').fadeOut('slow', function() {
					if (parseInt(informer[4]) != 0) {
						$('#radio').html('&#9836;&nbsp;&nbsp;'+informer[10]+'&nbsp;('+informer[4]+' online)');
					} else {
						$('#radio').html('&#9836;&nbsp;&nbsp;'+informer[10]);
					}
					$('#radio').fadeIn('slow');
				});

				currentradio = info;
			}
		}
	});
}

$(document).ready(function(){

	// Kote Code
	kote = new Konami();
	kote.pattern = '73698665';
	kote.code = function() {
		$.ajax({type: "GET", url: "/i/spiderpig.js", cache: true, dataType: "script"});
	}
	kote.load();

	var pageID = parseInt($('#com-control').attr('rel'));

	function commentsVK (num, last_comment, date, sign) {
		alert(last_comment);
		$.post('/i/comments.php', { url: document.location.href, page: pageID, count: num, last: last_comment, date: date, sign: sign });
	}

	function loadVK () {
		$.ajax({
			type: "GET",
			url: "http://vkontakte.ru/js/api/openapi.js",
			cache: true,
   			dataType: "script",
			success: function() {
				$('#com-control').hide();
				VK.init({apiId: 2235820, onlyWidgets: true});
				VK.Widgets.Comments('comments', {onChange: "commentsVK", width: 900, autoPublish: 0}, pageID);
			}
		});
	}

	if (typeof(lemmingsVK) != 'undefined') { loadVK(); }
	$('#com-control').click( function(){ loadVK(); $('#fuck').hide(); } );


	if ($('a.lightbox').length > 0) {
		$("head").append($('<link rel="stylesheet" href="/i/jquery.lightbox.css" type="text/css" media="screen" />'));
		$.ajax({
			type: "GET",
			url: "/i/jquery.lightbox.js",
			cache: true,
   			dataType: "script",
			success: function() {
				$('a.lightbox').lightBox({
					overlayBgColor: '#000000',
					overlayOpacity: 0.9,
					imageLoading: '/i/loading.gif',
					imageBtnClose: '/i/close.gif',
					imageBtnPrev: '/i/prev.gif',
					imageBtnNext: '/i/next.gif',
					imageBlank: '/i/blank.gif',
					txtImage: 'Бумажка',
					txtOf: 'из'
				});
			}
		});
	}

	radio();
	var t = window.setInterval("radio()", 60000);

});

