jQuery.fn.onImagesLoaded = function(_cb) { 
  return this.each(function() {
 
    var $imgs = (this.tagName.toLowerCase()==='img')?$(this):$('img',this),
        _cont = this,
            i = 0,
    _done=function() {
      if( typeof _cb === 'function' ) _cb(_cont);
    };
 
    if( $imgs.length ) {
      $imgs.each(function() {
        var _img = this,
        _checki=function(e) {
          if((_img.complete) || (_img.readyState=='complete'&&e.type=='readystatechange') )
          {
            if( ++i===$imgs.length ) _done();
          }
          else if( _img.readyState === undefined ) // dont for IE
          {
            $(_img).attr('src',$(_img).attr('src')); // re-fire load event
          }
        }; // _checki \\
 
        $(_img).bind('load readystatechange', function(e){_checki(e);});
        _checki({type:'readystatechange'}); // bind to 'load' event...
      });
    } else _done();
  });
};

(function () {
	function popup(url, width, height, options) {
		if (!url) return false;
		var optionsDefault = {
			width : 400,
			height : 400,
			windowName : "popup",
			scrollbars : true,
			resizable : true,
			onOpen : function(w){if (w && w.focus) return w.focus();}
		}
		if (options) {
			jQuery.extend(options, optionsDefault);
		} else {
			options = optionsDefault;
		}
		var windowFeatures = [];
		if (width) {
			windowFeatures.push('width='+width);
		} else {
			windowFeatures.push('width='+options.width);
		}
		if (height) {
			windowFeatures.push('height='+height);
		} else {
			windowFeatures.push('height='+options.height);
		}
		if (options.scrollbars) {
			windowFeatures.push('scrollbars=yes');
		} else {
			windowFeatures.push('scrollbars=no');
		}
		if (options.resizable) {
			windowFeatures.push('resizable=yes');
		} else {
			windowFeatures.push('resizable=no');
		}
		w = window.open(url, options.windowName, windowFeatures);
		if (options.onOpen) {
			options.onOpen(w);
		}
		return w;
	}
	$(document).ready(function() {
		$('a[class*=popup]').click(function (e) {
			e.preventDefault();
			var a = $(this);
			var c = $(a).attr('class');
			var p = c.indexOf('popup_', 0);
			if (p != -1) {
				p += 6;
				if (c.indexOf(' ', p) != -1) {
					var d = c.substring(p, c.indexOf(' ', p));
				} else {
					var d = c.substring(p);
				}
				d = d.split('x');
				popupSized($(a).attr('href'), d[0], d[1]);
			} else {
				popup($(a).attr('href'));
			}
		});
		$('.goBack').click(function (e) {
			e.preventDefault();
			history.back();
		});
		$('.goToIndex').click(function (e) {
			e.preventDefault();
			location.href = 'index.php';
		});
		$('.windowClose').click(function (e) {
			e.preventDefault();
			window.close();
		});	
		$('.windowCloseUpdate').click(function (e) {
			e.preventDefault();
			if (window.opener) {
				window.opener.location.reload(true);
				window.close();
			}
		});
	});
})();
