/**
 * @author greg
 */

function createSlider(el){
	track_id = "track1";
	handle_id = "handle1";
		
	var slider = new Control.Slider(handle_id, track_id, {
			axis: 'vertical',
			onSlide: function(v) { scrollVertical(v, $(el), slider);  },
			onChange: function(v) { scrollVertical(v, $(el), slider); }
	});

/*	if ($(el).scrollHeight <= $(el).offsetHeight) {
			console.info("SCROLL: " + $(el).scrollHeight + " OFFSET: " + $(el).offsetHeight);
			slider.setDisabled();
			$(track_id).hide();
	} */ 
}

// scroll the element vertically based on its width and the slider maximum value
			function scrollVertical(value, element, slider) {
				element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
			}
			
			// scroll the element horizontally based on its width and the slider maximum value
			function scrollHorizontal(value, element, slider) {
				element.scrollLeft = Math.round(value/slider.maximum*(element.scrollWidth-element.offsetWidth));
			}


function addListenersToNav(){
	setDisplayToNone();
	$A([$$("div#nav-menu ul li a"), $$("div.next_link area")]).flatten().each(function(link){
		if (link.title != ""){
			Event.observe($(link), 'click', function(l){
			 createLinkEffect(link, l);
			return false;
			}); 
		}
		return false;
	});
}	

function lookForAnchor(){
	var start = document.URL.indexOf("#");
	if (start == -1){
		return false;
	}
	var anchor = document.URL.substring(start + 1, document.URL.length);
	if (anchor == "top"){
		return false;
	}
	createLinkEffect($$('a[title="' + anchor + '"]')[0], '');
	var topAnchor = $$('a[name="top"]')[0];
	$(topAnchor).scrollTo();
}

function createLinkEffect(link, el){
		hideAllItems();
		unsetCurrentMenu();
		if ($(link.title) != null) {
			Effect.Appear(link.title, {
				duration: '1'
			});
			$(link).addClassName('current-menu');
			if (link.hasClassName('next_anchor')) {
				return true;
			}
			else {
				return false;
			}
		}
	return false;
}

function unsetCurrentMenu(){
	$$("a.current-menu").each(function(link){
		link.removeClassName('current-menu');
	});
}

function setDisplayToNone(){
	$$('div.menu_item').each(function(item, index){
		if (index == 0){
			return;
		}
		item.setStyle({ display: 'none'});
		});
		
	$$('a.top_anchor').each(function(item){
		item.setStyle({display: 'none'});
	})
}

function hideAllItems(){
	$$('div.menu_item').each(function(item){
	$(item).hide();
	});
}

function resetSlider(){
	$('handle1').style.top = "0px";
}

function applyTooltips(){
        $A([$$(".bandTip"), $$('.credited_image')]).flatten().each(function(l){
            (new Tooltip(l, {
                mouseFollow: false,
                backgroundColor: '#CCCC99',
                color: '#99CCCC',
                opacity: '.90',
                htmlTitle: true,
				width: '300px'
            }));
        });
}


Event.observe(window, 'load', function(){
  applyTooltips();
  addListenersToNav();
  lookForAnchor();
});


 