// this is a placeholder to replace the stuff that comes from the mola_jq command, which is deprecated!
// from here... standards/mola_0.9.7/mola_jquery_base.js?v=3 to this

var ie6=($.browser.msie && !window.XMLHttpRequest);	//a global hack test for IE...
var hConstraints=[];
minHeightFix=function(target,constraints,padding) {
	//alert("enacting minHeightFix"); // this prevents the existing fix from causing us problems...
	//alert("passed in "+constraints.length);
	if (ie6) {
		if(!$("#minheightfix").length){
			target.append("<div id='minheightfix'></div>");	
		}
		$("#minheightfix").height(0);
	} 	
	var targetH=target.height();
	var tallest=0;
	for(i=0;i<constraints.length;i++) {
		if (constraints[i]>tallest) {
			tallest=constraints[i];
		}
	}
	tallest+=padding;
	//alert("content ="+targetH+"; "+"tallest = "+tallest+ " differential="+(tallest-targetH>0?tallest-targetH:0));
	target.css("min-height",(tallest)).css("height","auto"); // go ahead and set it just in case
	//alert("after set min-height: "+target.css("min-height"));
	if (ie6) {  // need min-height detection!
		$("#minheightfix").height(tallest-targetH>0?tallest-targetH:0);
	} 	
}


$(function() {

    $(".jqmp3").each(function(i){
        var thisID="mp3player"+lPad(i,3,"0");
        $(this).attr("id",thisID);
        var thatID=thisID.replace(/player/,"links");
        $("body").append("<div id='"+thatID+"' class='jqPopUp'></div>");
        $("#"+thatID).prepend("<div style='color:white;background:black; text-align:right; padding:2px 0;'><img style='cursor:pointer' class='jqPopUpClose' width='14' height='14' src='"+molajsResources+"/icons/close.gif"+"'></div>");
        $("#"+thatID).append("<div class='jqPopUpContent'>"+$(this).html()+"</div>");
        var thisSet=$("#"+thisID+" a[@href$=.mp3]");
        var fileSwitch=thisSet.length>1?"mp3multi.swf":"mp3single.swf";
        var heightSwitch=thisSet.length>1?"150":"50";
        var so=new SWFObject(molajsResources+"/flash/"+fileSwitch,"lc_"+thisID,"220",heightSwitch,"7");
        $("#"+thisID+" a[@href$=.mp3]").each( function(j) {
            so.addVariable("passedAudio"+lPad(j,3,"0"), this.href);
            so.addVariable("passedTitle"+lPad(j,3,"0"),$(this).text());
        });
        so.addParam("wmode","transparent");
        so.write(thisID);
        $(this).append("<div class='mp3switch'>get downloads and info</div>").children('.mp3switch').click(
            function() {
                var thatID="#"+$(this).parent().attr("id").replace(/player/,"links");
                $(thatID).slideToggle(200);
            }
        );
    });
    //$(".jqPopUpContent").css("padding","1em");
    //$(".mp3close").css("background-image","url("+molajsResources+"/icons/close.gif)");
    $(".jqPopUpClose").click( function() {$(this).parent().parent().slideToggle(200);} );
    //$(".jqColumn").vjustify();
    $(".jqZebra tr:nth-child(odd)").addClass("jqOdd");
    $(".jqZebra tr:nth-child(even)").addClass("jqEven");
	$("#jqSupport").hide("slow");
    $("#formLoading").hide("slow");
});


$(function() {
	$("#search").submit(function(){
		if($.trim($("#q").val())=="catalog") {
		 	$("#q").val("catalogue");
		}
	});		
	
	$(".alertBox").wrapInner("<div></div>").prepend("<div></div>").append("<div></div>");
	$(".alertBox div").eq(0).addClass("alertPre");
	$(".alertBox div").eq(1).addClass("alertBody");
	$(".alertBox div").eq(2).addClass("alertPost");	
	
	$("#content").children().slice(0,1).css("margin-top","0"); // only works on sigletons, not compounds...
	// 36 is the current height of "#exploreBox" ... hardcoded here; only changes if template changes
	hConstraints=[$("#areaMenu").height()+36, $("#siteMenu").height()+36, $("#sidebarBox").height()];
	minHeightFix($("#content"),hConstraints,30);
	$("#sidebarBox form").css("margin-top","0"); //IE fix.
	$("#exploreBox a").click(function() {

		if($(this).attr("rel")=="closed") {
			$("#areaMenu").hide(100,function() {
				$("#siteMenu").show(200);
			});  // should work, but throws error!
			//$("#areaMenu").hide();$("#siteMenu").show();
			//console.log('clicked');
			$(this).parent().css("background-image","url(/d/img/exploreOpen.gif)");
			$(this).attr("rel","open");
			$(this).attr("title","click to hide Centenary site menu");
		} else {
			$("#siteMenu").hide(100, function() {
				$("#areaMenu").show(200);
			});
			//$("#siteMenu").hide();$("#areaMenu").show();
			$(this).parent().css("background-image","url(/d/img/exploreClosed.gif)");
			$(this).attr("title","click to show Centenary site menu");
			$(this).attr("rel","closed");
		}
		return false; // this should prevent anchor load in firefox ...// 
	});
});
	

