<!--//
function  parseXml(xml)
{
  $(xml).find("message").each(function()
  {
    var message = $('#banner-wrapper #banner-static').clone().removeAttr('id').hide();
    var line    = 0;
    var heights = new Array();
    $(this).find("line").each(function()
    {
      line++;
      heights[line] = $(this).attr("size");
      var color = parseInt($(this).attr("color"));
      if (256 > color) {
        //Interpret small colour values as grey
        color = (color << 16) + (color << 8) + color;
      }
      message.find(".banner-" + line).text($(this).attr("string")).css({'font-size' : $(this).attr("size") + 'px', 'color' : '#' + color.toString(16)});
    });
    if( $(this).find("name").attr("string"))
    {
      message.find('.banner-4').text($(this).find("name").attr("string"));
    } else {
      message.find('.banner-4').html('&nbsp');
    }
    if( $(this).find("date").attr("string"))
    {
       message.find('.banner-4').append(' <span>' + $(this).find("date").attr("string") + '</span>');
    }
    var top2 = 29 - (heights[2]/2);
    var top1 = top2 - heights[1] - 5;
    var top3 = 60 - top2;

    message.find(".banner-1").css('top', top1 + 'px');
    message.find(".banner-2").css('top', top2 + 'px');
    message.find(".banner-3").css('top', top3 + 'px');
    $('#banner-wrapper').append(message);
  });
  $('#banner-wrapper').cycle({
      timeout: 10000,
      speed: 2000
  });
}

$(function(){
    $('.JumpMenu').change(function(){
        window.location = $(this).val();
    });
    $('#language-switcher select').change(function(){
        $(this).parent().submit();
    });
    $('#language-switcher :submit').hide();
    $('.PopupWindow').click(function(event){
        event.preventDefault();
        window.open($(this).attr('href'),'PopupWindow','scrollbars=yes,width=450,height=550').focus();
    });
    $('#relatedreading').hide();
    $('#relatedreadinglink').click(function(){
        $('#relatedreading').toggle();
    });
    $('.spamspan').spamspan();
    $('#term').placeholder();
    $('a[href^=/news.php?nav=3-29&id=126]').click(function(){
        window.open('/embed.php?base_nav_id=3',
                    'PopupWindow',
                    'scrollbars=yes,width=450,height=550'
                    ).focus();
        return false;
    });
});

function MoreLessText(elementname){
	var d=document;

	if (d.getElementById) {
		var el1 = d.getElementById (elementname);
		var el2 = d.getElementById (elementname+"more");
		if (el1 && el1.className) {
			el1.className = (el1.className == 'collapsMenu') ? 'expandMenu' : 'collapsMenu';
			el2.className = (el2.className == 'collapsMenu') ? 'expandMenu' : 'collapsMenu';
		}
	}
	
	return false;
}

/*
 *  Vanilla jQuery version of spamspan (http://www.spamspan.com/).
 *  Based on Drupal module at http://drupal.org/project/spamspan
 *  GPL licensed (c) 2007 Lawrence Akka, (c) 2006 SpamSpan
 */ 
(function($) {
    jQuery.fn.spamspan = function(options) {
// settings...?
        return this.each(function() {
// set mail to the relevant value, removing spaces
            var _mail = ($("span.u", this).text() +
                "@" +
                $("span.d", this).text())
                .replace(/\s+/g, '')
                .replace(/\[dot\]/g, '.');
// Find the header text, and remove the round brackets from the start and end
            var _headerText = $("span.h", this).text().replace(/^ ?\((.*)\) ?$/, "$1");
            // split into individual headers, and return as an array of header=value pairs
            var _headers = $.map(_headerText.split(/, /), function(n, i){
                return (n.replace(/: /,"="));
            });
// Find the anchor text, and remove the round brackets from the start and end
            var _anchorText = $("span.t", this).text().replace(/^ \((.*)\)$/, "$1");
// Build the mailto URI
            var _mailto = "mailto:" + encodeURIComponent(_mail);
            var _headerstring = _headers.join('&');
            _mailto += _headerstring ? ("?" + _headerstring) : '';
// create the <a> element, and replace the original span contents
            $(this).after(
                $("<a></a>")
                    .attr("href", _mailto)
                    .html(_anchorText ? _anchorText : _mail)
                    .addClass("spamspan")
            ).remove();
        });
    }
})(jQuery);

/* 
 *  jQuery-placeholder Plugin v0.1
 *  Dual-licensed under the GPL and MIT licenses
 *  http://plugins.jquery.com/project/jquery-placeholder
 */
(function($) {
    jQuery.fn.placeholder = function(options) {
        settings = jQuery.extend({
            onClass: 'focused',
            offClass: false,
            placeholderSupport: (function(){
                return 'placeholder' in document.createElement('input');
            })()
        }, options);
        return this.each(function() {
            if(!settings['placeholderSupport']) this.defaultValue = $(this).attr('placeholder');
            $(this).bind('focus', function(){
                if(!settings['placeholderSupport'] && ($(this).val() == this.defaultValue)) $(this).val('');
                if(settings['onClass']) $(this).addClass(settings['onClass']);
                if(settings['offClass']) $(this).removeClass(settings['offClass']);
            }).bind('blur', function(){
                if(!settings['placeholderSupport'] && !$(this).val().length) $(this).val(this.defaultValue);
                if(settings['onClass']) $(this).removeClass(settings['onClass']);
                if(settings['offClass']) $(this).addClass(settings['offClass']);
            });
        });
    };
})(jQuery);
//-->

