var ImageFlowHelpers = {
  
    /**
    * @return object {x:NUMBER,y:NUMBER}
    */
    get_mouse_position_from_event: function(e){
        if (typeof e === "undefined"){ e = window.event;}
        if (typeof e.pageX !== "undefined"){
            return {x:e.pageX, y:e.pageY};
        } else if (typeof e.clientX !== "undefined"){
            return {x:e.clientX, y:e.clientY};
        } else if (typeof e.scrollX !== "undefined"){
            return {x:e.scrollX, y:e.scrollY};
        }    
    }
};

ImageFlow = function(custom_config){
/**
 *	ImageFlow 0.9
 *
 *	This code is based on Michael L. Perrys Cover flow in Javascript.
 *	For he wrote that "You can take this code and use it as your own" [1]
 *	this is my attempt to improve some things. Feel free to use it! If
 *	you have any questions on it leave me a message in my shoutbox [2].
 *
 *	The reflection is generated server-sided by a slightly hacked
 *	version of Richard Daveys easyreflections [3] written in PHP.
 *
 *	The mouse wheel support is an implementation of Adomas Paltanavicius
 *	JavaScript mouse wheel code [4].
 *
 *	Thanks to Stephan Droste ImageFlow is now compatible with Safari 1.x.
 *
 *
 *	[1] http://www.adventuresinsoftware.com/blog/?p=104#comment-1981
 *	[2] http://shoutbox.finnrudolph.de/
 *	[3] http://reflection.corephp.co.uk/v2.php
 *	[4] http://adomas.org/javascript-mouse-wheel/
 */
 var me = this;
 var noop = function(){};
 var config = {
   /* Configuration variables */
   reflection_p:   custom_config.reflection_p || 0.5,         // Sets the height of the reflection in % of the source image
   focus:          custom_config.focus || 4,                  // Sets the numbers of images on each side of the focussed one
   slider_width:   custom_config.slider_width || 14,          // Sets the px width of the slider div
   images_cursor:  custom_config.images_cursor || 'pointer',  // Sets the cursor type for all images default is 'default'
   slider_cursor:  custom_config.slider_cursor || 'default',  // Sets the slider cursor type: try "e-resize" default is 'default'

   /* advanced: modification of the carousel animation */
   scale_factor:   custom_config.scale_factor || 1,           // bigger numbers make the whole animation smaller
   scale_abs:      custom_config.scale_abs || false,          // very experimental abs value
   xstep:          custom_config.xstep || 150,                // 'gap' between images
   reflection_delta: custom_config.reflection_delta || 1,     // used for adjusting the vertical center of the scrolling effect

   coverflow_function: custom_config.coverflow_function || 'sqrt', // sqrt(curved coverflow) or abs(more straight)
   coverflow_function_abs: custom_config.coverflow_function_abs || 300, // 
   coverflow_function_abs_scale: custom_config.coverflow_function_abs_scale || 1, // 

   /* Id names used in the HTML */
   imageflow: custom_config.imageflow || 'imageflow',         // Default is 'imageflow'
   loading:   custom_config.loading || 'loading',             // Default is 'loading'
   images:    custom_config.images || 'images',               // Default is 'images'
   captions:  custom_config.captions || 'captions',           // Default is 'captions'
   scrollbar: custom_config.scrollbar || 'scrollbar',         // Default is 'scrollbar'
   slider:    custom_config.slider || 'slider',               // Default is 'slider'

   /* show a div overlay for center image */
   overlay:       custom_config.overlay || '',                      // Default is '' - if empty string or false no overlay is shown. if string ID of the overlay element - the overlay will be shown
   auto_display_overlay: custom_config.auto_display_overlay || false,     // default: false
   overlay_delay: custom_config.overlay_delay || 500,               //Default 500 - unit: ms - used when showing the overlay directly   
   before_show_overlay: custom_config.before_show_overlay || noop,
   
   /* callbacks */
   before_scroll_callback: custom_config.before_scroll_callback || noop, //TODO: cleanup
   after_scroll_callback:   custom_config.after_scroll_callback || noop,  //TODO: cleanup

   /* buttons */
   previous_button: custom_config.previous_button ||  'imageflowPreviousImage',
   next_button: custom_config.next_button || 'imageflowNextImage',
   
   scroll_to_middle_after_initial_display: custom_config.scroll_to_middle_after_initial_display || true,
   
   init_overlay: custom_config.init_overlay || noop

 };



/* Define global variables */
var caption_id = 0;
var new_caption_id = 0;
var current = 0;
var target = 0;
var mem_target = 0;
var timer = 0;
var array_images = [];
var new_slider_pos = 0;
var dragging = false;
var dragobject = null;
var dragx = 0;
var posx = 0;
var new_posx = 0;
var overlay_timer = null;
var overlay_original_image = null;
var overlay_element = null;
var overlay_current_image = null;
var max = 0; // will be initalized to count_images

/******
* compatibility to POJO / no-framework / jQuery?
***/
var imageflow_logger = new logger("imageflow");

var l = imageflow_logger.log;
var w = imageflow_logger.warn;
var d = imageflow_logger.debug;
var info = imageflow_logger.info;
// var l = function(){};
// var w = function(){};
//var d = function(){};
// var info = function(){};

// compat: Browser
/*
var Browser = {
  IE:     !!(window.attachEvent &&
    navigator.userAgent.indexOf('Opera') == -1),
  Opera:  navigator.userAgent.indexOf('Opera') > -1,
  WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
  Gecko:  navigator.userAgent.indexOf('Gecko') > -1 &&
    navigator.userAgent.indexOf('KHTML') == -1,
  MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
};
*/

// keep track of mouse movement within the imageflow - needed by mouseover options
var default_mouse_position = {x:0,y:0};
var current_mouse_position = default_mouse_position;
this.get_mouse_position = function(){
	return current_mouse_position;
};


document.getElementById(config.imageflow).onmousemove = function(e){
    current_mouse_position =  ImageFlowHelpers.get_mouse_position_from_event(e);
};

/*
jQuery('#'+config.imageflow).mouseleave(function(e){
    l("MOUSEOUT!! " + get_mouse_position_from_event(e).x);
    current_mouse_position = default_mouse_position;
});
*/
/*
document.getElementById(config.imageflow).onmouseout = function(e){
    l("MOUSEOUT!! " + get_mouse_position_from_event(e).x);
    //current_mouse_position = get_mouse_position_from_event(e);
};
*/
/**
subscribe_event($(config.imageflow),function(e){
	current_mouse_position = e.pointer();
	debug("new mouse pos",current_mouse_position.x,current_mouse_position.y);
},'mousemove');
**/
//pojo
function iefix(element){
  //if (Browser.IE){ warn("POJO - IMPLEMENT MAKE-POSITIONED"); }//@by torsten marek 
//	if (Prototype && Prototype.Browser.IE){ $(element).makePositioned(); }//@by torsten marek 
}

function active_image(){
	return img_div.childNodes.item(array_images[caption_id]);
}

//refactor out of here or POJO
var mouseover_toggler = null;
/***
* - checks/updates overlay_current_image
* - creates a new Overlay
**/
function show_overlay(){

	//l("[IMAGEFLOW] show_overlay", overlay_element);
	//var_dump();
/*
	if (active_image()==overlay_current_image){
		d("[IMAGEFLOW] current_image==overlay_current_image");
		return;
	}
	overlay_current_image = active_image();
  */
  if (overlay_element){ 
    
    if (typeof config.before_show_overlay == 'function'){
      config.before_show_overlay(overlay_element, active_image(), me.get_mouse_position);
    }    
    
    if (config.auto_display_overlay === true){
      //w("auto_display_overlay", overlay_element);
      overlay_element.style.display = 'block';
    }
  }

  if (typeof config.after_scroll_callback == 'function'){
    config.after_scroll_callback(overlay_element, active_image(), me.get_mouse_position);
  }
  
  /*
    var current_overlay = new Template('<div id="#{id}" class="imageflow-active-image-overlay" style="position:absolute; z-index:1000;display:none">#{inner_template}</div>');
	var current_image_object = parse_cmyc_attrib(overlay_current_image);

	var temp = current_overlay.evaluate({
		id: config.overlay,
		inner_template: evaltemplate_imageflow(current_image_object)
	});
	temp = new Insertion.After(
		$$('#images').first(), temp);
	config.after_scroll_callback(config.overlay, current_image_object);

	overlay_element = $(config.overlay);
	//iefix( overlay_element );

	Element.clonePosition(config.overlay, overlay_current_image,{
		setLeft: true,//
		setTop: true,
		setWidth: true,
		setHeight: true
	});

	overlay_element.setStyle({'width': parseInt(overlay_element.getWidth()+1,10) + "px"});
	d("[IMAGEFLOW] current_image=",current_image);
	*/
	/***
	* @comment : 1.8.2008 changed the behaviour, so that the options are not show
 	* immediately but on mouseover - thats the div_toggler
 	* old behaviour was showing the options after a short delay.
 	* if you want to switch back to the old behaviour, comment the next lines and 
 	* use overlay_element.show(); instead + set a small timeout above in var config.overlay_delay ...
	**/
  // if (mouseover_toggler instanceof Cmyc.behaviour.div_toggler.mouseover){ mouseover_toggler.destroy(); }
  // mouseover_toggler = new Cmyc.behaviour.div_toggler.mouseover(active_image(), get_mouse_position);

  // overlay_element.show(); - old behaviour see comment

}

/**
* clears timer and removes the overlay element
* @see comment below where called!!!
*/
function reset_overlay(){
	if (!config.overlay){ return; }
	
	d("[IMAGEFLOW] reset_overlay", overlay_timer);
	if (overlay_timer){
		d("[IMAGEFLOW] reset_overlay:clearing timeout");
		window.clearTimeout(overlay_timer);
		overlay_timer = null;
	}
	if (overlay_element && overlay_element.style.display !=='none'){
		d("[IMAGEFLOW] reset_overlay: hiding overlay_element");
    overlay_element.style.display = 'none';
	}
}

function init_overlay(){
  if (!config.overlay){ return; }
//  console.log("init_overlay");
	d("[IMAGEFLOW] ______init_overlay");
	if (config.overlay_delay>0){
		if (overlay_timer){
			// fix for IE, who starts 2x in the beginning
			window.clearTimeout(overlay_timer);
		}
		overlay_timer = window.setTimeout(show_overlay,config.overlay_delay);
	} else {
		show_overlay();
	}
	d("[IMAGEFLOW] overlay_timer");
	d(overlay_timer);
}

function step()
{
  // d("[IMAGEFLOW] step", target, current);
	switch (target < current-1 || target > current+1)
	{
		case true:
			moveTo(current + (target-current)/3);
			window.setTimeout(step, 50);
			timer = 1;
			break;

		default:
      // d("[IMAGEFLOW] target-current-timer",target,current,timer);
			init_overlay();
			timer = 0;
			break;
	}
}

function glideTo(x, new_caption_id)
{
	d("[IMAGEFLOW] glideTo", arguments);
	if (typeof config.before_scroll_callback =="function"){ 
	  config.before_scroll_callback(overlay_element, active_image()); 
	}
	
	/* Animate gliding to new x position */
	target = x;
	mem_target = x;
	if (timer == 0)
	{
		d("[IMAGEFLOW] glideTo: setting timeout for step");
		reset_overlay();
		window.setTimeout(step, 50);
		timer = 1;
	}
	d("[IMAGEFLOW] glideTo: step finished");
	/* Display new caption */

	d("_display new caption...");
	caption_id = new_caption_id;
	caption = img_div.childNodes.item(array_images[caption_id]).getAttribute('alt');
	d(caption);
	d(caption_div);
	if (caption == ''){ caption = '&nbsp;'; }
	caption_div.innerHTML = caption;


	/* Set scrollbar slider to new position */
	if (dragging == false)
	{
		if(new_slider_pos = (scrollbar_width * (-(x*100/((max-1)*config.xstep))) / 100) - new_posx){
			slider_div.style.marginLeft = (new_slider_pos - config.slider_width) + 'px';
		}
	}
}

function moveTo(x)
{
  // d("[IMAGEFLOW] moveTo", arguments);
	current = x;
	var zIndex = max;

	/* Main loop */
	for (var index = 0; index < max; index++)
	{
		var image = img_div.childNodes.item(array_images[index]);
		var current_image = index * -config.xstep;

		/* Don't display images that are not max_focus */
		if ((current_image+max_focus) < mem_target || (current_image-max_focus) > mem_target)
		{
			image.style.visibility = 'hidden';
			image.style.display = 'none';
		}
		else
		{
      // d("[IMAGEFLOW] _display");     
			var dummy = 10000 * config.scale_factor;
            var dummy2;
			if (parseFloat(config.scale_abs,10) > 0){
			    dummy2 = config.scale_abs;
			} else {
			    dummy2 = Math.sqrt(dummy);
			}
			var z;
			
			//dummy = 10000;
			if (config.coverflow_function == 'sqrt'){
			    z = Math.sqrt(dummy + x * x) + dummy2 ;// before: Math.sqrt(10000 + x * x) + 100 ;    
			}
			if (config.coverflow_function == 'abs'){
			    z = Math.abs( config.coverflow_function_abs_scale * x) + config.coverflow_function_abs;
			}
			
			//  var z = x ;// before: Math.sqrt(10000 + x * x) + 100 ;

//z = Math.sqrt(dummy + x * x);

			var xs = x / z * size + size;

//w("moveTo ", x, xs, z);

			/* Still hide images until they are processed, but set display style to block */
			image.style.display = 'block';

			/* Process new image height and image width */
			var new_img_h = (image.h / image.w * image.pc) / z * size;
      // d("[IMAGEFLOW] _x",new_img_h,image.h);
			switch ( new_img_h > max_height )
			{
				case false:
					var new_img_w = image.pc / z * size;
					break;

				default:
					new_img_h = max_height;
					var new_img_w = image.w * new_img_h / image.h;
					break;
			}
			var new_img_top = (images_width * 0.34 - new_img_h) + images_top + ((new_img_h / (config.reflection_p + config.reflection_delta )) * config.reflection_p);

			/* Set new image properties */
			image.style.left = xs - (image.pc / 2) / z * size + images_left + 'px';
			if(new_img_w && new_img_h)
			{
				image.style.height = new_img_h + 'px';
				image.style.width = new_img_w + 'px';
				image.style.top = new_img_top + 'px';
        // d("[IMAGEFLOW] debug",new_img_h,new_img_w,new_img_top,image.style);
			}
			image.style.visibility = 'visible';

			/* Set image layer through zIndex */
			switch ( x < 0 )
			{
				case true:
					zIndex++;
					break;

				default:
					zIndex = zIndex - 1;
					break;
			}

			/* Change zIndex and onclick function of the focussed image */
			switch ( image.i == caption_id )
			{
				case false:
					image.onclick = function() { glideTo(this.x_pos, this.i); };
					break;

				default:
					zIndex = zIndex + 1;
					image.onclick = function() { /*document.location = this.url;*/ };
					break;
			}
			image.style.zIndex = zIndex;
		}
		x += config.xstep;
	}
}

/* Main function */
function refresh(onload)
{
d("[IMAGEFLOW] _refresh",arguments);

	/* Cache document objects in global variables */
	imageflow_div = document.getElementById(config.imageflow);
	img_div = document.getElementById(config.images);
	scrollbar_div = document.getElementById(config.scrollbar);
	slider_div = document.getElementById(config.slider);
	caption_div = document.getElementById(config.captions);
  overlay_element = config.overlay?document.getElementById(config.overlay):null;

	/* Cache global variables, that only change on refresh */
	images_width = img_div.offsetWidth;
	images_top = imageflow_div.offsetTop;
	//w("images_top",images_top);
	images_left = imageflow_div.offsetLeft;
	max_focus = config.focus * config.xstep;
	size = images_width * 0.5;
	scrollbar_width = images_width * 0.6;
	config.slider_width = config.slider_width * 0.5;
	max_height = images_width * 0.51;

	/* Change imageflow div properties */
	imageflow_div.style.height = max_height + 'px';

	/* Change images div properties */
	img_div.style.height = images_width * 0.338 + 'px';

	/* Change captions div properties */
	caption_div.style.width = images_width + 'px';
	caption_div.style.marginTop = images_width * 0.03 + 'px';

	/* Change scrollbar div properties */
	scrollbar_div.style.marginTop = images_width * 0.02 + 'px';
	scrollbar_div.style.marginLeft = images_width * 0.2 + 'px';
	scrollbar_div.style.width = scrollbar_width + 'px';

	/* Set slider attributes */
	slider_div.onmousedown = function () { dragstart(this); };
	slider_div.style.cursor = config.slider_cursor;

	/* Cache EVERYTHING! */
	max = img_div.childNodes.length;
	var i = 0;
	for (var index = 0; index < max; index++)
	{
		var image = img_div.childNodes.item(index);
		if (image.nodeType == 1)
		{
			array_images[i] = index;

			/* Set image onclick by adding i and x_pos as attributes! */
			image.onclick = function() { glideTo(this.x_pos, this.i); };
			image.x_pos = (-i * config.xstep);
			image.i = i;

			/* Add width and height as attributes ONLY once onload */
			if(onload === true)
			{
				image.w = image.width || image.getAttribute("width");
				image.h = image.height || image.getAttribute("height");

				//d("[IMAGEFLOW] _y",image.h);
			}
			/* Check source image format. Get image height minus reflection height! */
			switch ((image.w + 1) > (image.h / (config.reflection_p + 1)))
			{
				/* Landscape format */
				case true:
					image.pc = 118;
					break;

				/* Portrait and square format */
				default:
					image.pc = 100;
					break;
			}

			/* Set ondblclick event */
			//image.url = image.getAttribute('longdesc');
			//image.ondblclick = function() { document.location = this.url; }

			/* Set image cursor type */
			image.style.cursor = config.images_cursor;

			i++;
		}
	}
	max = array_images.length;
	d("[IMAGEFLOW] _array_images",array_images);
	/* Display images in current order */
	moveTo(current);
	d("[IMAGEFLOW] refresh calling glideto");
	glideTo(current, caption_id);
}

/* Show/hide element functions */
function show(id)
{
	var element = document.getElementById(id);
	element.style.visibility = 'visible';
	element.style.display = 'block';
}
function hide(id)
{
	var element = document.getElementById(id);
	element.style.visibility = 'hidden';
	element.style.display = 'none';
}

/* Hide loading bar, show content and initialize mouse event listening after loading */
var init = function(){//@by torsten marek
	//l("[IMAGEFLOW] init called");
	if(document.getElementById(config.imageflow))
	{
		//hide(config.loading);

		iefix('images');//@by torsten marek
		refresh(true);
		//show(config.images);
		show(config.scrollbar);
		initMouseWheel();
		initMouseDrag();

		registerButtons();
		if (typeof config.init_overlay == "function"){
		    config.init_overlay(document.getElementById(config.overlay));
		}
		if (config.scroll_to_middle_after_initial_display){
		    var next_delta = - parseInt(max/2,10);
		    //w("scroll_to_middle_after_initial_display", next_delta, max);
		    scrollRelative(next_delta);
		}
		
		document.getElementById(config.imageflow).focus();		
//		var_dump();
	}

};

//window.onload = init;
init();
/* Refresh ImageFlow on window resize */
window.onresize = function(event)
{
	/**
	* @comment resize fires in IE very often!
	* we need another way to avoid douplicate calls
	* TODO: re-enable and find a work-around for IE
	**/
	/*
	if (Prototype.Browser.IE) return;	// TODO!! re-enable resize event
	d("[IMAGEFLOW] xxxonresize");
	if(document.getElementById(config.imageflow)){
		d("[IMAGEFLOW] xxxresize event");
		refresh();
		ignore_onload=false;
	}
	 */
};

/* Fixes the back button issue */
window.onunload = function()
{
  try{document = null;} catch(err){}
};


/* Handle the wheel angle change (delta) of the mouse wheel */
function handle(delta)
{
	var change = false;
	switch (delta > 0)
	{
		case true:
			if(caption_id >= 1)
			{
				target = target + config.xstep;
				new_caption_id = caption_id - 1;
				change = true;
			}
			break;

		default:
			if(caption_id < (max-1))
			{
				target = target - config.xstep;
				new_caption_id = caption_id + 1;
				change = true;
			}
			break;
	}

	/* Glide to next (mouse wheel down) / previous (mouse wheel up) image */
	if (change === true)
	{
		d("[IMAGEFLOW] mouse wheel change calling glideto");//WWWWW
		glideTo(target, new_caption_id);
	}
}

/* Event handler for mouse wheel event */
function wheel(event)
{
	var delta = 0;
	if (!event){ event = window.event; }
	if (event.wheelDelta)
	{
		delta = event.wheelDelta / 120;
	}
	else if (event.detail)
	{
		delta = -event.detail / 3;
	}
	if (delta){ handle(delta); }
	if (event.preventDefault){ event.preventDefault(); }
	event.returnValue = false;
}

/* Initialize mouse wheel event listener */
function initMouseWheel()
{
	if(window.addEventListener){ imageflow_div.addEventListener('DOMMouseScroll', wheel, false); }
	imageflow_div.onmousewheel = wheel;
}

/* This function is called to drag an object (= slider div) */
function dragstart(element)
{
	dragobject = element;
	dragx = posx - dragobject.offsetLeft + new_slider_pos;
}

/* This function is called to stop dragging an object */
function dragstop()
{
	dragobject = null;
	dragging = false;
}

/* This function is called on mouse movement and moves an object (= slider div) on user action */
function drag(e)
{
	posx = document.all ? window.event.clientX : e.pageX;
	if(dragobject !== null)
	{
		dragging = true;
		new_posx = (posx - dragx) + config.slider_width;

		/* Make sure, that the slider is moved in proper relation to previous movements by the glideTo function */
		if(new_posx < ( - new_slider_pos)){ new_posx = - new_slider_pos; }
		if(new_posx > (scrollbar_width - new_slider_pos)){ new_posx = scrollbar_width - new_slider_pos; }

		var slider_pos = (new_posx + new_slider_pos);
		var step_width = slider_pos / ((scrollbar_width) / (max-1));
		var image_number = Math.round(step_width);
		var new_target = (image_number) * -config.xstep;
		var new_caption_id = image_number;

		dragobject.style.left = new_posx + 'px';
		d("[IMAGEFLOW] drag glide calling glideto");
		glideTo(new_target, new_caption_id);
	}
}

/* Initialize mouse event listener */
function initMouseDrag()
{
	document.onmousemove = drag;
	document.onmouseup = dragstop;

	/* Avoid text and image selection while dragging  */
	document.onselectstart = function ()
	{
		if (dragging === true)
		{
			return false;
		}
		else
		{
			return true;
		}
	};
}

function getKeyCode(event)
{
	event = event || window.event;
	return event.keyCode;
}

document.onkeydown = function(event)
{
	var charCode  = getKeyCode(event);
	switch (charCode)
	{
		/* Right arrow key */
		case 39:
			handle(-1);
			break;

		/* Left arrow key */
		case 37:
			handle(1);
			break;
	}
};


/**
* scrolls relative to the current position
* @author torsten marek
*/
function scrollRelative(delta){
	/**
	* @comment max is the number of elements in the scroller
	* @comment caption_id is the currently active array_index (0..max-1)
	*/
//l("scrollRelative");
	var change = false;
	if (delta > 0){
		delta = Math.min(caption_id, delta);
		if(caption_id >= 1){
			target = target + (config.xstep*delta);
			new_caption_id = caption_id - delta;
			change = true;
		}
	} else {
		delta = Math.max(-(max-1-caption_id),delta);
		if(caption_id < (max-1)){
			target = target + (config.xstep*delta);
			new_caption_id = caption_id - delta;
			change = true;
		}
	}
	if (change === true){
		d("[IMAGEFLOW] scrollRelative calling glideto");
		glideTo(target, new_caption_id);
	}
}

function registerButtons(){
	var delta = 1;
	var temp = null;
	
	temp = document.getElementById(config.previous_button);
	if (temp){
		temp.onclick = function(){
			d("[IMAGEFLOW] click prev");
			scrollRelative(delta);
		};
	}
	temp = document.getElementById(config.next_button);
	if (temp){
		temp.onclick = function(){
			d("[IMAGEFLOW] click next");
			// START SCROLL EFFECT 1 WWWWW
			scrollRelative(-delta);
		};
	}
}
/**
* helper function
*/
function var_dump(){
	/*
	d("[IMAGEFLOW] slider-vars: current,posx,new_posx,caption_id,new_slider_pos,new_caption_id,max,target");
	d(current,posx,new_posx,caption_id,new_slider_pos,new_caption_id,max,target);
	d("[IMAGEFLOW] slider-vars:array_images",array_images);
	*/
	w("DUMP",config);
	w("images_width",images_width);
	w("images_top",  images_top);
	w("images_left", images_left);
	w("max_focus",max_focus);
	w("size",        size);
	w("scrollbar_width", scrollbar_width);
	w("config.slider_width", config.slider_width);
	w("max_height",  max_height); 
}

//window.onload = init;
var startup_timer = null;

// pojo + refactor!
this.start_wait_for_images = function(){
	d("[IMAGEFLOW] waitforImages");
	var test = false;
	test = $$('#imageflow #images IMG').find(function(img){
		return !img.complete;//complete;
	});

	if (test){
		d("[IMAGEFLOW] setting timeout, cauze img not loaded",test);
		startup_timer = window.setTimeout(me.start_wait_for_images,100);
	} else {
		d("[IMAGEFLOW] all images loaded");
		if (startup_timer){ window.clearTimeout(startup_timer); }
		d("[IMAGEFLOW] calling init");
		init();
	}
};

};
