// JavaScript Document

<!--//--><![CDATA[//><!--

//jQuery section
$(document).ready(function(){
	//снимаем фокус с кликов
	$("a").focus(function() {
		this.blur();
	});
	$(":checkbox").focus(function() {
		this.blur();
	});
	$(":radio").focus(function() {
		this.blur();
	});
	//левые href'ы
	$("#chart").click(function() {window.location.href = ('/chart/')	});
	$("#pf-link").click(function() {window.location.href = ('http://kuzbassfm.podfm.ru/');});
	$("#pf-link2").click(function() {window.location.href = ('http://kuzbassfm.podfm.ru/');});
	$("#lj-link").click(function() {window.location.href = ('http://kuzbassfm.livejournal.com/');});
	$("#wiki-link").click(function() {window.location.href = ('http://ru.wikipedia.org/wiki/Кузбасс%20FM');});
	$('div.vefire').css('cursor','pointer').click(function() {window.location.href = ('http://www.kuzbassfm.ru/radio/1052/');});
	$("span.f-link").hover(function() {$(this).css("color", "#C30");}, function() {$(this).css("color","#06C");	});
	$("#addbutton").hover(function() {$(this).addClass("active");}, function() {$(this).removeClass("active");});
	$("label.linked").hover(function() {$(this).css("color", "#C30");}, function() {$(this).css("color","#06C");	});
	$("div.bkmrks img").hover(function() {$(this).css("border-color", "#f0f0f0");}, function() {$(this).css("border-color","#f9f9f9");	});
	//ховеры реплик
	$('.topics li').hover(function() {$(this).addClass("active");}, function() {$(this).removeClass("active");});
	//запускаем ротацию частот
	$(function() {rotation.init();});		setInterval(function() {$('#temp').toggle();},5000);
	// подсвечиваем теги записи
	$('#hl a').hover(
		function() {
			var b = $(this).attr('class').split(' ');
			$.each( [1,2,3,4], function(i, n){
				$('div.tagcloud #'+b[i]).addClass("hltd");
			});
		}, 
		function() {
			$('div.tagcloud li').removeClass("hltd"); 
		} 
	);
});

function go(url){
	window.location.href = (url)
}

function showRmv(opt){
	//alert(opt)
	$("#"+opt).toggle();
	}

function openquick(type1){
	$("#addopinion").addClass("full").focus();
	if(type1 == '2') {
		if($("#subject").val() == '') {
			$("#subject").focus();
		}
	}
};

function showPic() {
	$("img.small").toggle();
	$("img.big").toggle();
}

function showHided() {
	$("center.hided").toggle();
}

function showSound() {
	$("span.sound").toggleClass('active');
	var $thisval=$("span.sound object").attr('data');
	$thisval=$thisval+'&startplay=true';
	$("span.sound object[data]").attr('data',$thisval);
	$("param[name='movie']").val($thisval);
}

// Ротация частот
var rotation = {
// properties
version: "0.1b",
// i - current value
i: 0,
step: -10,
first: 0,
last: -100,
// methods
init: function ()
{
	this.image = new Image( );
	this.image.src = "/i/stationids.png";
	this.image.onload = function( )
	{
		rotation.imageLoaded = true;
		rotation.img = $("<div id='rotator_img' />");
		rotation.img.css( {
			width: rotation.image.width,
			height: '168px',
			position: "relative",
			margin: '-2px 0 0 0',
			right: 0, top: 0,
			background: "#eef8ff url("+rotation.image.src+") no-repeat left top;"
		} );
		
		rotation.step = -10;
		rotation.last = -rotation.image.height + rotation.step;
		
		rotation.img.appendTo( rotation.container );
		rotation.img.css( 'backgroundImage', "url("+rotation.image.src+")" );
		
		rotation.start( );
	};
	
	this.container = $("<div id='rotator'>&nbsp;</div>");
	this.container.css( {
		width: "178px", height: "12px",
		margin: "0 0 -12px 0px", padding: "0",
		position: "relative",
		left: "38px", top: "114px", overflow: "hidden" 
	} );
	
	$('a#logo_block').css('display','block');
	this.container.prependTo("a#logo_block");
	
	return this;
},

start: function ()
{
	this.callnext();
},

callnext: function ()
{
	this.timer = setTimeout("rotation.tick();", 900);
},

freeze: function ()
{
	this.timer = setTimeout("rotation.tick();", 4000);
},

tick: function ()
{
	if( this.i < this.last )
	{
		this.i = this.first;
		this.img.css('top',this.i+"px");
		this.freeze();
		return;
	}
	
	this.i += this.step;
	this.img.animate( { top: this.i+"px" }, 400, 'linear', this.callnext );
}
};

//pure js

function get_curplaying() {
	document.getElementById('onair_loader').src = '/i/loader.gif';
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById("inair_content").innerHTML = req.responseText;
		}
	}
	req.open(null, '/_air.php', true);
	req.send();
	timer_cur_playing = setTimeout("get_curplaying()", 30000);
}

