$(document).ready(function(){
	// Redirects
	$('#facebook').click(function(){
		window.open('http://www.facebook.com/pages/Capitol-Consultants-Inc/139459566352');
	});
	$('#twitter').click(function(){
		window.open('http://twitter.com/#!/capconsultants');
	});
	$('#services').click(function(){
		window.location.href = '/Services.aspx';
	});
	$('#casestudies').click(function(){
		window.location.href = '/Case_Studies.aspx';
	});
	$('#clients').click(function(){
		window.location.href = '/Client_List.aspx';
	});

	// AG Articles and Inside header
	if (window.location.pathname == '/site/Viewer.aspx')  {
		$("#title").html(document.title.split(" - ")[1]);
		$(".aOpt H1:first").hide();
		innerHeader();
	}
	else if (window.location.pathname != '/Home.aspx')  {
		$("#title").html(document.title);
		innerHeader();
	}

	// Twitter
	$(".twitter").each(function()  {
		$(function() {
			$.getJSON(
				'http://twitter.com/status/user_timeline/capconsultants.json?count=4&callback=?',
				function(d) {  
					$.each(d.reverse(), function(i, item) {
						var html = '';
						html	= '<div class="item">'
							+ '<h2>' + $.format.date(item.created_at, "MM/dd/yyyy hh:mm") + '</h2>'
							+ replaceURLWithHTMLLinks(item.text)
							+ '</div>';
						$('.twitter #content').prepend(html);
					});
				}
			);
		});
	});
});

function innerHeader()  {
	$("#header").css("background-image", "url(/Domains/capitolconsultants/images/inner.jpg)");
	$("#header").height("310px");
	$("#header #flash").remove();
}

function replaceURLWithHTMLLinks(text) {
	var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
	return text.replace(exp,"<a href='$1'>$1</a>"); 
}
