var ie7 = (document.all && !window.opera && window.XMLHttpRequest);

function AjaxUpdaterHighlight2(args, meth, div, highlight)
{
	var req = new Request(
		{
			method: ''+meth+'',
			url: 'ajaxRequest.php',
			onSuccess: function(txt) {
				$(div).innerHTML = txt;
				if (highlight == true)
				{
					myEffect = new Fx.Morph($(div), {duration: 800, transition: Fx.Transitions.Sine.easeOut});
					myEffect.start({
					    'opacity': [0, 1.0],
					    'padding-left': [15, 0]
					});
				}
			},
			onFailure: function() {
				alert('The request failed.');
			}
		}
	).send(args);
}
function addFavourite(foto_id)
{
	$("fav_link").innerHTML = "<a class='option_item' href='#' OnClick=\"return false;\">&raquo; Gett gespaichert ...</a>";
	AjaxUpdaterHighlight2("page=favorite_add&foto_id=" + foto_id, "post", "fav_link", true);
	return false;
}

function whoFav(foto_id)
{
	new Request(
	{
	    url: "ajaxRequest.php",
	    onSuccess: function(txt) {
		if (txt != "")
		{
		    dimSite(txt);
		}
	    },
	    onFailure: function() {
		popupdiv = null;
		alert('The request failed: '+url);
	    }
	}
    ).send("page=favorite_who&foto_id="+foto_id);
    return false;
}

function removeFavourite(fav_id, foto_id)
{
	AjaxUpdaterHighlight2("page=favorite_remove&fav_id=" + fav_id + "&foto_id=" + foto_id, 'post', "fav_link", true);
	return false;
}

function addToPOTWVotelist(foto_id)
{
	AjaxUpdaterHighlight2("page=addphoto_potwvote&foto_id=" + foto_id, 'post', "potw_link", true);
	return false;
}

var photo_id;
var img_src;
var img_id;
var img;
var oldimg_out = false;
var fadeoutFx;

function LoadPhoto(photoID, image, id)
{
	fadeoutFx = new Fx.Tween($("foto_element"), { duration:'short', onComplete: function() { oldimg_out = true; }});
	fadeoutFx.start("opacity", 0.3);
	photo_id = photoID;
	img_src = image;
	img_id = id;
	
	if (!ie7)
	{
		img = new Image();
		img.addEventListener('load', showPhoto, false);
		img.src = image; 
	}
	else showPhoto();
}

function showPhoto()
{
	$('foto_element').innerHTML = "<a href='view.php?id="+photo_id+"' target='_blank'><img src='"+img_src+"' alt=''></a>";
	
	fadeoutFx.cancel();
	var myFx = new Fx.Tween($("foto_element"), { duration:'short', onComplete: function() { oldimg_out = false; }});
	myFx.start("opacity", 1.0);
}