$(document).ready(function() {
    // Focus on the first text input field in the first field on the page
    $("#contentBody form:first input:first[type='text']").focus()

    processMarkup($(this));

    $('#contentBody').localScroll({
        axis: 'xy',
        hash: 'true'
    });

    $("a.fancy").each(function() {
        var $trigger = $(this), options;

        options = { titlePosition: 'over',
                    titleFormat: function(title, currentArray, currentIndex, currentOpts) {
                            return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                    },
                    type: "image",
					overlayOpacity: 0.85,
					overlayColor: '#fff',
					transitionIn: 'elastic',
					transitionOut: 'elastic',
					speedIn: 200,
					speedOut: 200,
					changeSpeed: 50
                  }

	if ($trigger.hasClass("swf")) {
            options["type"]="swf";
	}

        $trigger.fancybox(options);
    });
});

function processMarkup(root) {
	
    root.find(".jsOnly").show()

    root.find("legend").each(function() {
        $(this).replaceWith('<p class="question">' + $(this).html() + '</p>');
    });

    // root.find("hr").each(function() {
    //     $(this).replaceWith('<div class="hr"><hr/></div>');
    // });

    root.find("button").each(function() {
        if ($(this).find("span").length == 0) {
            $(this).wrapInner("<span></span>");
        }
    });
}

