// JavaScript Document
document.createElement('header');
document.createElement('nav');
document.createElement('article');
document.createElement('aside');
document.createElement('footer');

function toggleDiv(objectID) {
	if (document.getElementById(objectID).style.display == 'block') {
		document.getElementById(objectID).style.display = 'none';
	} else {
		document.getElementById(objectID).style.display = 'block';
	}
	return
}
function toggleImg(new_image,caption) {
	document.getElementById('p_photo').style.backgroundImage = 'url(scale_image.php?f=_projects/' + new_image + '&w=690&h=518)';
	document.getElementById('caption').innerHTML = caption;
}

$(document).ready(function(){
	$('.category-title').click(function(){
		var id = $(this).attr("id");
		id = id.replace("link-","category-");
		if($('#'+id).css('display') == 'none') {
			$('#'+id).hide().slideDown(500);
		} else {
			$('#'+id).show().slideUp(500);
		}
	});
	
	$('.subcat-link').click(function(){
		var id = $(this).attr("id");
		id = id.replace("subcat-","subcat-members-");
		if($('#'+id).css('display') == 'none') {
			$('#'+id).hide().slideDown(500);
		} else {
			$('#'+id).show().slideUp(500);
		}
	});
	
	$('.team-name').click(function(){
		var id = $(this).attr("id");
		id = id.replace("team-","desc-");
		if($('#'+id).css('display') == 'none') {
			$('#'+id).hide().slideDown(500);
		} else {
			$('#'+id).show().slideUp(500);
		}
	});
	
	var fade = function(){
		var t = $('.featureimg:first');
		var l = $('.featureimg:last');
		l.css('opacity',1);
		var total = t.attr('data-count');
		l.show();
		if($('.featureimg').length > 1) { 
			t.animate({opacity:0},1000,function(){
				t.appendTo('#feature');
				var b = t.css('background-image');
				b = b.substr(b.lastIndexOf("/")+1,b.length);
				b = b.split('.')[0];
				b = parseInt(b) + 2;
				if(b > total) b = b-total;
				t.css({
					'background-image':'url(/feature_block/'+b+'.jpg)'
				});
				
				setTimeout(function(){
					fade();
				},5000);
			});
		}
	}
	
	setTimeout(function(){
		fade();
	},5000);
});
