// ====================================================================================
//
// Created by SDPsM — http://alest.cc
// 22.02.2008
//
// ====================================================================================

eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$(1(){$("8[0^=a]").7(1(){$("4[0="+5.0.2("3","6")+"]").9()},1(){$("4[0="+5.0.2("3","6")+"]").b()})})',12,12,'id|function|replace|Parent|div|this|Child|hover|li|show|mainMenuParent|hide'.split('|'),0,{}))

// ====================================================================================

$(function()
{
	$("body").prepend($("<div>").css({display:"none"}).html("<img src='http://counter.yadro.ru/hit?r"+escape(document.referrer)+((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";"+Math.random()+"' width='1' height='1' alt='' />"));
});

// ====================================================================================

function popupWin(url, width, height, additional) {
	additional = additional || null;
	var left       = screen.width / 2 - width / 2;
	var top        = screen.height / 2 - height / 2;
	window.open(url, '_blank', 'status=no,dependent=yes,modal=yes,height=' + height + ',width=' + width + ',left=' + left + ',top=' + top + additional);
	return;
}

function showPopup(action) {
	popupWin('/popup.php?action=' + action, 500, 400);
}

function showPopup_maxim(action) {
	popupWin('/popup_maxim.php?action=' + action, 500, 400);
}

function showPoll() {
	popupWin('/poll.php', 370, (navigator.userAgent.match("Gecko") ? 390 : 430), ',scrollbars=1');
}

function showPoll_song() {
	popupWin('/poll_song.php', 440, (navigator.userAgent.match("Gecko") ? 390 : 430), ',scrollbars=1');
}

function createHttpRequest() {
	req = false;
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				req = false;
			}
		}
	}
	return req;
}

function loadSongs(url) {
	var req = createHttpRequest();
	if(req) {
		req.onreadystatechange = processSongs;
		req.open("GET", url, true);
		req.send("");
	}
}
function processSongs() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var listing = document.getElementById("listing");
			var twenty  = document.getElementsByTagName("dl")[0];
			var link    = listing.getElementsByTagName("a")[0];
			var img     = listing.getElementsByTagName("img")[0];

			if (dir_type == "next") {
				link.setAttribute("href", "javascript:listing('prev')");
				link.setAttribute("id", "leftArrow");

				img.setAttribute("src", "/images/home/left_arrow.gif");
				img.setAttribute("alt", "Предыдущие 10");

				twenty.innerHTML = req.responseText + '<dd><a href="javascript:listing(\'prev\')">&lt;&lt; Предыдущие 10</a> | <a href="/programs/star_wars/">Проголосовать</a></dd>';
			} else {
				link.setAttribute("href", "javascript:listing('next')");
				link.setAttribute("id", "rightArrow");

				img.setAttribute("src", "/images/home/right_arrow.gif");
				img.setAttribute("alt", "Следующие 10");

				twenty.innerHTML = req.responseText + '<dd><a href="javascript:listing(\'next\')">Следующие 10 &gt;&gt;</a> | <a href="/programs/star_wars/">Проголосовать</a></dd>';
			}
		} else {
			/*alert("Файл недоступен:\n" +
			req.statusText);*/
		}
	}
}

function listing(direction) {
	dir_type = direction;
	loadSongs("/scripts/songs.php?dir=" + direction);
}

function inputLimit(field, quantity) {
	if (field.value.length > quantity) {
		field.value = field.value.substring(0, quantity + 1);
	}
}

$(function(){
	var new_marquee = document.createElement("marquee");
	var marquee = document.getElementById('etherSong');
	var old_marquee = document.getElementById('songName');
	//new_marquee.innerHTML = old_marquee.innerHTML;
	var cities = ["Киев 102.5FM", "Одесса 105.3FM", "Николаев 104.6FM", "Измаил 101.2FM", "Кишинев 87.6FM"];
	new_marquee.innerHTML = cities.join(' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ');
	new_marquee.setAttribute("scrollDelay", "150");
	if(marquee && old_marquee) marquee.replaceChild(new_marquee, old_marquee);

	try {
		new_marquee.start(); // for Mozilla
		//new_marquee.contentEditable = true;
	} catch (e) { }

})
