var footerHeight = 100;
var imagewidth = 1400;
var imageheight = 840;

//SWITCHER for slideshow, pass the index, then fade in the li based of parameter, hide others
function slideshowSwitch(newSlideIndex) {
    $slideshow = $('#fullscreenimage ul');
    $slideshow.children('li').eq(newSlideIndex).hide();
    $slideshow.children('li').eq(newSlideIndex).children('img').show();
    $slideshow.children('li').eq(curSlideIndex).fadeOut(500,function(){
        $slideshow.children('li').eq(curSlideIndex).addClass('nodisplay');
        $slideshow.children('li').eq(newSlideIndex).fadeIn(500);
        $slideshow.children('li').eq(newSlideIndex).removeClass('nodisplay');
        $slideshow.children('li').eq(newSlideIndex).show();
        curSlideIndex = newSlideIndex;
    });
}

//ENLARGE IMAGE - Set to fullscreen image
function supersizeImage(image) {
	var browserwidth = $(window).width();
	var browserheight = $(window).height();

	var ratio = imageheight/imagewidth;

	if ((browserheight/browserwidth) > ratio){
		$(image).height(browserheight);
		$(image).width(browserheight / ratio);
	} else {
		$(image).width(browserwidth);
		$(image).height(browserwidth * ratio);
	}
	$(image).css('left', (browserwidth - $(image).width())/2);
	$(image).css('top', (browserheight - $(image).height())/2);
}

/* Function to be called when window is resized */
function resizeAll()
{
	forceSupersize();
	setErrorRaportLocationToBottom();
}

//Force resize all the fullscreen image
function forceSupersize() {
	$('img.supersize').each(function() {
		if($(this).parent().is(':visible')) {
			supersizeImage($(this));
		} else {
			$(this).parent().removeClass('nodisplay');
			$(this).parent().show();
			supersizeImage($(this));
			$(this).parent().hide();
		}
	});
}

/* ACTIONS */

$(document).ready(function ()
{
	//RESIZE - all fullscreen image to be fullscreen
	$('img.supersize').each(function(){
		supersizeImage($(this));
	});

	//LISTENER - in window that will resize, reposition everything
	$(window).bind("resize", resizeAll);

	$("#trh-isannointi").click(function (e) {
		e.preventDefault();
		$("#dialog").dialog({
			height: 140,
			modal: true,
			resizable: false
		});
	});

	// Preload hover-image
	hoverPic = new Image(369,180); 
	hoverPic.src = "/uploads/trhleiska/ovimatto/hover.png"; 
});


