/* -------------------------------------------------- *
 * Global JavaScript Actions
 * Requires jQuery
 * -------------------------------------------------- */
var $j = jQuery.noConflict();


// used to display code in modals
function showModal(theLink) {

	var theMessage = "<pre>" + $(theLink).parent().prev("pre").html() + "</pre>";
	
	$j.blockUI({
		message: theMessage,
		css: {
			backgroundColor: "#fff",
			border: "5px solid #ccc",
			color: "#333",
			cursor: "auto",
			font: "12px/normal Arial, Helvetica, sans-serif",
			left: "50%",
			margin: "10% 0 0 -415px",
			padding: "10px",
			textAlign: "left",
			top: "0",
			width: "800px"
		},
		overlayCSS: {
			backgroundColor: "#000",
			cursor: "auto",
			opacity: "0.8"
		}
	});
	
	$j(".blockMsg").append('<p class="closeModal"><a href="#">Close</a></p>').click(function() {
		$.unblockUI();
		return false;
	});
}


// here we go!
$j(document).ready(function() {

    // archive list accordion effects
    //$j("#sidebar ul.archiveList")
	//	.find("li > ul").wrap("<div></div>").css("overflow", "hidden").end()
	//	.next("h4").css("margin-top", "0").end()
	//	.accordion(".accordionheader", {
	//	    autoHeight: false
	//	});

    // search text toggling
    $j("#searchForm input").toggleVal();

    // add text size bar
    $j('<div id="textSizeBar"><p><strong>Change article font size:</strong><label><input type="radio" id="fontSizeNormal" name="fontSize" value="normal" />Normal</label><label><input type="radio" id="fontSizeLarge" name="fontSize" value="large" />Large</label></p><div id="acceptChanges"><img src="/images/accept.png" alt="Accept Changes" title="Accept Changes" /></div></div>').insertAfter("#feedBar").hide();
    $j("#acceptChanges img").click(function() {
        $j("#textSizeBar").slideToggle("fast");
    });

    // toggle text size bar
    $j('<div id="adjustTextSize"><img src="/images/text-size.png" alt="Adjust Text Size" title="Adjust Text Size" /></div>').appendTo("#feedBar").click(function() {
        $j("#textSizeBar").slideToggle("fast");
    });

    // get text size
    if ($j.cookie("textSize") == "large") {
        $j("div.article").css("fontSize", "14px");
        $j("#fontSizeLarge").attr("checked", "checked");
    }
    else {
        $j("div.article").css("fontSize", "12px");
        $j("#fontSizeNormal").attr("checked", "checked");
        $j.cookie("textSize", "normal", { expires: 365 });
    }

    // text resize actions
    $j("#fontSizeNormal").click(function() {
        $j("div.article").animate({ "fontSize": "12px" }, "fast");
        $j.cookie("textSize", "normal", { expires: 365 });
    });
    $j("#fontSizeLarge").click(function() {
        $j("div.article").animate({ "fontSize": "14px" }, "fast");
        $j.cookie("textSize", "large", { expires: 365 });
    });

    // modals for code snippets
    /*
    $j("pre:has(code)").after('<div class="modalLink"><a href="#" onclick="showModal(this); return false;">View in full screen</a></div>');
    */
});