$(document).ready(function() {
						   
	enableProjectPopups();
	applyBreadCrumbUtils();
	maximizePrimaryColumn();
	addSIFR();
	patchMarketList();
	
});



var $fb = $.facebox;
var enableProjectPopups = function () {
	$('a.popup').click(function(e){
		var dataUrl = '/' + $(this).attr('name').replace(/\:/g, '/');
		/*
		$fb(function(){
			$.get(dataUrl, function(data) {
				$fb(data);
			})
		});
		*/
		return false;
	});
}

function fixTextOrphans () {
	function deorphanizeContents (el) {
		var t = $(el).html().replace(/ ([0-9a-z'"\.\(\)]+) ?$/i, "&nbsp;$1");
		$(el).html(t);
	}
	$('.primary').find('p, li').each(function(){
		if ($(this).contents().length == 1) deorphanizeContents(this);
	});
}

function maximizePrimaryColumn () {
	// lengthen primary column if needed (as compared to secondary column)
	if ($('.primary').height() < $('.secondary').height()) {
		$('.primary').height($('.secondary').height());
	}
	
	// lengthen primary column if needed (as compared to left-subnav column)
	var allowance = 300;
	if ($('.primary').height() < ($('#pageBody .subnav').height() - allowance)) {
		$('.primary').height($('#pageBody .subnav').height() - allowance);
	}
}

function addSIFR () {
	
	$("#pageHeader .tagline").sifr({ path: '/Content/sifr2/', font: 'Print_Bold_OT', textAlign: 'right', fontSize: 18, roY: 12 });

	$("#pageHeader ul.locations li a").sifr({ path: '/Content/sifr2/', font: 'Print_Bold_OT', textAlign: 'center', fontSize: 11, selectable: false });
	
	$("h1, .home .box h3").not(".no_sifr").each(function(i){
		if ($(this).find(".no_sifr").length == 0) {
			$(this).sifr({ path: "/Content/sifr2/", font: "ZapfHumnst_Ult_BT" });
		}
	});
	
	if (!($.browser.msie)) {
		$("#pageSplash h2").sifr({ path: "/Content/sifr2/", font: "Print_Bold_OT", verticalAlign: "top" });
	}
	
	$("h3, h4").not(".no_sifr").each(function(i){
		if ($(this).find(".no_sifr").length == 0) {
			$(this).sifr({ path: "/Content/sifr2/", font: "Print_Bold_OT" });
		}
	});


	// correct sifr implementation so as to make each contact link clickable
	var hotspotCSS = { display: 'block', position: 'absolute', left: 0, top: 0, padding: '2px 0', cursor: 'pointer', borderBottom: 'none' };
	var hotspotHoverCSS = { borderBottom: '1px solid #999' };
	if ($.browser.msie) {
		$.extend(hotspotCSS, { backgroundColor: '#fff', filter: 'alpha(opacity=0)' });
		$.extend(hotspotHoverCSS, { filter: 'alpha(opacity=15)' });
	}
	$("#pageHeader ul.locations li a").each(function(i){
		var jqLink = $(this);
		jqLink.css({ position: 'relative' }).append('<span class="hotspot">&nbsp;</span>').find('.hotspot')
			.css(hotspotCSS).width(jqLink.width()).height(jqLink.height())
			.hover(function(){ $(this).css(hotspotHoverCSS) }, function(){ $(this).css(hotspotCSS) })
			.click(function(){ location.href = jqLink.attr('href') })
		;
	});

//	$(".sifrtester").sifrTester({ path: '/Content/sifr2/', font: 'ZapfHumnst_Ult_BT' });
};

function applyBreadCrumbUtils () {
    $("#nav ul.breadcrumb").appendBreadCrumbList("/", {
        delimAfter: " &raquo; "
		, docRootLabel: "Home"
		, labels: {
		    "about": "About Us"
			, "conferences": "Conferences / Trade Shows"
			, "contact": "Contact Us"
			, "team": "Our Team"
		}
    });
    $("ul.mainMenu li").indicateCurrentPage("sel", false);
    $(".subnav ul li").indicateCurrentPage("sel", true);
};

function patchMarketList () {
	if ((/wirelesssystems/i).test(location.href)) location.replace('http://www.gpdgroup.com/Markets/');
	$('a[href*="WirelessSystems"], a[href*="wirelesssystems"], a:contains("Wireless Systems"), a:contains("wireless systems")').each(function(){
		$(this).parent().parent().andSelf().filter('li').remove();
	});
}

