$(document).ready(function(){
	
	var img;
	var divs = $("#gallery div.list");

	/* Set gallery div links with background and create the click event */
	for(var i=0; i<=divs.length; i++){
		img = $("#gallery div:eq("+i+")").attr("id");
		$("#gallery div:eq("+i+")").css("background", 'url('+img+') 45% 60%');
	}
	$("#gallery a").attr('class', 'gallery').fancybox({
		'autoDimensions' : false
	});

	/* Set footer links to tab content */
	$('#footer a.tab').click(function(){ // bind click event to footer links
		var href = $(this).attr('href'); // store href value of clicked link for ease of use
		var active = $("#tab_content").activeTab(); // store the value of the active tab
		
		if(href.indexOf($("body").attr('id')) != -1){ // proceed if we're on the same page as the desired tabs
			var hash = href.substring(href.indexOf("#")+1); // store the id value of the desired tab
			
			$("#tab_content ul li").each(function(index){ // traverse through the tab links to find the index of the desired tab
				if(hash == $(this).children().attr('href').substring(1) && active != index){ // proceed if we've found it
					$("#tab_content").triggerTab(index + 1); // trigger the tab based on the index value
				}
			});
		}
	});
	
	/* Set external links to open in new window */
	$(".searchResult a").attr('target', 'new');
	
});
