var SLIDERS_EXPANDED_WIDTH = 288;
var SLIDERS_COLLAPSED_WIDTH = 133;

var Site = {
	
	start: function(){
		if ($('slider')) {
			Site.parsesliders();
			
			var sliders = $$('#slider .slider');
		}
		
		if ($('login')) {
			Site.attachLoginToggle();
		}
		
		if ($('news_bar')) {
			Site.attachNews();
		}
		
		var tooltips = new Tips($$('.tooltip'), {
			maxTitleChars: 500   //I like my captions a little long
		});
	},
	
	parsesliders: function(){
		var sliders = $$('#slider .slider');
		var fx = new Fx.Elements(sliders, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
		sliders.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), SLIDERS_EXPANDED_WIDTH]
				};
				sliders.each(function(other, j) {
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != SLIDERS_COLLAPSED_WIDTH) obj[j] = {'width': [w, SLIDERS_COLLAPSED_WIDTH]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('slider').addEvent('mouseleave', function(e){
			var obj = {};
			sliders.each(function(other, j){
				if ( other.id == 'slider_default' ) {
					obj[j] = {'width': [other.getStyle('width').toInt(), SLIDERS_EXPANDED_WIDTH]};
				} else {
					obj[j] = {'width': [other.getStyle('width').toInt(), SLIDERS_COLLAPSED_WIDTH]};
				}
			});
			fx.start(obj);
		});
	},
	
	
	attachLoginToggle: function() {
		var login = $('login');
		var login_toggle = $('login_toggle');
		var login_toggle_close = $('login_toggle_close');
		var fx = new Fx.Styles(login, {duration:500, wait:false, transition: Fx.Transitions.quadOut});
		
		login_toggle.addEvent('click', function() {
			if ( login.getStyle('top').toInt() == -70 ) {
				fx.start({ 'top': [login.getStyle('top').toInt(), -190]	});
			} else {
				fx.start({ 'top': [login.getStyle('top').toInt(), -70]	});
			}
		});
		login_toggle_close.addEvent('click', function() {
			if ( login.getStyle('top').toInt() == -70 ) {
				fx.start({ 'top': [login.getStyle('top').toInt(), -190]	});
			} else {
				fx.start({ 'top': [login.getStyle('top').toInt(), -70]	});
			}
		});
	},
	
	
	attachNews: function() {
		var TIME_PER_ITEM = 3000;
		var FADE_TIME = 800;
		var news_items = $$('#news_bar .news_item');
		var final_item = news_items.getLast();
		
		news_items.each(function(other, j) {
			other.setStyle('zIndex', 1000 - j);
			other.setStyle('display', 'none');
			var fx = new Fx.Styles(other, {duration:parseInt(FADE_TIME), transition: Fx.Transitions.quadOut});
			fx.start({
				}).chain(function() {
					other.setStyle('display', 'block');
					this.start.delay(( (TIME_PER_ITEM * j) + (FADE_TIME * (j * 2)) ), this, { 'opacity': [0,1] });
					//this.start.delay(( (TIME_PER_ITEM * j) + (FADE_TIME * (j * 2)) ), this, { 'zIndex' : 500 });
				}).chain(function() {
					this.start.delay(TIME_PER_ITEM, this, { 'opacity': [1,0] })
					//this.start.delay(TIME_PER_ITEM, this, { 'zIndex' : 10 })
				}).chain(function() {
					other.setStyle('display', 'none');
					if ( other == final_item ) {
						Site.attachNews();
					}
				});
		});
	},
	
	
	hideStates: function() {
		var state_items = $$('.location_region');
		
		state_items.each(function(other, j) {
			other.setStyle('display', 'none');
		});
	}
	
};



window.addEvent('load', Site.start);



// Current Opportunites Map stuff
var states = Array('QLD', 'NT', 'WA', 'ACT', 'TAS', 'NSW', 'SA', 'VIC');

function showLocationFrame(state) {
	for ( id in states ) {
		if ( document.getElementById('location'+states[id]) ) {
			document.getElementById('location'+states[id]).style.display = 'none';
		}
	}
	
	if ( document.getElementById('location'+state) ) {
		document.getElementById('location'+state).style.display = '';
	}
}