var collapsedHeight;

function zp_gallery_open() {

  $("#fullimage ul:eq(0)").animate({top:0}, 1000, 'easeInOutExpo', function() {
    $("#fullimage ul:eq(0)").css('top', '0');
  });
  $("#fullimage").animate({height:473}, 1000, "easeInOutExpo", function(){
    $("#fullimage").css('height', '473px');
    $('#bannerToggle').stop().unbind().attr('src','img/banner.minus.gif').css({paddingRight:'100px',paddingBottom:'100px'}).hover(function() {$(this).stop().animate({opacity:'1.0'});}, function() {$(this).stop().animate({opacity:'0'});})
    $('#bannerToggle').click(zp_gallery_close);
  });
}

function zp_gallery_close() {
  $("#fullimage").animate({height:collapsedHeight}, 1000, "easeInOutExpo", function(){
    $("#fullimage").css('height', collapsedHeight);
  });
  $("#fullimage ul:eq(0)").animate({top:galYTargets[galOffset]}, 1000, 'easeInOutExpo', function() {
    $("#fullimage ul:eq(0)").css('top', galYTargets[galOffset]);
    $('#bannerToggle').stop().unbind().attr('src','img/banner.plus.gif').css({paddingRight:'37px',paddingBottom:'30px'}).animate({opacity:'1.0'}).click(zp_gallery_open);
  });
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

$(document).ready(function(){
    $('#bannerOpen').css({visibility:'visible',cursor:'pointer'});

    /* calculate offsets */
    /* TODO: targetY muss aus PHP (dem CMS) kommen, und sich auch auf das CSS auswirken -- aktuell #selectedImage, aber
     dann vermutlich per style direkt im Markup
    */
    bannerClass = $("#banner").attr("class");
    if (bannerClass == "tiny") {
        collapsedHeight= 20;
    } else if (bannerClass == "large") {
        collapsedHeight= 198;
    }

    $("#bannerOpen").click(function(){
      $("#bannerOpen").fadeOut("fast", function() {
        $("#fullimage").hide();
        $.get("dummy.php",{pd:pageDescriptor}, function (data) {
          $('#fullimage').html(data);
          $('.galshadow').ifixpng();
          $("#fullimage ul").css({top:galYTargets[galOffset], position:'absolute'});
          
          $("#fullimage").css({height:collapsedHeight}).show();
//          $("#banner").hide(); <- Auf display:none setzen provoziert einen Fehler in IE8, deswegen:
          $("#banner").css({visibility: 'hidden', height: '0px'});
          im = readCookie('selectedImage'+pageDescriptor);
          if (im) {
              $('#gal').slideView({setCookie:true,cookieName:pageDescriptor,showFirst:im});
          } else {
              $('#gal').slideView({setCookie:true,cookieName:pageDescriptor});
          }; 

          zp_gallery_open();

          /* bind the close-event */
          $('#bannerClose').click(function () {zp_gallery_close();return false;});
/*          $('.stripTransmitter li').hover(function(){$(this).addClass('hover');}, function(){$(this).removeClass('hover')});*/

          
        });
      });

      
      return false;
    });

});
