var t;
var _is_typing = false;
var _location;
var _last_location = false;
var _start = false;
var _is_result = false;
var url_ajax_pocasie = '/sluzby/homepage_pocasie/'+i9;
var url_ajax_kalendar = '/sluzby/homepage_kalendar/'+i9;
var url_ajax_horoskop = '/sluzby/homepage_horoskop/'+i9;
var url_ajax_program = '/sluzby/homepage_program/'+i9;

function pocasie_suggestions_check(word) {
	if( _last_location != $('#js_edit_pocasie').val() ||  word != $('#js_edit_pocasie').val()) {
		_is_result = false;
		_last_location = $('#js_edit_pocasie').val();
		if (_last_location.length>2) {
			t = setTimeout(function(){pocasie_suggestions_check($('#js_edit_pocasie').val());}, 300);
		}
	} else {
		_location = trim($('#js_edit_pocasie').val());
		if( (_location.length>2) && (_is_result == false) ) {
			_is_result = true;
			get_data(_location);
		}
		_is_typing = false;
		_start = false;
		clearTimeout(t);
	}
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value,days) {
	var hpDataString = '';
	hpDataString = readCookie('hpData');
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}	else {
		var expires = "";
	}
	if (name == 'novyazet') {
	  var cook = name+"="+value+expires+"; path=/;domain=azet.sk;";
		path = 'azet.sk';
	} else {
		if (hpDataString != null) {
			hpData = hpDataString.split('__');
		} else {
			hpData = new Array;
		}
		hpData[name] = value;
		hpDataString = hpData.join('__');
		var cook = "hpData="+hpDataString+expires+"; path=/";
		path = '/';
	}
	document.cookie = cook;
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function strtolower(str){
	return (str+'').toLowerCase();
}
function showError (elm, text) {
	if (elm.siblings('.chyba').is('p')) {
		elm.siblings('.chyba').html(text);
	} else {
		elm.after('<p class="chyba">'+text+'</p>');
	}
	elm.siblings('.chyba').show();
	elm.siblings('.chyba').fadeOut(5000);
}
function get_data(query) {
	$.getJSON(url_ajax_pocasie,{act:'sugg', q:query},function(json){
		html='<ul>';
		if (typeof(json['data']) != 'undefined') {
			$.each(json['data'],function(index,value){
			  if (value['locationName2'].length>0){
					moreTitle=value['locationName2']+', '+value['countryCode'];
				} else {
					moreTitle=value['countryCode'];
				}
				html=html+'<li class="'+strtolower(value['countryCode'])+'"><a href="#" tag="'+value['locationID']+'">'+value['locationNameSK']+' ('+moreTitle+')</a></li>';
			});
			html=html+'</ul>';
			$('#js_pocasie_conf').html(html);
			$('#js_pocasie_conf').show();
			$('#js_pocasie_conf a').click(function(){
				$.getJSON(url_ajax_pocasie,{act:'set',city:$(this).attr('tag')},function(json) {
					$('#js_pocasie_conf').hide();
					$('#js_edit_pocasie').val(json['cityData']['location']['locationNameSK']);
					if (json['cityData']['current']['icon']<10) {
						json['cityData']['current']['icon']='0'+json['cityData']['current']['icon'];
					}
					$('#js_pocasie strong:first').removeClass();
					$('#js_pocasie strong:first').addClass('p p' + json['cityData']['current']['icon']);
					$('#js_pocasie strong:first').attr('title',pS[json['cityData']['current']['icon']*1]);
					$('#js_temperature').text(json['cityData']['current']['temp']);
					$('a.editMesto').text(json['cityData']['location']['locationNameSK']);
					$('a.editMesto').attr('href',json['cityData']['fullUrl']);
					$('ul#pocasieBublina li.viac:first a').attr('href',json['cityData']['fullUrl']);
					$('#js_mesto').attr('title',json['cityData']['location']['locationNameSK']+' - počasie na 3 dni');
					$('#js_boxmesto').attr('title',json['cityData']['location']['locationNameSK']+' - počasie na 10 dní');
					for (i=0; i<3; i++) {
						if (json['cityData']['forecast']['days'][i]['icon']<10) {
							json['cityData']['forecast']['days'][i]['icon']='0'+json['cityData']['forecast']['days'][i]['icon']*1;
						}
						$('ul#pocasieBublina span.pocli').each(function () {
							$(this).find('li:eq('+i+')').removeClass();
							$(this).find('li:eq('+i+')').addClass('p p'+json['cityData']['forecast']['days'][i]['icon']);
							$(this).find('li:eq('+i+')').attr('title',pS[json['cityData']['forecast']['days'][i]['icon']*1]);
							$(this).find('li:eq('+i+') span:last').text(json['cityData']['forecast']['days'][i]['hight_temp']+'/'+json['cityData']['forecast']['days'][i]['low_temp']+'°C') ;
						});
						$('ul.pocasie').each(function () {
							$(this).find('li:eq('+i+')').removeClass();
							$(this).find('li:eq('+i+')').addClass('p p'+json['cityData']['forecast']['days'][i]['icon']);
							$(this).find('li:eq('+i+')').attr('title',pS[json['cityData']['forecast']['days'][i]['icon']*1]);
							$(this).find('li:eq('+i+') span').text(json['cityData']['forecast']['days'][i]['hight_temp']+'/'+json['cityData']['forecast']['days'][i]['low_temp']);
						});
					}
					closePocasie();
					if ($('#podhlavicka #pocasieBublina').is('ul')) {
						$('a#js_mesto').click();
					}
				});
				return false;
			});
		}
	});
}
function selectTab(elm) {
	$('#hlavicka ul > li > a.active').removeClass('active');
	$(elm).addClass('active');
	$('#hlavicka input.text:first').focus();
	sharp = $(elm).attr('href').substr(1);
	if (typeof(searchE[sharp]) != 'undefined' ) {
		$('div#hlavicka form').attr('action',searchE[sharp]['url']+i9);
		$('div#hlavicka input:submit').val(searchE[sharp]['name']);
	}
	if ($(elm).html() == 'slovník') {
		$('#hlavicka input.text:first').addClass('slovnik2');
		$('#hlavicka input.text:first').removeClass('slovnik');
		$('#selSlovnik').removeClass('schovaj');
		//$('#hlavicka select').attr('disabled','');
		$('#inpFirm').attr('disabled','disabled');
		$('#inpFirm').addClass('schovaj');
		$('label#co').addClass('schovaj');
		$('label#kde').addClass('schovaj');
	} else if ($(elm).html() == 'firmy') {
		$('#hlavicka input.text:first').addClass('slovnik');
		$('#hlavicka input.text:first').removeClass('slovnik2');
		$('#selSlovnik').addClass('schovaj');
		//$('#hlavicka select').attr('disabled','disabled');
		$('#inpFirm').removeClass('schovaj');
		$('#inpFirm').attr('disabled','');
		$('label#kde').removeClass('schovaj');
		$('label#co').removeClass('schovaj');
	} else {
		$('#hlavicka input.text:first').removeClass('slovnik');
		$('#hlavicka input.text:first').removeClass('slovnik2');
		$('#selSlovnik').addClass('schovaj');
		//$('#hlavicka select').attr('disabled','disabled');
		$('#inpFirm').attr('disabled','disabled');
		$('#inpFirm').addClass('schovaj');
		$('label#kde').addClass('schovaj');
		$('label#co').addClass('schovaj');
	}
}

