sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
var PortfolioItem = {

	upload: function() {
		$('loading').show();
		$('portfolio_item').submit();
	},

	finish: function(url) {
		new Ajax.Updater('portfolio_item', url, {method:'get', onComplete:function(){
			$('loading').hide();
			$('portfolio_item_upload').reset();
		}});
	},

	show: function(url) {
		$('portfolio_item').src = url;
		$('mask').show();
		$('portfolio_item_wrapper').visualEffect('appear', {duration:0.5});
	},

	hide: function() {
		$('mask').hide();
		$('portfolio_item_wrapper').visualEffect('fade', {duration:0.5});
	},

	currentIndex: function() {
		return this.urls().indexOf($('portfolio_item').src);
	},

	prev: function() {
		if(this.urls()[this.currentIndex()-1]) {
			this.show(this.urls()[this.currentIndex()-1])
		}
	},

	next: function() {
		if(this.urls()[this.currentIndex()+1]) {
			this.show(this.urls()[this.currentIndex()+1])
		}
	},

	urls: function() {
    if (!this.cached_urls) {
			this.cached_urls = $$('a.show_full_image').collect(function(el){
				return el.onclick.toString().match(/".*"/g)[0].replace(/"/g,'');
			});
		}
		return this.cached_urls;
	}

}

