eldridge_park = function(){};

eldridge_park.mixin = function(){
	var ret = {};
	dojo.forEach(arguments, function(item, i){
		ret = dojo.mixin(ret, item);
	});
	return ret;
}

dojo.declare("eldridge_park.nav", null, {
	nav_class: "ep_nav",
	navitem_class: "ep_navitem",
	nav_style: {},
	item_style: {},
	item_active_style: {},
	item_hover_style: {},
	nav_base_style: {},
	item_base_style: {},
	item_active_base_style: {},
	item_hover_base_style: {},
	pause_on_nav: false,
	constructor: function(opts){
		if (typeof opts == 'undefined'){
			opts = {};
		}
		dojo.mixin(this, opts);
		this.nav_style = eldridge_park.mixin(this.nav_base_style, this.nav_style);
		this.item_style = eldridge_park.mixin(this.item_base_style, this.item_style);
		this.item_active_style = eldridge_park.mixin(this.item_active_base_style, this.item_active_style);
		this.item_hover_style = eldridge_park.mixin(this.item_hover_base_style, this.item_hover_style);
		this._items = [];
		this.addNav();
		this.len = 0;
		this.carousel = null;
		this.curr = null;
	},
	addNav: function(element){
		dojo.addClass(element, this.nav_class);
		dojo.style(element, this.nav_style);
		this.nav = element;
	},
	addItem: function(idx, element){
		dojo.addClass(element, this.navitem_class);
		dojo.connect(element, "onclick", this, function(e){this.onClick(idx);});
		dojo.connect(element, "onmouseover", this, function(e){
			if (idx != this.curr){
				this.onHover(element);
			}
		});
		dojo.connect(element, "onmouseout", this, function(e){
			if (idx != this.curr){
				this.onUnHover(element);
			}
		});
		this.onUnHover(element);
		dojo.place(element, this.nav);
		this._items[idx] = element;
		this.len++;
	},
	onClick: function(idx){
		this.jumpTo(idx);
		this.carousel.fadeTo(idx);
		if (this.pause_on_nav){
			this.carousel.stop();
		}
	},
	onActive: function(element){
		dojo.style(element, this.item_active_style);
	},
	onHover: function(element){
		dojo.style(element, this.item_hover_style);
	},
	onUnHover: function(element){
		dojo.style(element, this.item_style);
	},
	jumpTo: function(idx){
		var items = this.items();
		var top_item = items.splice(idx, 1);
		this.curr = idx;
		this.onActive(top_item[0]);
		dojo.forEach(items, function(e){
			this.onUnHover(e);
		}, this);
	},
	items: function(){
		return dojo.mixin([], this._items);
	},
	THEEND: function(){}
});

dojo.declare("eldridge_park.block_nav", eldridge_park.nav, {
	nav_base_style: {
		'position': 'absolute',
		'left': '10px',
		'bottom': '10px',
		'height':'30px',
		'zIndex':100
	},
	item_base_style: {
		'float': 'left',
		'border': '1px solid #666',
		'height': '30px',
		'width': '30px',
		'backgroundColor': '#333',
		'marginRight': '5px',
		'cursor': 'pointer'
	},
	item_hover_base_style: {
		'backgroundColor':'#666'
	},
	item_active_base_style: {
		'backgroundColor':'#999'
	},
	constructor: function(opts){
	},
	addNav: function(){
		var i = dojo.create("div");
		this.inherited(arguments, [i]);
	},
	addItem: function(idx, element){
		var i = dojo.create("div");
		this.inherited(arguments, [idx, i]);
	},
	THEEND: function(){}
});

dojo.declare("eldridge_park.char_nav", eldridge_park.nav, {
	nav_base_style: {
		'position': 'absolute',
		'left': '10px',
		'bottom': '0px',
		'height':'30px',
		'zIndex':100
	},
	item_base_style: {
		'float': 'left',
		'color': '#666',
		'fontSize': '30px',
		'lineHeight': '1px',
		'marginRight': '5px',
		'cursor': 'pointer'
	},
	item_hover_base_style: {
		'color':'#999'
	},
	item_active_base_style: {
		'color':'#aaa'
	},
	item_text: "<p>&bull;</p>",
	constructor: function(opts){
	},
	addNav: function(){
		var i = dojo.create("div");
		this.inherited(arguments, [i]);

		var next = dojo.create("div");
		this.setStyle(next);
		dojo.connect(next, "onclick", this, function(e){this.onClick(idx);});

		var prev = dojo.create("div");
		this.setStyle(prev);
		dojo.connect(prev, "onclick", this, function(e){this.onClick(idx);});
	},
	setStyle: function(element){
		dojo.addClass(element, this.navitem_class);
		dojo.connect(element, "onmouseover", this, function(e){
			this.onHover(e);
		});
		dojo.connect(element, "onmouseout", this, function(e){
			this.onUnHover(e);
		});
		this.onUnHover(element);
		dojo.place(element, this.nav);
	},
	addItem: function(idx, element){
		this.len++;
	},
	THEEND: function(){}
});

