




$(function() {






  //corner which opens login etc
    $('.go-on-corner').click(
      function() {
        
        $('div#go-on-corner-popup').slideToggle(1000);
        if(document.getElementById('UserUsername')) {
          document.getElementById('UserUsername').focus();
        }
      }
    );
    

// Photogallery select
  $('.contentElementPhotogalleryAlbumSelect').livequery(
    'change', 
    function() {
      if (this.options[this.selectedIndex].value!=this.lastsel) {
			 window.location.href=ajaxPath+$(this).attr('pagename')+'/album/'+this.options[this.selectedIndex].value;
		  }
	  }
  );


  // Image click popup
  $('.contentElementPopupImage').livequery(
    'click', 
    function() {

        $.ImagePopup.show($(this).attr('large'),$(this).attr('title'));


	  }
  );

// Guestbook
  $('.MGuestbookForm form').submit(
	function() {
		 $('.MGuestbookForm .chk').val('chkfld');

	}

	);



  /*****************************************************************************
   *
   * IMage popup
   *  
   ****************************************************************************/
  $.ImagePopup= {
	
    show: function(img,title) {

	// Hide objects that are always on top
  	$("object").css("visibility","hidden");
  	$("embed").css("visibility","hidden");
      	$("select").css("visibility","hidden");

	
	// Create background
	var background = $('<div/>');
	$(background).attr('class', 'ImagePopupBackground');
	$(background).animate({'opacity' : '.8'}, 300);
	$(background).css(
		{
		'width' : $(document).width(),
		'height' : $(document).height()
		});

	$('body').append(background);

	// Create image 

	var newImage = $('<img/>');
	var newDiv = $('<div/>');
	var newTitle = $('<h2/>');
	$(newTitle).html(title);
	$(newTitle).attr('class', 'ImagePopupTitle');


	var width = $('body').width();

	$(newImage).attr('src',img);
	$(newDiv).attr('class', 'ImagePopupImg');

	


	$('body').append(newDiv);
	$(newDiv).append(newTitle);
	$(newDiv).append(newImage);
	

	// Wait for image to load
 
	$(newDiv).css('visibility','hidden');
	$(newImage).load(function () {
		
		$(newDiv).css('visibility','visible');
		$(newDiv).css('height',$(newImage).height());
		var top=$(newDiv).vCenter();

		
		
 		$(newDiv).css("left",$(document).width()/2-$(newImage).width()/2);

		$(newDiv).css({'opacity' : '.1'});
		$(newDiv).animate({'opacity' : '1'}, 300, function() {

			$(newDiv).bind('click', function() {

 

				$(newDiv).fadeOut(400, function() {
					$(newDiv).remove();
					$("object").css("visibility","visible");
		  			$("embed").css("visibility","visible");
		      			$("select").css("visibility","visible");

				});
				$('.ImagePopupBackground').fadeOut(400, function() {
					$(newDiv).remove();
				});
			});
		});
	});
    }

  }



    
    
});