function resizeCol() {
	if ($(window).width() > 1008) {
		createCookie(4,1,14);
		$('body').removeClass('mensi');
		$('ul.siet li:nth-child(n+4)').addClass('prvy');
		$('ul.siet li:nth-child(n+7)').addClass('druhy');
		$('ul.siet li:nth-child(n+10)').addClass('treti');
		$('ul.katalog li:nth-child(n+31)').addClass('prvy');
		$('ul.katalog li:nth-child(n+61)').removeClass('prvy');
		$('ul.katalog li:nth-child(n+61)').addClass('druhy');
		$('ul.katalog li:nth-child(n+91)').removeClass('druhy');
		$('ul.katalog li:nth-child(n+91)').addClass('treti');
	} else {
		createCookie(4,0);
		$('body').addClass('mensi');
		$('ul.siet li').removeClass('prvy');
		$('ul.siet li').removeClass('druhy');
		$('ul.siet li').removeClass('treti');
		$('ul.katalog li').removeClass('prvy');
		$('ul.katalog li').removeClass('druhy');
		$('ul.katalog li').removeClass('treti');

		$('ul.siet li:nth-child(n+5)').addClass('prvy');
		$('ul.siet li:nth-child(n+9)').addClass('druhy');
		$('ul.katalog li:nth-child(n+40)').addClass('prvy');
		$('ul.katalog li:nth-child(n+78)').addClass('druhy');
	}
  offset=$('#pata ul').offset();
	$('p#home').css('top',offset.top-235);
}
function set_homepage(url) {
	var userExplorer;
	userExplorer = navigator.appName;
	if (userExplorer == 'Microsoft Internet Explorer') {
		document.body.style.behavior="url(#default#homepage)";
		document.body.setHomePage('http://www.azet.sk/');
	}else{
		window.open(url, 'Pravidlá', 'status=0,toolbar=0,width=900px,height=600px,scrollbars=1');
	}
}
function switchHP(val,url) {
	createCookie('novyazet',val,14);
	location.href=url;
}

