$(function(){
	startxfade($("#fade"), ['header2.jpg','header3.jpg','header4.jpg']);
	$('#side a').attr('target','_blank');
	$('#side a.popup').click(function(){
		sub = window.open(this.href, 'sub', "scrollbars,dependent,height=600, width=500");
		sub.focus();								
		return false;						
	});
	$('#side li.calculator a').click(function(){
		calc = window.open(this.href, 'calc', "scrollbars,dependent,height=700, width=665");
		calc.focus();								
		return false;						
	});

});			   
			   
function startxfade(first,imgs) {
	if (!imgs) return;
	var counter = 0, url = first[0].src.split('/');
	imgs.push(url.pop());
	url = url.join('/')+'/'; 
	setInterval(function(){
		first = xfade(first,url+imgs[counter]);
		if (++counter==imgs.length) counter = 0;
	},10000);
}

function xfade(a,b) {
	return $('<img />').css('display','none').attr({'src': b, 'alt': ''}).load(
		function(){
			$(this).appendTo(a.parent()).fadeIn(3000,function(){a.remove()});
		}
	);
}	
