$(document).ready(function(){
	
	var logoheight = $('#header .leftside .logo img').height();

	$('#header .leftside .links').css('height', logoheight + 'px');
	$('#header .leftside .links a').css('line-height', logoheight + 'px');

	$('#header .rightside .form .unameinput input').click(function() {
		if(this.value === 'Käyttäjätunnus' || this.value === 'Username') {
			this.value = '';
		}
	});	
	$('#header .rightside .form .passinput input').click(function() {
		if(this.value === 'Salasana' || this.value === 'Password') {
			this.value = '';
		}
	});

	var h2toppadding = $('h2').css('padding-top');
	if(h2toppadding)
		$('#content .middle .kuva').css('margin-top', (parseInt(h2toppadding.substring(0, (h2toppadding.length - 2))) + 3) + 'px');


	$.ajax ({
		url: "/www/ajax/tapahtumat.php",
		cache: false,
		success: function(html)
		{
			$("#my-events").html(html);
		}
	});

	$('.event-add').click(function() {

		var objid = $(this).attr('id');

		$.ajax ({
			url: "/www/ajax/tapahtumat.php?add=" + objid,
			cache: false,
			success: function(html)
			{
				$("#my-events").html(html);
				$.ajax ({
					url: "/www/ajax/tapahtumat.php",
					cache: false,
					success: function(html)
					{
						$("#my-events").html(html);
					}
				});
			}
		});

	});

	$('.list-event-add').click(function() {
			
		$tama = $(this);
		var objid = $(this).attr('id');

		$.ajax ({
			url: "/www/ajax/tapahtumat.php?add=" + objid,
			cache: false,
			success: function(html, tama)
			{
				$tama.parent().html('<span style="color: #d20000;">Tapahtuma on lisätty omiin tapahtumiisi.</span>');
				$.ajax ({
					url: "/www/ajax/tapahtumat.php",
					cache: false,
					success: function(html)
					{
						$("#my-events").html(html);
					}
				});
			}
		});

	});

	$('.event-show-add').click(function() {
			
		$tama = $(this);
		var objid = $(this).attr('id');

		$.ajax ({
			url: "/www/ajax/tapahtumat.php?add=" + objid,
			cache: false,
			success: function(html, tama)
			{
				$tama.parent().html('<span style="color: #d20000;">Tapahtuma on lisätty omiin tapahtumiisi.</span>');
				$.ajax ({
					url: "/www/ajax/tapahtumat.php",
					cache: false,
					success: function(html)
					{
						$("#my-events").html(html);
					}
				});
			}
		});

	});

	$('.event-drop').click(function() {

		$tama = $(this);
		var objid = $(this).attr('id');

		$.ajax ({
			url: "/www/ajax/tapahtumat.php?drop=" + objid,
			cache: false,
			success: function(html)
			{
				$tama.parent().parent().remove();
				$.ajax ({
					url: "/www/ajax/tapahtumat.php",
					cache: false,
					success: function(html)
					{
						$("#my-events").html(html);
					}
				});
			}
		});

	});

});