function godate(c_month, c_day, c_year, c_hour, c_minute, c_second) {
	var daystuff = new Date();
	var monthname=new Array("янв", "фев", "мар", "апр", "мая", "июн", "июл", "авг", "сен", "окт", "ноя", "дек");
	if(!c_month) {
		c_month_name = monthname[daystuff.getMonth()];
		c_day = daystuff.getDate();
		c_year = daystuff.getFullYear();
		c_hour = daystuff.getHours();
		c_minute = daystuff.getMinutes();
		c_second = daystuff.getSeconds();
	} else {
		c_month_name = monthname[c_month];
		c_second++;
		if(c_second==60) {
			c_second = 0;
			c_minute++;
		}
		if(c_minute==60) {
			c_minute = 0;
			c_hour++;
		}
		if(c_hour==24) {
			c_hour = 0;
		}
	}
	if (c_hour < 10) {
		c_hour = "0" + c_hour;
	}
	if (c_minute < 10) {
		c_minute = "0" + c_minute;
	}
	if (c_second/2 == Math.ceil(c_second/2)) {
		c_second_text = 'visible';}
		else
		{c_second_text = 'hidden'}

	if (c_hour > 9 && c_hour < 20) {
		if (c_minute > 9 && c_minute < 20) {document.getElementById("time").innerHTML = '<span>' + c_hour + '</span>' + '<div style="visibility:' + c_second_text + '">:</div>'  + '<span>' + c_minute + '</span>';} else {document.getElementById("time").innerHTML = '<span>' + c_hour + '</span>' + '<div style="visibility:' + c_second_text + '">:</div>' + c_minute;} 
		} else {
		if (c_minute > 9 && c_minute < 20) {document.getElementById("time").innerHTML =  c_hour + '<div style="visibility:' + c_second_text + '">:</div>'  + '<span>' + c_minute + '</span>';} else {document.getElementById("time").innerHTML = c_hour + '<div style="visibility:' + c_second_text + '">:</div>' + c_minute;} 
		}
		
		document.getElementById("date").innerHTML = c_day + " " + c_month_name + " " + c_year + " ";
		setTimeout('godate ('+c_month+', '+c_day+', '+c_year+', '+c_hour+', '+c_minute+', '+c_second+');', 1000);
}

function get_news_calendar(m,y) {
	document.getElementById('calendar_year').disabled = true;
	document.getElementById('calendar_month').disabled = true;
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if(req.responseJS.r=='OK') {
				document.getElementById('calendar_year').disabled = false;
				document.getElementById('calendar_month').disabled = false;
				document.getElementById('ajax_calendar').innerHTML = req.responseText;
			}
		}
	}
	req.open(null, '/news.php?ajax_calendar', 1);
	req.send( { 'm': m, 'y': y } );
}

function ShowLogin() {
	document.getElementById('b-login').style.display = 'none';
	document.getElementById('login').style.display = 'block';
}

var ch_count = 0;
function vote(obj, check_obj){
	if(check_obj && ch_count==3) return false;
	var el0 = document.getElementById(obj);
	if (el0.className != "active") { el0.className = "active"; ch_count++;}
	else { el0.className = " "; ch_count--;
	if(ch_count==2) {
		clearTimeout(timer_hit_submit);
		for(i=1;i<=20;i++) {
			if(document.getElementById('tr'+i).className == 'disable') document.getElementById('tr'+i).className = '';
		}
	}
	}
	if(ch_count==3) {
		for(i=1;i<=20;i++) {
			obj = document.getElementById('hit_check_'+i);
			if(!obj.checked) document.getElementById('tr'+i).className = 'disable';
		}
		if($('#u01').val()=='true'){
			timer_hit_submit = setTimeout("hit_submit()",3000);
		}else{
			timer_hit_submit = setTimeout("hit_check()",3000);
		}
	}
}

function vote2(id){
	if('vote2obj' in this) vote2obj.className = '';
	vote2obj = document.getElementById(id);
	if (vote2obj.className != "active") { vote2obj.className = "active";}
	if('timer_hit_submit2' in this) clearTimeout(timer_hit_submit2);
	timer_hit_submit2 = setTimeout("document.getElementById('hitform2').submit()",3000);
}

function hit_submit() {
	if(ch_count!=3) return;
	document.getElementById('hitform').submit();
}

function hit_check() {
	if(ch_count!=3) return;
	$('div.chart ol').css('opacity', '.4');
	$('div.checker').show();
}

timer_cur_playing = setTimeout("get_curplaying()", 5000);


function fromPoll(fromid) {
	$('#image').show();
	var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            $("#image").html(req.responseText);
        }
    }
    req.open(null, '/_from_poll.php', 1);
    req.send( { 'id':fromid } );
}

function fromPollClose() {
	$('#image').hide();
	$("#image").html('');
}

//Настройки Яндекс.Директа
// Размер шрифтов
var yandex_ad_fontSize = 1;

// Настройки объявлений Директа
var yandex_direct_showType = 1;
var yandex_direct_fontColor = '000000';
var yandex_direct_BorderColor = '33CC00';
var yandex_direct_BgColor = 'F0FCE3';
var yandex_direct_headerBgColor = 'D8F2B8';
var yandex_direct_titleColor = '006600';
var yandex_direct_siteurlColor = '006600';
var yandex_direct_linkColor = '006600';
