//
// define scripts to be loaded, waiting for 'func' to exist before next is loaded
//
var scripts=[
  {name: '/scripts/jquery.js',       func: 'jQuery' },
  {name: '/scripts/lightbox.js',     func: 'jQuery.fn.lightBox'},
  {name: '/scripts/autocolumn.js',     func: 'jQuery.fn.columnize'}
];

//
// Import a javascript file
//
function import_js(jsFile) {
	var head = document.getElementsByTagName("head")[0] || document.documentElement,
		script = document.createElement("script");
	script.type = "text/javascript";
  script.src = jsFile;
	// Use insertBefore instead of appendChild  to circumvent an IE6 bug.
	// This arises when a base node is used (#2709).
	head.insertBefore( script, head.firstChild );
	//head.removeChild( script ); //not good for IE and opera!

  // wait till loaded, than load next
  setTimeout(js_loaded, 0);
}
//
// wait till javascript loaded, than load next
//
var js_loadcount;
var cur_script;
function js_loaded() {
//geht nicht in IE oder opera:
//  if (cur_script && typeof(eval(cur_script.func))=='undefined') {
  var f;
  try { f=eval("window."+cur_script.func); } catch(e) { f=false; }
  if (cur_script && !f) {
    if (js_loadcount++<=10) {
      setTimeout(js_loaded, 100);  //wait some more, max 10 times
      return;
    }
//alert(cur_script.name+' not loaded');
  }
  cur_script=scripts.shift();
  if (cur_script) {
    js_loadcount=0;
    import_js(cur_script.name);
  } else
    all_loaded();
}
//
// start loading javascript
js_loaded();

//////////////////////////////////////////////////////////////////////////////////
// All javascripts are loaded now
//
function all_loaded() {
  $(document).ready(function() {

    //
    // Die Bilder in den Bildboxen mit Bildunterschrift
    //
    $('a.lightbox').lightBox({
      singleImage:      true, //patched!
      davbs:            false, //patched!
      maxWidth:         -1000,  //patched! <0: fit to page to this max
      maxHeight:        -1000,  //patched!

  		fixedNavigation:		true,
    	overlayBgColor: '#ccc',
    	overlayOpacity: 0.8,
  		imageLoading:			'/scripts/images/lightbox-ico-loading.gif',
  //			imageBtnPrev:			'/scripts/images/lightbox-btn-prev.gif',
  //			imageBtnNext:			'/scripts/images/lightbox-btn-next.gif',
  //			imageBtnClose:		'/scripts/images/lightbox-btn-close.gif',
  		imageBtnPrev:			'/scripts/images/prev.png',
  		imageBtnNext:			'/scripts/images/next.png',
  		imageBtnClose:		'/scripts/images/close.gif',
  		imageBlank:				'/scripts/images/lightbox-blank.gif',
    	containerResizeSpeed: 350,
    	txtImage: 'Bild',
    	txtOf: 'von'
    });


  });
  if (window.iffLoaded) iffLoaded();
};
