﻿$(document).ready(function(){

	// Left menu functionality
	// For <li> items that have a nested <ul> (submenu) but DON'T lead to a specific page
	$('ul.menu > li:has(ul):has(li) > a[href="#"]').each(function(){
		$(this).click(function(){
			$(this).next('ul').slideToggle().end().toggleClass('selected');
			return false;
		});
	});
	
	// Event handlers for the font enlarge / reduce links
	$('a.font_resize_smaller').click(function(){
		metadataFontsize('-');
		return false;
	});
	$('a.font_resize_larger').click(function(){
		metadataFontsize('+');
		return false;
	});
	
	// If we're working on localhost, subst the image.ashx with e-tipos.metadata.gr/image.ashx
	if ($(window).attr('location').toString().match("localhost") != null) {

		var site = 'kokkalisfoundation.metadata.gr';
		$('img[src*=mage.ashx]').attr('src', function() {
			return 'http://' + site + '/' + $(this).attr('src');
		});

	}

});

// Change font size
function metadataFontsize(dir) {
     
    // If we don't have a direction, set it to +
    if (!dir) { dir = "+"; }
       
	// Get the pixel size of the font inside the article body
	var fontSize = parseInt($('.article_left').css('font-size').replace('px',''));

	if (fontSize) {
		if (dir == "+") {
			fontSize = fontSize + 1;
		} else if (dir == "-") {
			fontSize = fontSize - 1;
		}
		if (fontSize < 11 || fontSize > 16) { fontSize = 11; }
		$('.article_left,.article_body').css({
			'font-size':fontSize,
			'line-height':'1.4em'
		});
	}

}

function openCenteredWindowNoScroll(url, height, width) {
	var left = Math.floor((screen.width - width) / 2);
	var top = Math.floor((screen.height - height) / 2);
	var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
	winParms += "," + "titlebar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,alwaysRaised=yes,AlwaysOnTop=yes";
	popupWindow = window.open(url, "", winParms);
}
