images_scroll_timer = "";
actual_wheel_action_prev = "";
actual_wheel_action = "";

function changePic(link,url){
	osszes_nagy_kep = Element.childElements($('images_act'));
	for(var i=0,a_img; a_img=osszes_nagy_kep[i++];){
		a_img.hide();
	}
	
	link_id = link.id;
	$(link_id+'_img').show();
	
	osszes_link = Element.select(link.up('div'),'.chosen');
	for(var i=0,a_link; a_link=osszes_link[i++];){
			a_link.removeClassName('chosen');
	}
	link.addClassName('chosen');
	
}

function scrollImages(move){
	
	move = parseInt(move);
	margintop = $('images_list_inner').getStyle('marginTop');
	margintop = parseInt(margintop.substr(0,margintop.length-2));
	innerheight = parseInt($('images_list_inner').offsetHeight);
	ujmargintop = margintop+move;
	if (move < 0 && margintop < 237-innerheight){
		stopImageScroll();
		return;
	}
	if (move > 0 && margintop>=0){
		stopImageScroll();
		return;
	}
	$('images_list_inner').setStyle({ marginTop: ujmargintop+'px' });
}


function stopImageScroll(){
	clearInterval(images_scroll_timer);
}


function imagesUp(){
	margintop = $('images_list_inner').getStyle('marginTop');
	margintop = margintop.substr(0,margintop.length-2);
	
	images_scroll_timer = setInterval("scrollImages(10);",50);
		
}

function imagesDown(){
	margintop = $('images_list_inner').getStyle('marginTop');
	margintop = margintop.substr(0,margintop.length-2);
	
	images_scroll_timer = setInterval("scrollImages(-10);",50);

}

function up_imagesScroll(){
	scrollImages(-5);
}

function down_imagesScroll(){
	scrollImages(5);
}

function initImages(){
	if (!$('images_list_inner')) return;
	 
	Event.observe($('images_list_inner'),'mouseover',function(event){
		actual_wheel_action_prev = actual_wheel_action;
		actual_wheel_action = "imagesScroll()";
	});
	Event.observe($('images_list_inner'),'mouseout',function(event){
		actual_wheel_action = "";
		actual_wheel_action_prev = "imagesScroll()";
	});
	
	initMouseWheel();
	
}


static_sliders = new Array();

function down_staticScroll(container,content,scroller_sorszam){
	scroll_step = 50 / $(content).offsetHeight;
	static_sliders[scroller_sorszam].setValue(static_sliders[scroller_sorszam].value-scroll_step);
}
function up_staticScroll(container,content,scroller_sorszam){
	scroll_step = 50 / $(content).offsetHeight;
	static_sliders[scroller_sorszam].setValue(static_sliders[scroller_sorszam].value+scroll_step);
}


function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}



