function open_picture_in_window(picture, alt, width_f, height_f)
{
	var win = new Window({
				className: "dialog",
				width: width_f,
				height: height_f,
				zIndex: 100,
				resizable: true,
				title: alt,
				showEffect:Effect.BlindDown,
				hideEffect: Effect.SwitchOff,
				draggable:false,
				wiredDrag: false,
				minimizable: false,
				maximizable: false,
				resizable: false
				});
	win.getContent().innerHTML= "<img src='" + picture + "' alt='" + alt + "' align='centre' />";
	win.showCenter();
} 

function change_menu_picture(id)
{
	pic= $("meni_picture");
	pic.src="images/m_" + id + ".png"
}

var max_width = 640;
var max_height = 480;
var win;

function open_in_new_window() {
	  var pic = $('bigpic');
/*	  var newImg = new Image();
	  newImg.src = pic.src;
	  var H = newImg.height;
	  var W = newImg.width;*/
	  window.open(pic.src, pic.alt,'fullscreen=yes,scrollbars=yes,menubar=no,status=no,location=no,toolbar=no');
}

var picture_selected = 0;

function nextpicture() {
	picture_selected = picture_selected +1;
	if(picture_selected == piclist.length) picture_selected = 0;
	var pic = $('bigpic');
	var alt = (piclist[picture_selected][1] === '') ? piclist[picture_selected][0] : piclist[picture_selected][1];
	Windows.getFocusedWindow().setTitle(alt);
	pic.alt = alt;
	pic.width = 1;
	pic.height = 1;
	pic.onload=imageloaded;
	pic.src = startfolder +piclist[picture_selected][0];
}

function prevpicture() {
	picture_selected = picture_selected -1;
	if(picture_selected == -1) picture_selected = piclist.length -1;
	var pic = $('bigpic');
	var alt = (piclist[picture_selected][1] === '') ? piclist[picture_selected][0] : piclist[picture_selected][1];
	Windows.getFocusedWindow().setTitle(alt);
	pic.alt = alt;
	pic.width = 1;
	pic.height = 1;
	pic.onload=imageloaded;
	pic.src = startfolder +piclist[picture_selected][0];
}

function imageloaded (bool) {
	  var pic = $('bigpic');
	  var newImg = new Image();
	  newImg.src = pic.src;
	  var H = newImg.height;
	  var W = newImg.width;
	  
	  //set image size
	  var x_ratio = max_width / W;
	  var y_ratio = max_height / H;
	  var tn_W, tn_H;
	  if ((W <= max_width) && (H <= max_height) ) {
	    tn_W = W;
	    tn_H = H;
	    pic.setStyle({cursor: 'default'});
	    pic.onclick = false;
	  } else if ((x_ratio * H) < max_height) {
	    tn_H = Math.ceil(x_ratio * H);
	    tn_W = max_width;
	    if(Prototype.Browser.Gecko) pic.setStyle({cursor: '-moz-zoom-in'});
	    else pic.setStyle({cursor: 'crosshair'});
	    pic.onclick = open_in_new_window;
	  } else {
	    tn_W = Math.ceil(y_ratio * W);
	    tn_H = max_height;
	    if(Prototype.Browser.Gecko) pic.setStyle({cursor: '-moz-zoom-in'});
	    else pic.setStyle({cursor: 'crosshair'});
	    pic.onclick = open_in_new_window;
	  }
	  pic.width = tn_W;
	  pic.height = tn_H;
	  pic.onload = false;
	  pic.src = pic.src;
	};

function open_picture_in_window_new(id)
{
	picture_selected = id;
	var alt = (piclist[picture_selected][1] === '') ? piclist[picture_selected][0] : piclist[picture_selected][1];
	picture = startfolder +piclist[picture_selected][0];
	Windows.closeAll();
	win = new Window({
				className: "dialog",
				width: max_width,
				height: max_height,
				zIndex: 100,
				resizable: true,
				title: alt,
				showEffect:Effect.BlindDown,
				hideEffect: Effect.SwitchOff,
				draggable:false,
				wiredDrag: false,
				minimizable: false,
				maximizable: false,
				resizable: false
				});
	win.getContent().innerHTML= "<img src='" + picture + "' alt='" + alt + "' id='bigpic' width='1' height='1' />";
	$(win.element.id).insert({top: "<div id='" + win.element.id + "_prev' onclick='prevpicture()' class='dialog_prev'> </div><div id='" + win.element.id + "_next' onclick='nextpicture()' class='dialog_next'> </div>"});
	win.setDestroyOnClose();
	win.showCenter();
	$('bigpic').onload=imageloaded;
}
