function checkDonation(ele){
    var sel = ele.selectedIndex;
    $('#donation_sel_info').find('.account_info').css('display', 'none');
    $('#donation_sel_info').children().eq(sel).css('display', 'block');
}
var fancyboxText = {
    pic : 'Bild',
    of : 'von',
    pics : 'Bildern',
    press_download : 'Download in Druckqualität'
}

function swapText(ele1,ele2){
  if(ele1 && ele2){
    var t1 = ele1.text();
    ele1.text(ele2.text());
    ele2.text(t1);
  }
}

$(document).ready(function(){
  $('.history_back').click(
    function(){
      history.back(-1);
      return false;
    }
  );
	if(typeof fixIEQuotes!='undefined'){
		fixIEQuotes();
	}
	$("a.fancy").fancybox({
		'titlePosition'	: 'inside',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
			var org = currentOpts.orig.parent();
			var id = org.attr('id');
			if(typeof id!='undefined' && id.indexOf('press_img_')>-1){
		      id = id.replace(/press_img_/,'');
		      var download = $('#press_download_'+id);
		      var pname = $('#press_picturename_'+id);
		      var headline = $('<span>').text(pname.html());
		      if(download.length>0){
			        var download_clone = download.parent().clone(true);
			        download_clone.find('a').text(fancyboxText.press_download);
			        download_clone.find('a').addClass('download_fancybox');
			        if( pname.html() != "" ){
			        	var txt = $('<p>').text(title).prepend(headline);
			        	var wrapper = $('<div>').append(txt).append(download_clone).remove();
			        }else{
			        	var txt = $('<p>').text(title);
			        	var wrapper = $('<div>').append(txt).append(download_clone).remove();
			        }
			        return wrapper.html();
		      }else{
		    	  	var txt = title;
			        if( pname.html() != "" ){
			        	var wrapper = $('<div>').append(headline).append(txt).remove();
			        }else{
			        	var wrapper = $('<div>').append(txt).remove();
		      		}
			        return wrapper.html();
		      }
			}
			return ''+title;
		}
	});
	$("a[rel=image_group]").fancybox({
		'titlePosition'	: 'inside',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
        'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
            return '<span>'+ fancyboxText.pic + ' ' + (currentIndex + 1) + ' ' + fancyboxText.of + ' ' + currentArray.length + ' ' + fancyboxText.pics + ' / ' + title + '</span>';
        } 
	});
	$("a[rel=image_group_marg]").fancybox({
		'titlePosition'	: 'inside',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
        'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
            return '<span>'+ fancyboxText.pic + ' ' + (currentIndex + 1) + ' ' + fancyboxText.of + ' ' + currentArray.length + ' ' + fancyboxText.pics + ' / ' + title + '</span>';
        } 
	});
    
     $('#donation_sel').change(function(){
            checkDonation(this);
     });
     $('#donation_sel').change();
    $('.opener').each(function(){
      var par = $(this).css('display','block').parent().find('.opened').css('display','none');
    });
    $(".opener").click().toggle(function() {
    swapText($(this).find('.opener_text'),$(this).next('.alt_text'));
		$(this).parent().find('.opened').animate({
			opacity: 'show',
			height: 'toggle'
		}, 'fast');
	}, function() {
    swapText($(this).find('.opener_text'),$(this).next('.alt_text'));
		$(this).parent().find('.opened').animate({
			opacity: 'hide',
			height: 'toggle'
		}, 'fast');
	}); 
});
	
