var current = 0;

function rotator(in_id){
	var el = $(in_id);
	var images = $$('#'+in_id+' img');
	if(images.length < 2) $$('#'+in_id+'_prev, #'+in_id+'_next').setStyle('display', 'none');
	$(in_id+'_prev').addEvent('click', function(){
		if(--current < 0){
			current = (images.length-1);
			el.setStyle('margin-left', -1 * current * 459);	
			current--;
		} 
		if(el.fx) el.fx.cancel();
		el.fx = new Fx.Tween(el, {duration: 500}).start('margin-left', el.getStyle('margin-left'), -1 * current * 459);  	
	});
	$(in_id+'_next').addEvent('click', function(){
		current++;
		if(el.fx) el.fx.cancel();
		el.fx = new Fx.Tween(el, {duration: 500, onComplete: function(){
			if(current >= images.length-1){
				current = 0; el.setStyle('margin-left', 0+'px');
			}
		}}).start('margin-left', el.getStyle('margin-left'), -1 * current * 459);  	
	});
}

function rotator_next(in_id){
	var el = $(in_id);
	var images = $$('#'+in_id+' img');
	current++;
	if(el.fx) el.fx.cancel();
	el.fx = new Fx.Tween(el, {duration: 500, onComplete: function(){
		if(current >= images.length-1){
			current = 0; el.setStyle('margin-left', 0+'px');
		}
	}}).start('margin-left', el.getStyle('margin-left'), -1 * current * 459);  	
}

function make_scrollarea(content, scrollbar, handle){
	var steps = (content.getScrollSize().y - content.getSize().y);
	if(steps > 0){
		scrollbar.removeClass('scrollcover');
		$$(scrollbar, handle).removeEvents();
		var slider = new Slider(scrollbar, handle, {	
			steps: steps,
			mode: 'vertical',
			onChange: function(step){
				content.scrollTo(0,step);
			}
		}).set(0);
		$$(content, scrollbar).removeEvents('mousewheel');
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
		scrollbar.setStyle('visibility', 'visible');
		handle.setStyle('visibility', 'visible');
	} else {
		scrollbar.setStyle('visibility', 'hidden');
		handle.setStyle('visibility', 'hidden');
	}
}

function fixpng(){
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (document.body.filters) && (version < 7)){
		var png_images = $$('.pngfix');	
		png_images.each(function(element) {
			if(!$(element).hasClass('pngfixed')){
				$(element).addClass('pngfixed');
				var img = $(element);
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.getProperty('width') + "px; height:" + img.getProperty('height') + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML					
			}
		});
	} else {
		$$('.pngfix').addClass('pngfixed');
	}
}

function init(){
	fix();
	fixpng();
	
	$$('a').addEvent('focus', function(){ this.blur(); });
	
}

function fix(){
	
}

window.addEvent('load', init);
window.addEvent('resize', fix);
