/**
 * Resize text - can only change the font-size of em and % (relative font units) and NOT px (pixel)
 */
function resize_text()
{
  // Reset Font Size
  var originalFontSize = $('#page-main-content').css('font-size');
    $(".resetFont").click(function(){
    $('#page-main-content').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('#page-main-content').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum * 1.2;
	if (newFontSize < 24)
	{
		$('#page-main-content').css('font-size', newFontSize);
	}
    return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('#page-main-content').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum * 0.8;
	if (newFontSize >= 9)// Only allow font size bigger than 9 (by checking the logs in firebug)
	{
		$('#page-main-content').css('font-size', newFontSize);
	}
    return false;
  });
}




function get_slideshow_images()
{
	
	// Show ajax loader image
	$('#slideshow-ajax-loader').show();
	$.ajax({
		type: 'GET',
		dataType: 'json',// also add header in ajax-serverside script
		url: "/application/bin/slideshow_ajax.php",
		success: function(response) { 
			var json_formatted = response;
			
			// super detection of all IE versions
			//var IE = /*@cc_on!@*/false;
			//if (IE) ...
			var data = json_formatted;
			
			// Start building list
			var list = "\n";
			
			// Loop through all images in the returned array
			for (var idx in data)
			{
				//alert(data[idx]);
				//console.log(data[idx] +' '+ idx);
				// Append page as a list item, where the page id becomes the value
				list += '<li><img src="'+ data[idx] +'" alt="'+ data[idx] +'" width="500" height="316" /></li>'+"\n";
			}
			
			// Empty list before appending (showing) the images
			$('ul#slideshow-header').html('');
			$('ul#slideshow-header').append(list);
			
			slideshow_start();
		},
		error: function(xhr, type, exception) { 
			alert("Ett fel har uppstått (bildspelet): " + type); 
		}
	});
	
}


function slideshow_start()
{
	// Fetch image titles
	// http://jquery.malsup.com/cycle/int2.html
	$('ul#slideshow-header').cycle({
		fx: 'fade',
		speed: 1200,
		timeout: 7000,
		pager: '#slideshow-nav',
		pause: 1					// pause on hover
	});
}


$(document).ready(function(){
	resize_text();
	
	// Visa kontrollpanel vid hover: http://jquery.malsup.com/cycle/hover.html
	get_slideshow_images();
});
