// Core JavaScript Document

// external links
function externalLinks() {
	var a = $$('a');
	a.each(function(el){
		if (el.getProperty('rel')=='external'){
			el.setProperty('target','_blank');
		}
	});
}

function category(){
	if ($('category')){
		$('category').addEvent('change', function(e){
			if (this.value){
				window.location = '/' + this.value + '/';
			}else{
				window.location = '/';
			}
		});
	}
}

function tweet(){
	if ($('tweets-here')){
		var req = new Request.HTML({url:'/feeds.php',
			onSuccess: function(html) {
				//Clear the text currently inside the results div.
				//Inject the new DOM elements into the results div.
				$('tweets-here').adopt(html);
				$('tweets-here').removeClass('loading');
				if (html != 'Oops, the Tweet feeder is empty!'){
					bouncer = bouncescroll.periodical(6000);
					var bouncer;
				}
			}
		}).send();
	}
}

function bouncescroll(){
	var l;
	var bouncescrollers = $('tweets-here');
	var first = bouncescrollers.getFirst();
	var fx1 = new Fx.Tween(bouncescrollers,{transition: Fx.Transitions.Quad.easeOut, duration: 500});
	bouncescrollers.setStyle('margin-left','722px');	
	var pop = first.dispose();
	pop.inject(bouncescrollers);
	fx1.start('margin-left', '0px');
	/*
	first = bouncescrollers.getFirst().get('html');
	l = first.length;
	*/
}


function forms(){
var form = $$('form');
form.each (function(el){
		 new FormCheck(el.id);
	});
}

window.addEvent('domready', function(){
	externalLinks();
	category();
	forms();
	tweet();
});