var _links = [];

$(function () {
	if (location.pathname.toLowerCase() == "/contributions") {
		// Accordion
		$('.adxSection').each(function () {
			$(this).find('p').wrapAll('<div></div>');
		});

		$('.content2').accordion({
			header: '.adxSubheading',
			active: 0,
			collapsible: true,
			autoHeight: false
		}).find('.adxSubheading').css({ cursor: "pointer" });
	}

	$('.AuthorSection').accordion({
		active: -1,
		collapsible: true,
		autoHeight: false
	});

	$("a[href*='youtube.']:first", ".main-area").parents('ul:first').addClass('youtube');
	$("a[href*='youtube.']", ".main-area").each(function () {
		// Grab video ID from the url and the title from the H3 tag
		var videoID = $(this).attr('href').match(/watch\?v=(.+)+/)[1];
		var videoTitle = $(this).text();

		// Move the link to before the title to it can float to the left properly
		$(this).before('<h3>' + videoTitle + ':</h3>');

		// Add the thumbnail
		// $(this).html("<img src='http://img.youtube.com/vi/" + videoID + "/default.jpg' />");
		$(this).css({ backgroundImage: "url(http://img.youtube.com/vi/" + videoID + "/default.jpg)" });

		// Set up ColorBox
		$(this).parents("li:first").colorbox({
			iframe: true,
			href: "http://www.youtube.com/v/" + videoID + "?autoplay=1&rel=0",
			title: videoTitle,
			initialWidth: 100,
			initialHeight: 100,
			width: "775",
			height: "510",
			opacity: 0.5,
			onCleanup: function () {
				// This just kills the contents before the box closes for a smoother appearance
				$("#cboxLoadedContent").html("");
			}
		});
	});
});

function initTabs()
{
	var blocks = document.getElementsByTagName("li");
	for (var i=0; i<blocks.length; i++)
	{
		if (blocks[i].className.indexOf("roll") != -1)
		{
			links = blocks[i].getElementsByTagName("a");
		
				for (var k=0; k<links.length; k++) {
					
					if (links[k].className == "button") {
						_links.push(links[k]);
						links[k].onclick = function()
						{
							for (var j = 0; j < _links.length; j++)
							{
								if (_links[j] != this)
								{
									_links[j].parentNode.className = _links[j].parentNode.className.replace("open", "");
								}
							}
							
							if ( this.parentNode.className.indexOf("open") != -1 ) 
							{
								this.parentNode.className = this.parentNode.className.replace("open", "");
								var temp1 = document.getElementById("nav");
								var temp2 = temp1.getElementsByTagName("a");
								for (var g=0; g<temp2.length; g++)
								{
									temp2[g].style.color = "#666666";
								}
							}
							else
							{
								this.parentNode.className += " open";
								var temp1 = document.getElementById("nav");
								var temp2 = temp1.getElementsByTagName("a");
								for (var g=0; g<temp2.length; g++)
								{
									temp2[g].style.color = "#cccccc";
									var temp3 = this.parentNode.getElementsByTagName("a");
									for (var gg=0; gg<temp3.length; gg++)
									{
										temp3[gg].style.color = "#666666";
									}
									this.style.color = "#000000";
								}
							}
							return false;
						}
				}
			}
		}
	}
}
if (window.addEventListener){
	//window.addEventListener("load", initTabs, false);
}
else if (window.attachEvent){
	//window.attachEvent("onload", initTabs);
}
