
// MooTools: the javascript framework.
// Load this file's selection again by visiting: http://mootools.net/more/0119174cc074dcb3c71d29e9b0ee39d9 
// Or build this file again with packager using: packager build More/Request.JSONP
/*
---
copyrights:
  - [MooTools](http://mootools.net)

licenses:
  - [MIT License](http://mootools.net/license.txt)
...
*/
MooTools.More={version:"1.3.2.1",build:"e586bcd2496e9b22acfde32e12f84d49ce09e59d"};Request.JSONP=new Class({Implements:[Chain,Events,Options],options:{onRequest:function(a){if(this.options.log&&window.console&&console.log){console.log("JSONP retrieving script with url:"+a);
}},onError:function(a){if(this.options.log&&window.console&&console.warn){console.warn("JSONP "+a+" will fail in Internet Explorer, which enforces a 2083 bytes length limit on URIs");
}},url:"",callbackKey:"callback",injectScript:document.head,data:"",link:"ignore",timeout:0,log:false},initialize:function(a){this.setOptions(a);},send:function(c){if(!Request.prototype.check.call(this,c)){return this;
}this.running=true;var d=typeOf(c);if(d=="string"||d=="element"){c={data:c};}c=Object.merge(this.options,c||{});var e=c.data;switch(typeOf(e)){case"element":e=document.id(e).toQueryString();
break;case"object":case"hash":e=Object.toQueryString(e);}var b=this.index=Request.JSONP.counter++;var f=c.url+(c.url.test("\\?")?"&":"?")+(c.callbackKey)+"=Request.JSONP.request_map.request_"+b+(e?"&"+e:"");
if(f.length>2083){this.fireEvent("error",f);}Request.JSONP.request_map["request_"+b]=function(){this.success(arguments,b);}.bind(this);var a=this.getScript(f).inject(c.injectScript);
this.fireEvent("request",[f,a]);if(c.timeout){this.timeout.delay(c.timeout,this);}return this;},getScript:function(a){if(!this.script){this.script=new Element("script",{type:"text/javascript",async:true,src:a});
}return this.script;},success:function(b,a){if(!this.running){return;}this.clear().fireEvent("complete",b).fireEvent("success",b).callChain();},cancel:function(){if(this.running){this.clear().fireEvent("cancel");
}return this;},isRunning:function(){return !!this.running;},clear:function(){this.running=false;if(this.script){this.script.destroy();this.script=null;
}return this;},timeout:function(){if(this.running){this.running=false;this.fireEvent("timeout",[this.script.get("src"),this.script]).fireEvent("failure").cancel();
}return this;}});Request.JSONP.counter=0;Request.JSONP.request_map={};

window.addEvent('domready', function(){


$('menu').getElements('a').set('morph', {
	duration: 'long',
	transition: 'elastic:out'
}).addEvents({
	mouseenter: function(){
		this.morph({
			'padding-top': [40, 35],
			'height': [20, 25]
		});
	},
	mouseleave: function(){
		this.morph({
			'padding-top': [35, 40],
			'height': [25, 20]
		});
	}
});

var twitter = $('twitter');
if (twitter){
	new Request.JSONP({
		url: 'http://twitter.com/status/user_timeline/astolwijk.json',
		onRequest: function(){
			twitter.set('text', 'loading...');
		},
		onComplete: function(tweets){
			var ul = new Element('ul');
			tweets.each(function(tweet){
				ul.grab(new Element('li').grab(new Element('a', {
					href: 'http://twitter.com/astolwijk/status/' + tweet.id_str,
					text: tweet.text,
					target: '_blank'
				})));
			});
			twitter.empty().grab(ul);
		}
	}).send({
		data: {
			count: 4,
			include_rts: true
		}
	});
}

var github = $('github');
if (github){
	new Request.JSONP({
		url: 'http://github.com/api/v2/json/repos/show/arian',
		onRequest: function(){
			github.set('text', 'loading...');
		},
		onComplete: function(repos){
			var ul = new Element('ul');
			repos.repositories.sort(function(value1, value2){
				return new Date(value2.pushed_at) - new Date(value1.pushed_at);
			}).slice(0, 15).each(function(repo){
				ul.grab(new Element('li').grab(new Element('a', {
					href: repo.url,
					text: repo.name,
					target: '_blank'
				})))
			});
			github.empty().grab(ul);
		}
	}).send({
		data: {
			count: 4,
			include_rts: true
		}
	});
}

$$('div.fout, .verstuurd').highlight('#F90');

$$('input[type="text"], textarea').tween('opacity', 0.5).addEvents({
	focus: function(){
		this.fade('in');
	},
	blur: function(){
		this.tween('opacity', 0.5);
	}
});


var projects = $('projects');
if (projects){
	var desc = projects.getElements('.desc'),
		images = projects.getElements('img');

	desc.setStyles({
		display: 'none',
		opacity: 0.9
	});

	var zIndex = images.length + 1000, maxIndex = zIndex + 1;
	images.each(function(image, i){
		var imgIndex = zIndex--,
			open = false,
			imgPos = {
				width: 180,
				top: Math.floor(i / 4) * 130 + Number.random(-20, 20),
				left: (i % 4) * 120 + Number.random(-20, 20),
				opacity: 0.7
			};
		image.setStyles(imgPos)
			.setStyle('z-index', imgIndex)
			.set('morph', {
				transition: 'back:out'
			});
		
		image.addEvents({
			mouseenter: function(){
				this.morph({
					width: 224,
					top: imgPos.top - 20,
					left: imgPos.left - 20,
					opacity: 1
				}).setStyle('z-index', maxIndex);
				
				desc[i].setStyles({
					display: 'block',
					bottom: projects.getStyle('height').toInt() - imgPos.top + 40,
					'z-index': maxIndex
				});
			},
			mouseleave: function(){
				this.morph(imgPos).setStyle('z-index', imgIndex);
				desc[i].setStyle('display', 'none');
			}
		});
	});

	projects.setStyle('height', Math.ceil(images.length / 4) * 130 + 50);
}

});