function initScroller(container,content,scroller,handle,needsizing,onlyscroller,arany){
	if (!$(container) || !$(content)) return;

	if (needsizing){
		var cont_container = $(container).up();
		var cont_childs = cont_container.childElements();
		var cont_heights = 0;
		for(var i=0,node; node=cont_childs[i++];){
			if (node.id != $(container).id && node.tagName!='SCRIPT' && node.tagName!='script'){
				cont_heights += node.offsetHeight;
				//alert(node.tagName+' '+node.offsetHeight);
			}
		}
		//alert($(container).offsetHeight+' '+$(container).getStyle(''));
		//alert(cont_container.getStyle('paddingTop'));
		var pt = cont_container.getStyle('paddingTop');
		var pb = cont_container.getStyle('paddingBottom');
		//alert(parseInt(pt.substring(0,pt.indexOf('px')),10));
		cont_heights = cont_heights + ( parseInt(pt.substring(0,pt.indexOf('px')),10) + parseInt(pb.substring(0,pt.indexOf('px')),10));
		//alert(cont_heights);
		//alert((cont_container.offsetHeight-cont_heights)+'px');
		//alert(((cont_container.offsetHeight-cont_heights)-5)+'px');
		var cont_container_height = cont_container.offsetHeight;
		var container_new_height = cont_container_height-cont_heights;
		if (!onlyscroller){
			//alert(cont_container.className);
			//alert(cont_container.offsetHeight);
			$(container).setStyle({ height: container_new_height+'px' });
		}
		
		var scroller_new_height = ($(container).getStyle('height'));
		var container_height = parseInt(scroller_new_height.substring(0,scroller_new_height.indexOf('px')),10);
		//alert(scroller_new_height);
		$(scroller).setStyle({ height: container_height+'px' });
	}	
	
	//alert($(content).getStyle('height')+' '+$(container).getStyle('height'));
	if ($(content).offsetHeight-10 > $(container).offsetHeight){
		$(scroller).show();
	}else{
		return false;
	}
	
	var handle_h = parseInt(($(container).offsetHeight/$(content).offsetHeight)*$(container).offsetHeight,10);
	if (handle_h < 20) handle_h = 20;
	$(handle).setStyle({ height: handle_h + 'px'});
	
	//alert('container:'+$(container).offsetHeight+', content:'+$(content).offsetHeight+', scroller: '+$(scroller).style.height.replace(/px$/,"")+', handle: '+$(handle).offsetHeight);
	var len = static_sliders.length;
	static_sliders[len] = new Control.Slider($(handle),$(scroller),{
		axis:'vertical',
		onSlide: function(value){
			egesz = $(content).offsetHeight-$(container).offsetHeight;
			margintop = parseInt((egesz * value),10);
			$(content).setStyle({ marginTop: (-1)*margintop + 'px' });
		},
		onChange: function(value){
			egesz = $(content).offsetHeight-$(container).offsetHeight;
			margintop = parseInt((egesz * value),10);
			$(content).setStyle({ marginTop: (-1)*margintop + 'px' });
			//alert(static_sliders[len].maximum);
		}		
		
	});
	//alert(static_sliders[len].);
	var sorszam = static_sliders.length-1;

	
	if ($(content).offsetHeight > $(container).offsetHeight){
		Event.stopObserving($(content),'mouseover');
		Event.observe($(content),'mouseover',function(event){
			actual_wheel_action_prev = actual_wheel_action;
			actual_wheel_action = "staticScroll('"+container+"','"+content+"',"+sorszam+");";
		});
		Event.stopObserving($(content),'mouseoout');
		Event.observe($(content),'mouseout',function(event){
			actual_wheel_action = "";
			actual_wheel_action_prev = "staticScroll('"+container+"','"+content+"',"+sorszam+");";
		});
	
		initMouseWheel();
	}
	
	if (arany){
		static_sliders[sorszam].setValue(arany);
	}

	return sorszam;
}



/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta) {
	//alert(actual_wheel_action);
	if (actual_wheel_action.length > 0){
		if (delta>0){
			eval("down_"+actual_wheel_action);
		}else{
			eval("up_"+actual_wheel_action);
			
		}
		
		return true;
	}else{
		return false;
	}
	
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                ret = handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (ret){
	        if (event.preventDefault)
	                event.preventDefault();
			event.returnValue = false;
        }
}


function initMouseWheel(){
		
	/** Initialization code. 
	 * If you use your own event management code, change it as required.
	 */
	if (window.addEventListener)
	        /** DOMMouseScroll is for mozilla. */
	        window.addEventListener('DOMMouseScroll', wheel, false);
	/** IE/Opera. */
	window.onmousewheel = document.onmousewheel = wheel;

}


//Event.observe(window,'load',initScroller.bindAsEventListener(this));
//Event.observe(window,'load',initScroller2.bindAsEventListener(this));
//Event.observe(window,'load',initScroller3.bindAsEventListener(this));
//Event.observe(window,'load', initImages.bindAsEventListener(this));
//Event.observe(window,'load', initMouseWheel.bindAsEventListener(this));

