doCufon();

jQuery(document).ready(function($) {
    initGlobalTools();
    initIEHacks();
    //addBreadCrumb();

    $('#pageBody > .primary').find('p, li').deorphanize();
    $('ul.features > li > h3 a').closest('li')
		.click(function() { location.href = $(this).find('h3 a').attr('href'); })
	;

    $('#nav .mainMenu > ul').find('li:has(a):has(ul)').children('a').hoverfix();

    $('a.exp')
		.nextAll().hide().end()
		.click(function() { $(this).toggleClass('open').nextAll().toggle('fast'); return false; })
	;
    if ($.prettyPhoto) {
        $('a.vid')
			.prettyPhoto({ theme: 'dark_rounded', show_title: false, callback: function() { $('#nav .global-tools').show('fast'); } })
			.click(function() { $('#nav .global-tools').hide('fast'); })
			.find('img').after('<span class="ico">&nbsp;</span>')
		;
    }

    /*
    if (navigator.userAgent.match(/\biP/i)) {
    $('.global-tools form.login .help').css('margin-left': '15px');
    }
    */




    function initGlobalTools() {
        $('.global-tools form label').hide().each(function(i) {
            var thisLabel = $(this).text();
            $('.global-tools input:text#' + $(this).attr('for'))
				.val(thisLabel)
				.addClass('empty')
				.focus(function() {
				    if ($(this).is('.empty')) $(this).val('').removeClass('empty');
				})
				.blur(function() {
				    if ($(this).val().length < 1) $(this).val(thisLabel).addClass('empty');
				})
			;
        });
    }

    function initIEHacks() {
        if ($.browser.msie) {

            $('.global-tools form select')
				.focus(function() {
				    $(this)
						.data("origWidth", $(this).css("width"))
						.css("width", "auto");
				})
				.blur(function() {
				    $(this).css("width", $(this).data("origWidth"));
				})
			;

            if (Number($.browser.version.split('.')[0]) <= 7) {
                $('input.btn').val('');
            }

        }
    }

    //	function addBreadCrumb () {
    //		$("#nav ul.breadcrumb").appendBreadCrumbList("/", {
    //			delimAfter: " &raquo; "
    //			, docRootLabel: "Home"
    //			, labels: { 'services': 'Logistics Services' }
    //		});
    //		$("#nav .mainMenu ul li, .secondary .subnav li").indicateCurrentPage("sel", {
    //			overrides: {  }
    //		});
    //	}

});



function doCufon () {
	Cufon.replace('#nav .mainMenu > ul > li > a', {
		fontFamily: 'CopperplateBold'
		, fontSize: '13px'
		, lineHeight: '1px'
		, letterSpacing: '-0.5px'
		, hover: true
	});
	$('.global-tools > h4 a').css({ position: 'absolute', top: '7px' });
	Cufon.replace('.global-tools h4 a', {
		fontFamily: 'CopperplateBold'
		, fontSize: '12px'
		, marginTop: '-3px'
		, modifyText: function(str, node, el, opt){ return 'foo'; }
	});
	Cufon.replace('#pageBody h1, #pageBody h2, #pageBody h3, #pageBody h4', {
		fontFamily: 'MyriadPro'
	});
}

function adjustColumns () {
	// if secondary content doesn't exist, widen main column to include right column space
	if ($("#pageBodyContent > .secondary").length == 0 || $("#pageBodyContent > .secondary").height() == 0 || $("#pageBodyContent > .secondary").text().length == 0) $("#pageBodyContent > .primary").css("padding-right", "0px");
	
	// if secondary content does exist, equalize the primary and secondary columns
	if ($("#pageBodyContent > .secondary").length > 0) {
//		var targetHeight = Math.max($("#pageBodyContent > .primary").height(), $("#pageBodyContent > .secondary").height());
//		$("#pageBodyContent > .primary, #pageBodyContent > .secondary").height(targetHeight);\
		$('#pageBodyContent > .primary, #pageBodyContent > .secondary').setEqualHeight();
	}
	
	// stretch subnav column
//	$('#subnav').height($('#pageBodyContent').height());
	$('#subnav, #pageBodyContent').setEqualHeight();
}

