﻿var Site = {
	start: function(){
		Site.loadJS([
			'effects.js',
			'slimbox.js'
		]);
	},
	loadJS: function(file){
	/*
		var getScript, path, scriptList;
		
		getScript = document.getElementsByTagName('script')[1];
		path = getScript.src.replace(/[^\/]+\.js.*$/,'');
		
		
	*/
		$$(document.getElementsByTagName('script')[0]).map(function(el){
			var path = el.src.replace(/[^\/]+\.js.*$/,'');
			var scriptList = file || [];
		
			for (var i=0, len=scriptList.length; i<len; i++){
				new Asset.javascript(path + scriptList[i]);
			}
		});
	}
};

var rss2List = {
	buildList: function(url,element){
		new XHR({
			method: 'get',
			onSuccess: function(req) {
				(function(){$(element).innerHTML = req}).delay(1000);
				$(element).fadeOut(500).fadeIn(500);
			},
			onFailure: function() {
				(function(){$(element).innerHTML = 'Sorry an error has occured'}).delay(1000);
				$(element).fadeOut(500).fadeIn(500);
			}
		}).send(url);
		return false;
	}
};

Element.extend({
	fadeIn:function(delay) {
		// Will fade in after delay - is chainable, ie:
		// $('element').fadeIn(500).fadeOut(1000);
		f = new Fx.Style(this, 'opacity', {duration:500, fps:50});
		f.start.pass([0,1], f).delay(delay);
		return this;
	},
	fadeOut:function(delay) {
		// Will fade out after delay - is chainable, ie:
		// $('element').fadeOut(500).fadeIn(1000);
		f = new Fx.Style(this, 'opacity', {duration:100, fps:50});
		f.start.pass([1,0], f).delay(delay);
		return this;
	}
});

Window.onDomReady(Site.start.bind(Site));