$(document).ready(function(){
	fixNavFirst();
	fixNavBold();
	
	clientsRemoveTopMarginFirst();
	clientsWorkshopPop()
	clientBackLink();
	
	aboutPageAlign();
	aboutStatsBorder();
	
	processLastStep();
	
	fixWorkPage();
	
	//techHover();
	techList();
	techListMarginBottomIE();
	
	pressNav();
	
	footerPop();
});

function fixNavFirst() {
	$('#mainNav li:first a').css('padding-left', '0');
}

function fixNavBold() {	
	$('#mainNav li a').each(function(){
		var paddingLeft = $(this).css('paddingLeft');
		var paddingRight= $(this).css('paddingRight');
		paddingLeft = parseInt(paddingLeft, 10);
		paddingRight= parseInt(paddingRight, 10);
		var newWidth = $(this).width()+paddingLeft+paddingRight;
		$(this).css({width:newWidth,paddingLeft:0,paddingRight:0,textAlign:'center'});
	});
	$('#mainNav li:first a').css('text-align', 'left');
}


function clientsRemoveTopMarginFirst() {
	$('#about h2:first, #bulletpoints h2:first').css('marginTop', '0');
}

function clientsWorkshopPop() {
	$('#workshop a').attr('target', '_blank');
	$('#currentDeployments a').attr('target', '_blank');
}

function aboutPageAlign() {
	$('#leftColumn, #rightColumn').css('position', 'relative');
	var leftWidth = $('#leftColumn').width();
	var rightWidth = $('#rightColumn').width();
	$('#leftColumn h2:last, #leftColumn h2:last ~ *').wrapAll('<div style="position: absolute; top: 300px; width: ' + leftWidth + 'px;"></div>');
	$('#rightColumn h2:last, #rightColumn h2:last ~ *').wrapAll('<div style="position: absolute; top: 300px; width: ' + rightWidth + 'px;"></div>');
}

function aboutStatsBorder() {
	$('#stats th:last, #stats td:last').css('border-bottom', 'none');
}

function processLastStep() {
	$('.step:last').css('padding-right', '0').css('border-right', 'none').css('margin-right', '0');
}

function fixWorkPage() {
	$('.row .workshop:last-child').css('padding-right', '0').css('border-right', 'none').css('margin-right', '0');
	$('.row .workshop:last-child .more').css('right', '0');
	$('.row:last').css('border-bottom', 'none');
}

function techHover() {
	$(".tech .icon a").hover (
		function() {
			$(this).css("background-position", "center -52px");
		},
		function() {
			$(this).css("background-position", "center top");
		});
	$(".tech h3 a").hover (
		function() {
			$(".icon a", $(this).parents(".tech").get(0)).css("background-position", "center -52px");
		},
		function() {
			$(".icon a", $(this).parents(".tech").get(0)).css("background-position", "center top");
		});
}

function techList() {
	$('.techList .tech').filter(function (index) {
		return ((index+1) % 4 == 0);
	}).css('border-right', 'none');
}
function techListMarginBottomIE() {
	$('.techList').append('<div style="clear: both; font-size: .1em;"><span></span></div>');
}

function pressNav() {
	$('#pressNav li:last-child a').css('border-bottom', '1px solid #D7D7D7');
}

function clientBackLink() {
	if(document.location.toString().indexOf('oddcast.com/clients/') != -1 && document.referrer.indexOf('oddcast.com/technologies/') != -1)
	{
		var backLink = $('#clientMain #backLink a');
		if(backLink.length != 0)
		{
			backLink.get(0).href = document.referrer;
			backLink.text('< back to TECHNOLOGY');
		}
	}
}

function footerPop() {
	$('#footer a').attr('target', '_blank');
}
