function plus_one(arr){
	if (arr.state == "on") {$('#thanks').show();}
	else {$('#thanks').hide();}

}

function temp_togle(){ //pro prepinani celsius/farenheit
	if ($('#container').hasClass('farenheit')) {
		$('#container').removeClass('farenheit');
	}else{
		$('#container').addClass('farenheit');
	}
}

/*
		Kalendář
						*/
function explode(a,b,c){var d={0:""};if(arguments.length<2||typeof arguments[0]=="undefined"||typeof arguments[1]=="undefined"){return null}if(a===""||a===false||a===null){return false}if(typeof a=="function"||typeof a=="object"||typeof b=="function"||typeof b=="object"){return d}if(a===true){a="1"}if(!c){return b.toString().split(a.toString())}var e=b.toString().split(a.toString());var f=e.splice(0,c-1);var g=e.join(a.toString());f.push(g);return f};

var req;
function set_tip(){
var tip = $('#tip');
$("tr.dayrow td a").hover(function(){
	var content = '',additional, spanClass = '',i = 0;
	var events = explode(',',$(this).attr('rel'));

	$.each(events,function(key, value)
		{
			additional = ($('#eventTitle-' + value)) ? $('#eventTitle-' + value).html() : '';
			if (additional)
			{
				i++;
				//alert(i);
				spanClass =  (i == '1') ? ' class="first"' : '';
				content += '<span' + spanClass + '>' + additional + '</span>';
			};
		}
	);
	//tip = $(this).find('.tip');
	tip = $('#tip');
	tip.html(content);
	if (content) tip.show(); //Show tooltip
}, function() {
	tip.hide(); //Hide tooltip
	}).mousemove(function(e) {
	var mousex = e.pageX - 540; //Get X coodrinates
	var mousey = e.pageY - 240; //Get Y coordinates
	var tipWidth = tip.scrollWidth; //Find width of tooltip
	var tipHeight = tip.scrollHeight; //Find height of tooltip

	//Distance of element from the right edge of viewport
	var tipVisX = $(window).width() - (mousex + tipWidth);
	//Distance of element from the bottom of viewport
	var tipVisY = $(window).height() - (mousey + tipHeight);

	if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
		mousex = e.pageX - tipWidth + 20;
	} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
		mousey = e.pageY - tipHeight + 20;
	}
	//Absolute position the tooltip according to mouse position
	$('#tip').css({  top: mousey, left: mousex });
	});
}
function kalendarItem(rel){

	$('.entry').slideUp();


	var events = explode(',',rel);

	$.each(events,function(key, value)
		{
			//alert('.item-' + value);
			$('.item-' + value).slideDown();
		}
	);

}
function navigate(month,year) {
	var url = "http://www.private-prague-guide.com/articles/?kalendar=small&cmonth="+month+"&cyear="+year;

	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", url, true);
	req.onreadystatechange = callback;
	req.send(null);
}
function show_rest(){
	$('.entry:hidden').slideDown();
	$('.cal_btn_switch').attr('href', 'javascript:show_upcoming()');
	$('.cal_btn_switch div').html('Show upcoming');
}
function show_upcoming(){
	$('.entry.past').slideUp();
	$('.cal_btn_switch').attr('href', 'javascript:show_rest()');
	$('.cal_btn_switch div').html('Show all');
}
function callback() {
	obj = document.getElementById("calendar");

		if(req.readyState == 4) {
		if(req.status == 200) {
			response = req.responseText;
			obj.innerHTML = response;
			set_tip();
		} else {
			//alert("There was a problem retrieving the data:\n" + req.statusText);
		}
	}
}

$(function () {
		navigate("","");
	});

