window.addEvent('domready',function() {
	if ($('faqs')) faqs();
	if ($('caption')) workgallery();
	if ($$('div.pagination')) miniblocks();
});

function faqs() {
	$('faqs').getChildren('li').each(function(el,index) {
		el.getFirst('a').onclick = function() {
			this.getParent('li').toggleClass('open');
			return false;
		}
	});
}

function workgallery() {
	$('projects').getChildren('li').each(function(el, index) {
		el.getFirst('a').onclick = function() {
			var img = this.getFirst('img');
			var title = img.get('alt');
			var imgname = img.get('src').replace('-thumb','');
			$('mainimg').set('src',imgname);
			if (title != null) {
				$('caption').set('html','<p>'+title+'</p>');
			} else {
				$('caption').set('html','<p></p>');
			}
			return false;
		}
	});
}

function miniblocks() {
	var current = 0;
	changoutminis(current);
	$$('div.pagination').each(function(el,index) {
		el.getFirst('a.previous').onclick = function() { 
			if (current <= 0) { current = $$('div.miniblock').length-1;	} else { current--; }
			changoutminis(current);
			return false;
		}
		el.getFirst('a.next').onclick = function() {
			if (current >= $$('div.miniblock').length-1) { current = 0; } else { current++; }
			changoutminis(current);
			return false;
		}
	});
}

function changoutminis(current) {
	$$('div.miniblock').each(function(el,index) {
		if (current == index) {
			if (el.hasClass('hidden')) el.removeClass('hidden');
		} else {
			if (!el.hasClass('hidden')) el.addClass('hidden');
		}
	});
}

/*
* * * * * * * * * * * * * * * * * * * * *
IE :hover Fix --- taken from A List Apart
* * * * * * * * * * * * * * * * * * * * *
*/
sfHover = function() {
	if ($('menu')) {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
