function gallery(options) {
	
	History.set('FOTO_ID', options['fotoId']);
	
	var seite 		= options['seite'] || 'singlefoto';
	var rider		= strReplace(options['rider']);
	var city 		= strReplace(options['city']);
	var credit 	= strReplace(options['credit']);
	var text 		= strReplace(options['text']);
	new Ajax.History.Updater('userContainer','/cgi-bin/adframe/gallery/'+seite+'.snp',{onComplete: function(r) {collapseComments(); },method:'get',evalScripts:true,
		parameters: {CARD_ADFRAME_USER_ID:options['cardId'],ALBUM_ID:options['albumId'],FOTO_ID:options['fotoId'],ORDER:options['order'],RIDER:rider,CITY:city,CREDIT:credit,adframe_event:options['adframeEvent'],TEXT:text,id:options['id']},
		 history : { id:'z',cache : false  }
		}	
	);
	ReloadPixelImages();
}	

function collapseComments() {
	$('comments').myOffsetHeight = $('comments').offsetHeight;
	$('comments').style.display = "none";
}	
	
function post_comment(fotoId,comment,id) {
	comment = comment.replace(/\n/g,'<br>');
	comment = strReplace(comment);
	$('comment_write').innerHTML='';
	$('FORMULAR').innerHTML = '<img src="/img/loading.gif" style="margin:30px 0 0 223px;">';
	new Ajax.Updater('commentContainer','/cgi-bin/adframe/gallery/foto_comments.snp',{method:'get',evalScripts:true,parameters: {adframe_event:'comment_form',id: id,FOTO_ID:fotoId,FORUM_COMMENT:comment}});
}

function delete_comment(commentId,fotoId,id) {
			
	if (confirm('Den Kommentar wirklich loeschen?')) {
		new Ajax.Updater('commentContainer','/cgi-bin/adframe/gallery/foto_comments.snp',{method:'get',evalScripts:true,parameters: {adframe_event:'__DEL_COM__',ADFRAME_FORUMCOMMENT_ID:commentId,FOTO_ID:fotoId,id: id}});
	}
}
		
function quote(id,session) {
	
	var name = $('name_'+id).innerHTML;
	new Ajax.Request('/cgi-bin/adframe/gallery/foto_comment_quote.snp',
	{encoding:'iso-8859-1',method:'get',
	parameters: {QUOTE:id,NAME:name,id: session},onSuccess:function(transport) { document.comment_form.FORUM_COMMENT.value=strReturn(transport.responseText)}});
	
}
function beachball(id) {

	$(id).innerHTML ='<img src="/img/loading.gif" style="margin:200px 50% 0 50%;">';
}

function goComment(id) {
	
	if($(id).style.display == 'none') { slide('comments');}
	Effect.ScrollTo('commentform',{duration:0.2});
	return false;

}

function changeThumbs(id,mini,maxi) {
	var steps = 5;
	distance = parseInt((maxi-mini)/steps);
	function openThumbs()
	{
		var hoehe = $(id).style.height;
		hoehe = parseInt(hoehe.replace(/px/g, ""));
		if(hoehe+distance <= maxi){
			$(id).style.height = hoehe+distance+"px";

		}
		else { clearInterval(interval);}
		$(id+'_img').src='/img/minus.png';

	}
	
	function closeThumbs()
	{
		var hoehe = $(id).style.height;
		hoehe = parseInt(hoehe.replace(/px/g, ""));
		if(hoehe-distance >= mini) {
			$(id).style.height = hoehe-distance+"px";

		}
		else { clearInterval(interval);}
		$(id+'_img').src='/img/plus.png';

	}
	
	if($(id).style.height==mini+'px') { interval = setInterval(openThumbs,1); }
	else { interval = setInterval(closeThumbs,1); }
	
	
}

function delImage(id,text,session) {
	text = strReplace($F(text));
	if(text == '') { alert('Bitte begründen!');return false; }
	else { 
		gallery({seite:'singlefoto',fotoId:id,adframeEvent:'confirmed_delete',text:text,id:session});return false; 
	}
}

function album(seite,cardId,albumId,title,text,id) {

	title = strReplace(title);
	text = strReplace(text);
	new Ajax.Updater('userContainer','/cgi-bin/adframe/gallery/'+seite+'.snp',{contentType:'text/html',encoding:'iso-8859-1',method:'get',evalScripts:true,parameters: {CARD_ADFRAME_USER_ID:cardId,ALBUM_ID:albumId,adframe_event:seite,TEXT:text,TITLE:title,id:id}});

}	

function deleteImg(card_id,album_id,foto_id,id)
{
	var ok = confirm("Willst du das Bild wirklich entfernen???");
	if (ok)
	{
		new Ajax.Updater('userContainer','/cgi-bin/adframe/gallery/edit_foto.snp',{contentType:'text/html',encoding:'iso-8859-1',method:'get',evalScripts:true,parameters: {CARD_ADFRAME_USER_ID:card_id,adframe_event:'__del__ImG__',ALBUM_ID:album_id,FOTO_ID:foto_id,id:id}});

		
	}
}

function deleteAlbum(card_id,album_id,id)
{
	var ok = confirm("Willst du das Album und alle darin enthaltenen Bilder wirklich entfernen???");
	if (ok)
	{
		new Ajax.Updater('userContainer','/cgi-bin/adframe/gallery/edit_album.snp',{contentType:'text/html',encoding:'iso-8859-1',method:'get',evalScripts:true,parameters: {CARD_ADFRAME_USER_ID:card_id,adframe_event:'__del__AlB__',ALBUM_ID:album_id,id:id}});

		
	}
}




function latest(start,nextpage,expand,id) {


	new Ajax.History.Updater('latestContainer','/cgi-bin/adframe/gallery/latest_fotos.snp',{contentType:'text/html',encoding:'iso-8859-1',method:'get',evalScripts:true,
		parameters: {start:start,nextpage:nextpage,expand:expand,id:id},
		 history : { id:'z',cache : false  }
		}	
	);
}	

function rating(fotoId,rating,id) {


	new Ajax.Updater('ratingContainer','/cgi-bin/adframe/gallery/rating.snp',{onComplete: function(doof) {ratingUpdate(id) },contentType:'text/html',encoding:'iso-8859-1',method:'get',evalScripts:true,
		parameters: {ADFRAME_FOTO_ID:fotoId,rating:rating,id:id}}	
	);
	
}	

function ratingUpdate(id) {

	new Ajax.Updater('ratedContainer','/cgi-bin/adframe/gallery/rated_fotos.snp',{contentType:'text/html',encoding:'iso-8859-1',method:'get',evalScripts:true,
	parameters: {id:id}}	
	);
}
function textCounter(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) 
	{	
		field.value = field.value.substring(0, maxlimit);
	}
	else
	{ 
		countfield.value = maxlimit - field.value.length;
	}
}

function enableDropdownMenuForIE()
{
    if (document.all)
	{
        uls = document.getElementsByTagName('UL');

        for(i = 0; i < uls.length; i++)
        {
            if (uls[i].className == 'dropdown')
            {
                var lis = uls[i].getElementsByTagName('li');

                for (j = 0; j < lis.length; j++)
                {
                    if(lis[j].lastChild.tagName == 'UL')
                    {
                        lis[j].onmouseover = function() { this.lastChild.style.display = 'block'; }
                        lis[j].onmouseout = function() { this.lastChild.style.display = 'none'; }
                    }
                }
            }
        }
    }
}
