document.getElementsByClassName = function (needle) {
    var s = document.getElementsByTagName('*'), i = s.length, r = [], e, c;
    needle = ' ' + needle + ' ';
    while (i--) {
        e = s.item(i);
        if (e.className) {
            c = ' ' + e.className + ' ';
            if (c.indexOf(needle) != -1) r.push(e);
        }
    }
    return r;
}
var hover;
var fwd = true;
window.addEvent('domready', function() {
	
	if($('scroller') != undefined){
		var scroller = new Fx.Scroll('scroller', {
			wait: false,
			duration: 500,
			transition: Fx.Transitions.Quad.easeInOut
		});
		$('scroller').scrollTop = scrollCount;
		
		$('scroll_up').addEvent('click', function(event) {
			scrollCount = scrollCount - 42;
			if(scrollCount < 0) scrollCount = 0;
			event = new Event(event).stop();
			scroller.scrollTo(0,(scrollCount));
		});
		
		$('scroll_down').addEvent('click', function(event) {
			scrollCount = scrollCount + 42;	
			var dimensions = $('scroller').getSize();
			var maxScroll = dimensions['scrollSize']['y'] - dimensions['size']['y'];
			if(scrollCount > maxScroll) scrollCount = maxScroll;
			event = new Event(event).stop();
			scroller.scrollTo(0,(scrollCount));
		});
	}
	/*
	var hover = new Fx.Scroll('hover_wrapper', {
		wait: false,
		duration: 500,
		transition: Fx.Transitions.Quad.easeInOut
	});
	

	var  i = 0;
	var elem = $('navbutton_'+i);
	var scrollPosition = 348;
	while ( elem != null){
		elem.addEvent('mouseover', function(event) {
			event = new Event(event).stop();
			if(this.className != "disabled"){
				hover.scrollTo(0,this.scrollPosition);
			}
		});
		elem.addEvent('mouseout', function(event) {
			event = new Event(event).stop();
			hover.scrollTo(0,400);
		});
		elem.scrollPosition = scrollPosition - 30*i;
		i++;	
		elem = $('navbutton_'+i);
	}
	*/
	if($('black') != null){
		$('black').style.width = window.getScrollWidth() + "px";
		$('black').style.height = window.getScrollHeight() + "px";
		
		window.addEvent('resize', function(){
			$('black').style.width = window.getWidth() + "px";
			$('black').style.height = window.getHeight() + "px";
			$('black').style.width = window.getScrollWidth() + "px";
			$('black').style.height = window.getScrollHeight() + "px";	
			
			//$('nuformer').style.marginTop = window.getScrollHeight() + "px";
		});
	}

	if($('profile_gallery_wrapper') != null){
		var profileScrollCount = 0;
		var profileScroll = new Fx.Scroll('profile_gallery_wrapper', {
			wait: false,
			duration: 1000,
			transition: Fx.Transitions.Quad.easeInOut
		});
		
		this.scrollNext = function () {
			if(fwd){ profileScrollCount += 144;	
			} else { profileScrollCount -= 144; }
	
			if(profileScrollCount > 286){ fwd = false; }
			if(profileScrollCount < 2){ fwd = true; }
	
							 
			var dimensions = $('profile_gallery_wrapper').getSize();
			var maxScroll = dimensions['scrollSize']['x'] - dimensions['size']['x'];
			if(profileScrollCount > maxScroll) profileScrollCount = maxScroll;										 
													 
			profileScroll.scrollTo(profileScrollCount,0);
		};
		this.setInterval('scrollNext()', 5000);
	}

});

function openItem(page,collection,itemname){
	window.location.href = '?page='+page+'&collection='+collection+'&item='+itemname+'&pos='+scrollCount;
}

function setScroll(){
	//window.location='#bottom';
}

function showBig(image,url){
	if(url != null){
		$('moreInfo').style.display = '';
		$('moreInfo').href = url;
	} else {
		$('moreInfo').style.display = 'none';
	}
	$('black').style.display = '';
}

function closeBig(image){
	$('black').style.display = 'none';
}

function atelier(target){
	var atelier_items = document.getElementsByClassName('atelier mouseover');
	var i = 0;
	while (i < atelier_items.length){
		if('atelier_'+target == atelier_items[i].id){
			atelier_items[i].style.display = "";
		} else {
			atelier_items[i].style.display = "none";
		}
		i++;	
	}
}