function addBindWeather() {
	$('body').bind('click',function(e) {
	  if ($(e.target).parent().attr('id') == 'zatvor') {
			closePocasie();
			return false;
		}
	  if (e.target && $(e.target).attr('id') != 'pocasieBublina') {
			hide = 1;
    	$(e.target).parents().each(function() {
				if ($(this).attr('id') == 'pocasieBublina') {
					hide = 0;
					return false;
				}
			});
			if (hide) {
				closePocasie();
			}
		} else {
			$('#js_pocasie_conf').hide();
		}
		return true;
	});
}
function showPocasie(bindFrom,bindTo, bindAfter) {
	closePocasie();
	if (!$(bindTo+' #pocasieBublina').is('ul')) {
		$('#pocasieBublina').clone(true).insertAfter(bindAfter);
		$(bindFrom+' #pocasieBublina').remove();
	}
	$('#pocasieBublina').show();
	$('#js_edit_pocasie').focus();
	$('#js_edit_pocasie').select();
	addBindWeather();
}
function closePocasie() {
	$('ul#pocasieBublina').hide();
	$('#js_pocasie_conf').hide();
	$('body').unbind('click');
}



$('document').ready(function() {
	resizeCol();
	$('#hlavicka input.text:first').focus();
	sharpUrl = window.location.href.split('#');
	if (typeof(sharpUrl[1]) != 'undefined' && typeof(searchE[sharpUrl[1]]) != 'undefined') {
		$('#hlavicka input.text:first').attr('disabled','');
		$('#hlavicka ul#menu > li a').each(function() {
			if ($(this).attr('href') == '#'+sharpUrl[1]) {
				selectTab($(this));
				return false;
			}
		});
	}
	$(window).bind('resize',function(){
		resizeCol();
	});
	$('#login form').submit(function (){
		if (navigator.appName == "Microsoft Internet Explorer") {
			if (!hp.isHomePage(HomePage)) {
				hpDataString=readCookie('hpData');
				if (hpDataString != null) {
					hpData = hpDataString.split('__');
					cook = hpData[7] * 1;
					if (cook != null) {
						if (cook < 4) {
							if (cook == 3) {
								set_homepage();
							}
							createCookie(7,cook+1,14);
						}
					} else {
						createCookie(7,1,14);
					}
				} else {
					createCookie(7,1,14);
				}
			}
		}
	});
	$('#hlavicka form').submit(function (){
		if ($('#hlavicka input.text:first').val() == '') {
			$('#hlavicka input.text:first').focus();
			return false;
		} else {
			$('div#hlavicka input#hic').attr('disabled','disabled');
			if ($('#hlavicka ul#menu > li a.active').attr('href') == '#mapy') {
				$('#hlavicka input.text:first').attr('disabled','disabled');
				get_action = $('div#hlavicka form').attr('action')+'#p=pageSearching&q='+encodeURI($('#hlavicka input.text:first').val());
				$('div#hlavicka form').attr('action', get_action);
				$('div#hlavicka form').attr('method', 'post');
			} else if ($('#hlavicka ul#menu > li a.active').attr('href') == '#slovnik') {
				get_action = $('div#hlavicka form').attr('action')+$('ul#selSlovnik li a:first').attr('name')+'/?q='+encodeURI($('#hlavicka input.text:first').val());
				$('div#hlavicka form').attr('action', get_action);
			}
			if ($('#hlavicka ul#menu > li a.active').attr('href') == '#firmy' || $('#hlavicka ul#menu > li a.active').attr('href') == '#internet') {
				$('div#hlavicka input#hic').attr('disabled','');
			}
		}
		return true;
	});
	$('#hlavicka ul#menu > li a').click(function(){
	  selectTab(this);
	});
	$('#q').keydown(function(e) {
		if (e.keyCode == '9') {
			if ($('#inpFirm:visible').is('input')) {
				$('#inpFirm:visible').focus();
			} else if ($('#selSlovnik:visible').is('ul')){
				$('#selSlovnik li a#selLang').click();
			} else if ($('#hlavicka ul#menu li a.active').parent().next().find('a').is('a')) {
				$('#hlavicka ul#menu li a.active').parent().next().find('a').click();
			} else {
				$('#hlavicka ul#menu li:first a').click();
			}
			return false;
		}
		return true;
	});
	$('#inpFirm').keydown(function(e) {
		if (e.keyCode == '9') {
			if ($('#hlavicka ul#menu li a.active').parent().next().find('a').is('a')) {
				$('#hlavicka ul#menu li a.active').parent().next().find('a').click();
				$('#q').focus();
				$('#q').val($('#q').val());
			}
			return false;
		}
		return true;
	});

	$('#selSlovnik').click(function(e) {
		if (e.target && ($(e.target).attr('id') == 'selLang' || $(e.target).is('span') )) {
			if ($('#selSlovnik li').hasClass('show')) {
				$('#selSlovnik li').removeClass('show');
				$('body').unbind('click');
			} else {
				$('body').bind('click',function(e) {
				  if (e.target && $(e.target).attr('id') != 'selSlovnik') {
						hide = 1;
						$(e.target).parents().each(function() {
							if ($(this).hasClass('show')) {
								hide = 0;
								return false;
							}
						});
						if (hide) {
							$('#selSlovnik li').removeClass('show');
						}
					}
					return true;
				});
				$('#selSlovnik li:first').addClass('show');
				//$('#selSlovnik ul').focus();
				if (!$('#selSlovnik ul li a.hover').is ('a')) {
					$('#selSlovnik ul li a:first').addClass('hover');
				}
				$('#selSlovnik ul li a.hover').focus();
			}
		} else if ($(e.target).is('a')) {
		  $('#selSlovnik li:first').removeClass('show');
			$('#selSlovnik li:first a:first').html($(e.target).html());
			$('#selSlovnik li:first a:first').attr('name',$(e.target).attr('name'));
			findText = $(e.target).html();
			/*
			$('#hlavicka select').find('option').each(function() {
				if ($(this).html() == findText) {
					$(this).attr('selected','selected');
				} else {
					$(this).attr('selected','');
				}
			});
			*/
		}
	});
	$('#selSlovnik').keydown(function(e) {
		if (e.keyCode==40) {
			var liNext = $('#selSlovnik ul li a.hover').parent().next();
			if (liNext.hasClass('jazyk')) {
				liNext = liNext.next();
			}
			if (liNext.is('li')) {
				$('#selSlovnik ul li a.hover').removeClass('hover');
				liNext.find('a').addClass('hover');
			}
			return false;
		} else if (e.keyCode==38){
			var liPrev = $('#selSlovnik ul li a.hover').parent().prev();
			if (liPrev.hasClass('jazyk')) {
				liPrev = liPrev.prev();
			}
			if (liPrev.is('li')) {
				$('#selSlovnik ul li a.hover').removeClass('hover');
				liPrev.find('a').addClass('hover');
			}
			return false;
		} else if (e.keyCode==13){
			$('#selSlovnik ul li a.hover').click();
			$('#q').focus();
			$('#q').val($('#q').val());
			return false;
		} else if (e.keyCode==9) {
			if ($('#hlavicka ul#menu li a.active').parent().next().find('a').is('a')) {
				$('#hlavicka ul#menu li a.active').parent().next().find('a').click();
				$('#q').focus();
				$('#q').val($('#q').val());
				return false;
			}
		}
		return true;
	});


	$('a.lock').click(function() {
		if ($(this).hasClass('ssl')) {
			$(this).removeClass('ssl');
			$(this).addClass('nossl');
			$('form.prihlas').attr('action',$('form.prihlas').attr('action').replace('https:','http:'));
		} else {
			$(this).addClass('ssl');
			$(this).removeClass('nossl');
			$('form.prihlas').attr('action',$('form.prihlas').attr('action').replace('http:','https:'));
		}
	});
	$('#js_pocasie_conf').keydown( function(e){
		if(e.keyCode == '38') {
			iSugg = iSugg - 1;
			if (iSugg == -1) {
				$('#js_edit_pocasie').focus();
			} else {
				$('#js_pocasie_conf ul li').find('a.hover').removeClass('hover');
				$('#js_pocasie_conf ul li:eq('+iSugg+')').find('a').addClass('hover');
				$('#js_pocasie_conf ul li:eq('+iSugg+')').find('a').focus();
			}
			return false;
		}
		if(e.keyCode == '40') {
			if (iSugg < $('#js_pocasie_conf ul').children().size() - 1) {
				iSugg = iSugg + 1;
				$('#js_pocasie_conf ul li').find('a.hover').removeClass('hover');
				$('#js_pocasie_conf ul li:eq('+iSugg+')').find('a').addClass('hover');
				$('#js_pocasie_conf ul li:eq('+iSugg+')').find('a').focus();
			}
			return false;
		}
	});
	$('#js_edit_pocasie').keyup( function(e){
	  if (_last_location != $(this).val()) {
     	pocasie_suggestions_check();
		} else if(e.keyCode == '40') {
			$('#js_pocasie_conf:visible ul li:first a').focus();
			$('#js_pocasie_conf ul li').find('a.hover').removeClass('hover');
			$('#js_pocasie_conf ul li:first').find('a').addClass('hover');
			iSugg = 0;
		} else if(e.keyCode == '13') {
			$('#js_pocasie_conf li:first a').click();
			return false;
		}
		return false;
	});
	$('#js_edit_pocasie').focus(function() {
		if ($(this).val().length > 2) {
			if (_last_location != $(this).val()) {
				pocasie_suggestions_check();
			} else {
				$('#js_pocasie_conf').show();
			}
		}
	});
	$('a#js_mesto').click(function(){
	  if ($('#podhlavicka #pocasieBublina:visible').is('ul') && $('ul#pocasieBublina span.input').hasClass('schovaj')) {
			closePocasie();
		} else {
			$('ul#pocasieBublina span.pocli').removeClass('schovaj');
			$('ul#pocasieBublina span.input').addClass('schovaj');
			showPocasie('.box','#hlavicka','#podhlavicka a#js_editMesto');
		}
	  return false;
	});

	$('a#js_editMesto').click(function(e) {
	  if ($('#podhlavicka #pocasieBublina:visible').is('ul') && $('ul#pocasieBublina span.pocli').hasClass('schovaj')) {
			closePocasie();
		} else {
			$('ul#pocasieBublina span.pocli').addClass('schovaj');
			$('ul#pocasieBublina span.input').removeClass('schovaj');
			showPocasie('.box','#hlavicka','#podhlavicka a#js_editMesto');
		}
		return false;
	});
	$('a#js_editBoxMesto').click(function(e){
	  if ($('#js_boxpocasie #pocasieBublina:visible').is('ul')) {
			closePocasie();
		} else {
			$('ul#pocasieBublina span.pocli').addClass('schovaj');
			$('ul#pocasieBublina span.input').removeClass('schovaj');
			showPocasie('#hlavicka','.box ','#js_editBoxMesto');
		}
		return false;
	});


	$('#pocasieBublina input.button').click(function(){
		$('#js_pocasie_conf li:first a').click();
	});
	$('span.pocli li:last a').click(function(){
		$('ul#pocasieBublina').find('span.pocli').addClass('schovaj');
		$('ul#pocasieBublina').find('span.input').removeClass('schovaj');
		$('#js_edit_pocasie').focus();
		$('#js_edit_pocasie').select();
	});

	$('div.program h2 a:last').click(function(){
		if ($('#tv_stations').css('display') == 'none') {
			$('body').unbind('click');
		} else {
			$('body').bind('click',function(e) {
				if (e.target && $(e.target).attr('id') != 'tv_stations') {
					hide = 1;
					$(e.target).parents().each(function() {
						if ($(this).attr('id') == 'tv_stations') {
							hide = 0;
							return false;
						}
					});
					if (hide) {
						$('#tv_stations ul').hide();
						$('.program h2.nadpis span').hide();
						$('body').unbind('click');
					}
				}
				return false;
			});
		}
		if ($('div#tv_stations').html() != '') {
			$('#tv_stations ul').toggle();
			$('.program h2.nadpis span').toggle();
		} else {
			$.getJSON(url_ajax_program,{act:'show'},function(json){
				html='<ul>';
				$.each(json['programData']['stations'],function(index,value){
					if ($('div#station'+index).is('div')) {
						html=html+'<li class="'+strtolower(value['station_name'])+' fajka">';
						html=html+'<input type="checkbox" value="1" checked="checked" />';
					} else {
						html=html+'<li class="'+strtolower(value['station_name'])+'">';
						html=html+'<input type="checkbox" value="1" />';
					}
					html=html+'<a href="#" tag="'+index+'">'+value['station_name']+'</a>';
					html=html+'</li>';
				});
				html=html+'</ul>';
				$('div#tv_stations').html(html);
				$('#tv_stations ul li:nth-child(n+20)').addClass('prvy');
				// $('#tv_stations ul li:nth-child(n+31)').addClass('druhy');
				$('.program h2.nadpis span').show();
				$('#tv_stations li').click(function(){
					var idTv = $(this).find('a').attr('tag');
					hpDataString=readCookie('hpData');
					if (hpDataString != null) {
						hpData = hpDataString.split('__');
						tv = hpData[3];
						if (tv != null) {
							tv=tv.replace('-'+idTv+'-','-');
							var myRegExp = new RegExp("^"+idTv+"-");
							tv=tv.replace(myRegExp,'');
							var myRegExp = new RegExp("-"+idTv+"$");
							tv=tv.replace(myRegExp,'');
							var myRegExp = new RegExp("^"+idTv+"$");
							tv=tv.replace(myRegExp,'');
						}
					}
					if ($(this).find('input').is(':not(:checked)')) {
						if (tv != null) {
							tv = tv+'-'+idTv;
						} else {
							tv = idTv;
						}
						$(this).find('input').attr('checked',1);
						$(this).addClass('fajka');
						if (!$('div#station'+idTv).is('div')) {
							$.getJSON(url_ajax_program,{act:'set',tv:idTv},function(json) {
							  if (typeof(json['programData']) != 'undefined') {
							    tvData = json['programData']['data'][idTv]['now'];
								  html='<div class="prog" id="station'+idTv+'">';
								  html+='<p class="cas"><span class="prg">'+json['programData']['stations'][idTv]['station_name']+'</span>';
								  html+='<span class="t">'+tvData['program_time']+'</span>';
								  html+='<span class="ciara" title="program končí za '+tvData['endmin']+' min."><span class="g" style="padding-left:'+tvData['duration']+'px; "><span class="bb">•</span> </span></span>';
								  html+='<span class="t">'+tvData['program_time_end']+'</span>';
								  html+='</p>';
								  html+='<p class="nazov"><span class="prvy">'+tvData['program_name']+'</span>';
									html+='<span class="prvy gray"><span>'+tvData['program_time_end']+': '+tvData['program_name_next']+'</span></span></p>';
								  html+='</div>';
								  $('.program h2').after(html);
								}
							});
						} else {
							$('div#station'+$(this).find('a').attr('tag')).show();
						}
					} else {
						$(this).find('input').attr('checked',0);
						$(this).removeClass('fajka');
						if ($('div#station'+idTv).is('div')) {
							$('div#station'+idTv).hide();
						}
					}
					createCookie(3,tv,14);
					return false;
				});
			});
		}
		return false;
	});
	$('h2.hor a:last').click(function() {
		$(this).addClass('schovaj');
	  if ($('div#horData').html() != '') {
			$('div#horData').toggle();
			$('p#cely').toggle();
			$('div#horAll').toggle();
		}
		if ($('div#horData').css('display') == 'block') {
			$('span#horName').html(horTmp);
		} else {
		  horTmp = $('span#horName').html();
			$('span#horName').html('Zvoľte si znamenie');
		}
		return false;
	});
	$('#horAll li a').click(function(){
		sign_class = $(this).attr('name');
		$.getJSON(url_ajax_horoskop,{act:'set', q:sign_class},function(json){
		  if (typeof(json['horoskopData']) != 'undefined' ) {
				html='<p><span class="h2 ';
				html+=json['horoskopData']['class']+'2">';
				html+='&nbsp;</span>'+json['horoskopData']['horoskop']+'</p>';
				$('span#horName').html('<a href="'+json['horoskopData']['fullUrl']+'">'+json['horoskopData']['sign']+'</a>');
				$('p#cely').html('<a href="'+json['horoskopData']['fullUrl']+'">Celý horoskop - '+json['horoskopData']['sign']+'</a>');
				$('div#horData').html(html);
				$('div#horAll').hide();
				$('div#horData').show();
				$('p#cely').show();
				$('h2.hor a:last').removeClass('schovaj');
			} else {
			  showError($('p.hor'), 'Nepodarilo sa načítať horoskop.');
			}
		});
		return false;
	});
	$('span#tyzden a').click( function(){
		if ($(this).html() != 'Dnes') {
			if ($(this).attr('id') == 'kalL') {
				iWeek = -1;
			} else {
				iWeek = 1;
			}
			id_year = $('span#iY').html()*1;
  	  id_week = $('span#iW').html()*1 + iWeek*1;
    	var year_week = id_year+'~'+id_week;
  	} else {
			var year_week = '1';
		}

		$.getJSON(url_ajax_kalendar,{act:'set',week:year_week },function(json) {
			$('span#iW').html(json['kalendarData']['idWeek']);
			$('span#iY').html(json['kalendarData']['year']);
			$('ul#kalendar li').each(function(i){
			  i = i+1;
			  if (i == 7) {
					i = 0;
				}
				html = '';
				$(json['kalendarData']['names'][i]['data']).each(function(nameData){
				  if (html.length > 0) {
						html = html+', ';
					}
					html = html+'<a href="'+this['url']+'">'+this['name']+'</a>';
				});
				$(this).removeClass('active');
				if (json['kalendarData']['names'][i]['isToday'] == 1) {
					$(this).addClass('active');
				}
				$(this).find('span:last').html(html);
				$(this).find('span').eq(1).each(function(){
					den = json['kalendarData']['names'][i]['date'].split('-');
					den =den[2]+'.';
					$(this).html(den);
				});
			});
			$('span#iM').html(json['kalendarData']['monthName']);
		});
		return false;
	});
	$('#crossX').click(function () {
		$('#prepinac').hide();
		$('#content').css('z-index',50);
		$('#dz').removeClass('schovaj');
		$('.napoveda').addClass('schovaj');
		$('#layer').addClass('schovaj');
		$('#d').val('zobraziť novinky');
		$('body').removeClass('lista');
		$('body').removeClass('lista2');
		if (i9.length > 0) {
			$('body').addClass('lista3');
		}
		createCookie(5,'2',14);
	});
	$('#dz').click(function () {
		$('#prepinac').show();
		$('#dz').addClass('schovaj');
		$('body').removeClass('lista');
		$('body').removeClass('lista3');
		if (i9.length > 0) {
			$('body').addClass('lista2');
		} else {
			$('body').addClass('lista');
		}
	});
	$('#layer').click(function () {
		$('.napoveda').addClass('schovaj');
		$('#layer').addClass('schovaj');
		$('#d').val('zobraziť novinky');
	});
	$('#d').click(function () {
	  if ($('.napoveda').hasClass('schovaj')) {
	    $('#content').css('z-index',200);
		  $('.napoveda').removeClass('schovaj');
		  $('#layer').removeClass('schovaj');
		  $('#d').val('skryť novinky');
		  offset=$('#pata ul').offset();
			$('p#home').css('top',offset.top-235);
		} else {
			$('#content').css('z-index',50);
		  $('.napoveda').addClass('schovaj');
		  $('#layer').addClass('schovaj');
		  $('#d').val('zobraziť novinky');
		}
	});
});

