﻿$(function(){

	$('hr').before('<div class="hr"></div>').remove();

	$('div.workplace').hover(
		function() {
			var elem = $(this).find('.hidden');
			if (elem.length > 0)
			{
				if (elem.attr('oh')==undefined)
				{
					elem.attr('oh', $.css(elem[0], 'height'));
					
				}
				//stop all animations:
				elem.queue("fx", []);
				elem.css({height: '0', display: 'block'});
				elem.animate({height: elem.attr('oh') + 'px' }, 300)
			}
		},
		function() {
			var elem = $(this).find('.hidden');
			if (elem.length > 0)
			{
				//stop last animation:
				elem.stop();
				elem.slideUp(300);
			}
		});
		
	var loadingImg = 'http://app.alejtech.eu/lightbox/img/loading.gif';
	$('img.popup').click(function()
		{
			if ($('#apopup')) {$('#apopup').remove()};
			var src = this.src.replace(/\?[hw].*/, '?w=600&h=600');

			var left = $(document).width() / 2 - 20;
			var top = $(window).height() / 2 - 20;

			var cont = '<div id="apopup"><div style="background-color: #004483; opacity: 0.8; filter: alpha(opacity=80); -moz-opacity:0.8; -khtml-opacity: 0.8; position: absolute; top: 0px; left: 0px; cursor: pointer; width: 100%; height: ' + $(document).height() +  'px;  "></div><img src="' + loadingImg + '" alt="" style="border: 3px solid #ddd; padding: 1em; background-color: white; top: ' + top + 'px; left: ' + left + 'px; position: fixed; cursor: pointer; #top: ' + (top + $(document).scrollTop()) +'px; #position: absolute; " /></div>';
			$('body').append(cont);

			$('<img style="visible: hidden; position: absolute;" src="' + src + '" />').appendTo('body').load(function() {
				
				var $this = $(this);
				//alert(this.width);
				left = $(document).width() / 2 - this.width / 2;
				top = $(window).height() / 2 - this.height / 2;
				
				$('#apopup img').css({top: top + 'px', left: left + 'px'});
				$('#apopup img').attr('src', src);
				
				if ($.browser.msie && $.browser.version < 8)
				{
					$('#apopup img').css({top: (top + $(document).scrollTop()) + 'px'});
				}
				
				$this.remove();
			});

			
			
			$(document).click(function() {$('#apopup').remove();});
			return false;
		}).css('cursor', 'pointer');		

});