dojo.declare("eldridge_park.arrow_nav", eldridge_park.nav, {
	nav_base_style: {
		'position': 'absolute',
		'left': '10px',
		'bottom': '10px',
		'height':'30px',
		'zIndex':100
	},
	item_base_style: {
		'float': 'left',
		'border': '1px solid #666',
		'height': '30px',
		'width': '30px',
		'backgroundColor': '#333',
		'marginRight': '5px',
		'cursor': 'pointer'
	},
	item_hover_base_style: {
		'backgroundColor':'#666'
	},
	item_active_base_style: {
		'backgroundColor':'#999'
	},
	constructor: function(opts){
	},
	addNav: function(){
		var i = dojo.create("div");
		this.inherited(arguments, [i]);
	},
	addItem: function(idx, element){
		var i = dojo.create("div");
		this.inherited(arguments, [idx, i]);
	},
	THEEND: function(){}
});

dojo.declare("eldridge_park.carousel", null, {
	item_selector: ".ep_item",
	overlay_selector: ".ep_overlay",
	item_style: {
		display: "block",
		position: "absolute",
		top: "0px",
		left: "0px"
	},
	slow_dur: 500,
	quick_dur: 100,
	wait_dur: 3000,
	nav_z: 15,
	raised_z: 10,
	lowered_z: 5,
	height: 800,
	width: 300,
	constructor: function(root, opts){
		var that = this;
		if (typeof opts == 'undefined'){
			opts = {};
		}
		dojo.safeMixin(this, opts);
		this.root = dojo.query(root)[0];
		if (typeof this.root == "undefined"){
			return;
		}
		this.overlay = dojo.query(this.overlay_selector, this.root)[0];
		this._items = dojo.query(this.item_selector, this.overlay);
		this.len = this._items.length;
		if (this.len <= 1){
			return;
		}
		dojo.style(this.root, {
			position: "relative",
			width: this.width + "px",
			height: this.height + "px"
		});
		dojo.style(this.overlay, {
			width: this.width + "px",
			height: this.height + "px"
		});
		dojo.forEach(this.navigation, function(nav){
			dojo.style(nav.nav, 'z-index', that.nav_z);
			nav.carousel = that;
			dojo.place(nav.nav, that.root);
		});
		this.curr = null;
		this.move = null;
		this.timeout = null;
		this.makeEntries();
		this.setTimer(0);
	},
	items: function(){
		return dojo.mixin([], this._items);
	},
	makeEntries: function(){
		var u = dojo.create("ul", {}, this.nav);
		this.items().forEach(
			function(entry, i){
				dojo.style(entry, this.item_style);
				dojo.forEach(this.navigation, function(nav){
					nav.addItem(i, entry);
				});
			}, this
		);
	},
	lower: function(e){
		dojo.style(e, "zIndex", this.lowered_z);
	},
	raise: function(e){
		dojo.style(e, "zIndex", this.raised_z);
	},
	setFull: function(e){
		dojo.style(e, "opacity", "1.0");
	},
	setClear: function(e){
		dojo.style(e, "opacity", "0.0");
	},
	fadeOut: function(e, dur){
		dojo.fadeOut({
			node: e,
			duration: dur,
		}).play();
	},
	jumpTo: function(n){
		var items = this.items();
		var top_item = items.splice(n, 1);
		this.raise(top_item[0]);
		this.setFull(top_item[0]);
		dojo.forEach(items, function(e){
			this.lower(e);
			this.setClear(e);
		}, this);
		this.curr = n;
		this.move = null;
	},
	fadeTo: function(i, dur){
		var items = this.items();
		var top_item = items.splice(i, 1);
		this.move = i;
		this.clearTimer();
		this.setClear(top_item[0]);
		this.raise(top_item[0]);
		dojo.forEach(items, function(e){
			this.lower(e);
			dojo.fadeOut({
				node: e,
				duration: dur
			}).play();
		}, this);
		dojo.fadeIn({
			node: top_item[0],
			duration: dur,
			onEnd: dojo.hitch(this, "setTimer", i)
		}).play();
	},
	stop: function(){
		this.clearTimer();
	},
	clearTimer: function(){
		if (this.timeout != null){
			clearTimeout(this.timeout);
		}
	},
	setTimer: function(i){
		var that = this;
		this.curr = i;
		this.clearTimer();
		this.jumpTo(this.curr);
		dojo.forEach(this.navigation, function(nav){
			nav.jumpTo(that.curr);
		});
		this.timeout = setTimeout(dojo.hitch(this, "goNext"), this.wait_dur);
	},
	goNext: function(){
		var i = this.curr + 1;
		if (i >= this.len){
			i = 0;
		}
		this.fadeTo(i, this.slow_dur);
	},
	browseTo: function(e){
		if (e == this.move || e == this.curr){
			return;
		}
		this.fadeTo(e, this.quick_dur);
	},
	THEEND: function(){}
});

