// Header Image Slider
var slidey = {
	button : null,
	leadimg : null,
	img : null,
	going : null,
	toggle : 'down',
	init : function() {
		this.button = $('caption-arrow');
		this.leadimg = $('main-image');
		this.button.addEvent('click',this.slide);
	},
	slide : function() {
		if (slidey.toggle == 'down' ) {
			slidey.animate(165,260);
			slidey.toggle = 'up';
			slidey.button.setStyle('background-position', '0 -33px');
		} else if (slidey.toggle == 'up') {
			slidey.animate(240,165);
			slidey.toggle = 'down';
			slidey.button.setStyle('background-position', '0 0');
		}
	},
	animate : function(start,end) {
		
		start = eval(start);
		end = eval(end);
		
		if (end > start ) {
			start = start + 10;
			if( start >= end ) {
				clearTimeout(slidey.going);
				start = end;
			}
		}
		
		if (start > end ) {
			start = start - 10;
			if( start <= end ) {
				clearTimeout(slidey.going);
				start = end;
			}
		}
				
		slidey.going = setTimeout("slidey.animate('" + start + "','" + end + "')",0.5);
		
		slidey.leadimg.style.height = start + 'px';
		if ( start == end ) {
			return clearTimeout(slidey.going);
		}
	}
}

// ajax load page (viewer page)
function loadPage(url,div) {
	var parent = $(div).parentNode;
	var fade = new Fx.Style(div, 'opacity', {duration:200, wait:false});
	var load = new Ajax(url, {
		method: 'get',
		evalScripts: 'true',
		update: $(div),
		onRequest: function() {
			$(div).empty();
			// set loading element class
			parent.className = 'viewer-loading';
			fade.start(0);
		},
		onComplete: function() {
			// unset loading element class
			parent.className = '';
			fade.start(1);
		}
	});
	load.request();
}

// global events
window.addEvent('domready', function(){

	/* ------ instantiate tooltips for items that have a class of 'tip' and a respective 'title' attribute ----- */
	var tip = new Tips($$('.tip'), {
		initialize:function() {
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 150, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(.9);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		},
		className: 'tooltip',
		offsets: {'x': 22, 'y': -14}
	});
	
});