$(document).ready(function() {
    // stripe
    $("table#program tr:nth-child(even)").addClass("even");

    // tulostusnappi
    $("div#print_link").click(function() {
			$("div#rest-of-showdays").show();
		}
	);
    
	// prettyPhoto
	$("a[rel^='prettyPhoto']").prettyPhoto();

	$("div#review-popup").dialog(
		{
		buttons: { "Lähetä kommentti": function() {
				var rating = $("input#review_rating").val();
				var nick = $("input#nick").val();
				var content = $("textarea#content").val();
				var playId = $("input#playId").val();
				var spamblock = $("input#spamblock").val();
				if(rating == '' || nick == '' || content == '' || spamblock == '') {
					$("div#review_error").html('T&auml;yt&auml; kaikki kent&auml;t').addClass("error");
				}
				else {
					$.post('teatteri_ajax.php', { act: 'submitReviewScore', rating: rating, nick: nick, content:content, playId: playId, sbca: $("input#sbca").val(), spamblock: spamblock},
						function(returned_data) {
							if(returned_data.result) {
								/*
								$("input#review_rating").val('0');
								$("input#nick").val('');
								$("textarea#content").val('');
								*/
								//alert(returned_data.message);
								window.location.href = window.location.href;
								//$(this).dialog('close');
							}
							else {
								$("div#review_error").html(returned_data.message).addClass("error");
							}
						}, "json"
					);
				}
			} 
		},
		close: function() {
				$("input#review_rating").val('0');
				$("input#nick").val('');
				$("textarea#content").val('');
				$("div#review_error").removeClass("error");
			},
		draggable: false,
		modal: true,
		autoOpen: false,
		width:500,
		title: 'Kommentoi näytelmää'
		}
	);

	$("a#review_open").click(function() {
		$("div#review-popup").dialog('open');
	});

	$('.star[class!="star-rating-readonly"]').click(function() {
			$("input#review_rating").val($(' a', this).attr('title'));
		}
	);

	$("a#increase-font").click(function() {
			var curSizeNum = parseFloat($("body").css("font-size"), 10);
			var newSize = curSizeNum*1.1;
			$.post('teatteri_ajax.php', { act: 'setFontSize', size: newSize});			
			//$("body").css("font-size", newSize);
			window.location.href = window.location.href;
		}
	);

	$("a#reset-font").click(function() {
		$.post('teatteri_ajax.php', { act: 'setFontSize', size: 'reset'});
		window.location.href = window.location.href;
	});
	
	$("a#decrease-font").click(function() {
			var curSizeNum = parseFloat($("body").css("font-size"), 10);
			var newSize = curSizeNum/1.1;
			$.post('teatteri_ajax.php', { act: 'setFontSize', size: newSize});			
			//$("body").css("font-size", newSize);
			window.location.href = window.location.href;
		}
	);
	
	$("a#more-showdays").click(function() {
			$("div#rest-of-showdays").toggle();
		}
	);
	
    
    // defaulttina liput auki
    $('div.menu1').css({'background-image':'url(images/tab_liput_hover.png)'});
	$("a.tab").click(function() {
			var ID = 'tab_'+$(this).attr('rel')+'_content';
			$("div#tab_content").html($("div#"+ID).html());
            $("a.tab").children('div').removeAttr('style'); /* Kristian */
            $(this).children('div').css({'background-image':'url(images/tab_'+$(this).attr('rel')+'_hover.png)'}); /* Kristian */
		}
	);
	
	$("a.changeCalendarMonth").live('click',
		function() {
			var year_month = $(this).attr('rel');
			$.post('teatteri_ajax.php', {act: 'getCalendar', year_month: year_month}, 
				function(returned_data) {
					$("div#calendar").html(returned_data);
				}
			);
		}
	);

	$("a.changeCalendarDay").live('click',
		function() {
			var year_month_day = $(this).attr('rel');
			$("span[class*='selected']").each(
				function() {
					$(this).removeClass('selected');
				}
			);
			$("span", this).addClass('selected');
			$.post('teatteri_ajax.php', {act: 'getCalendarDayPlays', year_month_day: year_month_day}, 
				function(returned_data) {
					$("div#calendarPlays").html(returned_data);
				}
			);
		}
	);
	
	$("a.staff_toggle").click(function() {
			var id = $(this).attr('rel');
			$("div#"+id).toggle();
		}
	);

	$("#slider").easySlider(
		{
			prevText: '<img src="images/prev_button.png" />',
			nextText: '<img src="images/next_button.png" />',
			continuous: true,
			auto: true,
			pause: 5000
		}
	);
	
});


function popUp(url) {
	window.open( url, "myWindow", "status = 1, height = 370, width = 470, resizable = 0" )
}