var docurl = location.href;
if ( docurl.match(/virbo/) ) {

    // Add onload handler that modifies spans created by
    // http://virbo.org/Template:ProductsSpan
    $(function () {
	    $('#productshelp').click(function ()
				     {$('#productskey').show();});
	    $('#productskeyclose').click(function ()
					 {$('#productskey').hide();});

	    $('span.avail').
		each(function () 
		     {$(this).attr('title',
				   $(this).attr('title')
				   + ": available")});

	    $('span.partavail').
		each(function () 
		     {$(this).attr('title',
				   $(this).attr('title')
				   + ": partially available")});
	    $('span.planned').
		each(function ()
		     {$(this).attr('title',
				   $(this).attr('title')
				   + ": under development")});
	    $('span.notplanned').
		each(function ()
		     {$(this).attr('title',
				   $(this).attr('title') +
				   ": no development planned")});
	})

}

if ( docurl.match(/virbo/) ) {

    $(function() {

        //$('<div id = "p-tb-options"></div>').insertBefore("#p-tb .pBody ul");   
	//$('#p-tb-options').append($("#p-personal .pBody ul"));
        //$("#p-tb .pBody ul").append($("#p-personal .pBody ul"));
        //$("#p-tb .pBody ul *").prependTo("#p-tb .pBody #p-tb-options");         
        //$("#p-tb-options #pt-login").hide();                                    
        //$("#p-tb-options").css("width", "100%").hide();                         
	//$('#p-tb-options li').css('list-style-type','none');
 
        numberRegExp = /^([0-9]) /;
        $("div#bodyContent h1 span.mw-headline").each(function(x){
            elementText = $("div#bodyContent h1 span.mw-headline").slice(x, x + 1).text();
             elementText = elementText.replace(numberRegExp, "$1.");
            $("div#bodyContent h1 span.mw-headline").slice(x, x + 1).text(elementText);
        });


	    using.register('bigiframe','http://virbo.org/meta/autocomplete/lib/jquery.bgiframe.min.js');
	    using.register('ajaxQueue','http://virbo.org/meta/autocomplete/lib/jquery.ajaxQueue.js');
	    using.register('thickbox', 'http://virbo.org/meta/autocomplete/lib/thickbox-compressed.js');
	    using.register('autocomplete', 'http://virbo.org/meta/autocomplete/jquery.autocomplete.js');
	    using.register('order-globals','http://virbo.org/meta/js/order/order-globals.js');
	    using.register('order',        'http://virbo.org/meta/js/order/order.js');

	    using("bgiframe");
	    using("ajaxQueue");
	    using("thickbox");
	    using("autocomplete","order-globals","order",function() {

		    $('head').append('<link>');
		    css = $('head').children(":last");
		    css.attr({ rel: "stylesheet", type: "text/css", href: "http://virbo.org/meta/autocomplete/jquery.autocomplete.css"});
		    $('head').append('<link>');
		    css = $('head').children(":last");
		    css.attr({ rel: "stylesheet", type: "text/css", href: "http://virbo.org/meta/js/order/order.css"});
		    
		    function format(item) {
			return item.matchstring; // + " &lt;" + item.docid + "&gt";
		    }
		    
		    $("#email").autocomplete('http://virbo.org/meta/autocomplete/autocomplete.jsp?searchSection=NumericalData&searchElement=Description', {	
			        minChars: 2,
				delay: 200,
				dataType: "json",
				parse: function(data) {
				return $.map(data, function(row) {   
					return {
					    data: row,
						value: row.matchstring,
						result: row.matchstring + " <" + row.docid + ">"
						}
				    })
				    },
				formatItem: function(item) {
				return format(item);
			    }
			}).result(function(e, item) {
				$("#email").attr("value",format(item));
				$.ajax({url:'http://virbo.org/meta/outersearch?sourceUrl=http://virbo.org/meta/&searchAction=outersearch&section=NumericalData&strictSearch=true&keyNumericalDataResourceID='+item.spaseid+'&output=keyNumericalDataResourceID&output=keyResourceName&output=keyResourceHeaderDescription&output=keyStartDate&output=keyStopDate&useTransformer=true&transformer=http://ec2-174-129-50-195.compute-1.amazonaws.com:8088/exist/rest/db/virbo/xsl/order0.xsl&resType=html',success: function(html) {$('#plotarea form').remove();$('#plotarea').append(html);render();$($('a.show')[0]).click();}})
				    });
		});
	    
	});

}


if ( docurl.match(/cds130/) ) {

    $(function() {

    
     // Create a black div on the bottom of the page that can be re-sized to
    // shade out the bottom part of the page.

    // Add jquery UI CSS
    $('head').append('<link>');
    css = $('head').children(":last");
    css.attr({ rel: "stylesheet", type: "text/css", href: "/wiki/skins/jquery-ui/jquery.ui.all.css"});

    using.register("jquery-ui", "/extensions/js/jquery/jquery-ui-1.8.9.min.js");
    using('jquery-ui',function () {
	    $('#overlay').resizable({handles: 'n'});
    });


    $('#footer').before('<div id="overlay" class="" style="position: fixed; background-color: black; filter:alpha(opacity=100); -moz-opacity:1.00; -khtml-opacity: 1.00; opacity: 1.00; z-index: 10000;"></div>');

    $('#p-tb').append('<div style="padding-left:8px;background-color:yellow"><a href="/wiki/index.php?title=2012S004">Marr\'s page</a></div>');
    $('#p-tb').append('<div style="padding-left:8px;background-color:yellow"><a href="/wiki/index.php?title=2012S003">Weigel\'s page</a></div>');
    $('#p-tb').append('<div style="padding-left:8px;background-color:yellow"><a href="/wiki/index.php?title=2012S002">Sheng\'s page</a></div>');

    $('#p-tb').append('<p><div><img src="/wiki/images/thumb/cds130front.png/180px-cds130front.png"/></div></p>');
    
    $('#overlay').css('height',10);
    $('#overlay').css('width',$(window).width());
    $('#overlay').css('top',$(window).height()-10);
    $('#overlay').css('left',0);

    // Every 500 ms, reset width to 100%.  Ideally would bind an event
    // to change in vertical scrollbar (appeared/disappear) instead, but 
    // such binding is not possible.
    setInterval("$('#overlay').css('width',$(window).width());",500);
    $(window).resize(function() {
	    $('#overlay').css('height',$('#overlay').css('height'));
	    $('#overlay').css('top',$(window).height()-$('#overlay').css('height').replace("px",""));
	});

	});

}

