// JavaScript Document
jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: '/common/images/x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

$(document).ready
(
	function()
	{	
	    $('.fadeblue, #contentwrapper').supersleight({shim: '/common/images/x.gif'});
	    
		//this is used for the top navigation opacity when a page gets loaded.
		$('#topnav1 ul, #topnav2 ul, #topnav3 ul, #topnav4 ul, #topnav5 ul, #topnav6 ul, #topnav7 ul').fadeTo
		(
			'fast',
			0.9
		);
		
		//not sure if this is used!!!
		$('#latestnewscontent').fadeTo
		(
			'fast',
			0.7
		);

		// Wil - Tabbed Content

		$('#tablinks').css('display', 'block');
		$('#tabcontent div.content-item').css('display', 'none');
		$('#tabcontent h4').css('display', 'none');
		$('#tabcontent').css('border-top', '1px solid #012d6b');
		$('#tabcontent table').css('padding', '0');

		$('#tablinks ul li').each(function(index, element){$(element).attr("id", "tab" + index);});
		$('#tabcontent div.content-item').each(function(index, element){$(element).attr("id", "content-item" + index);});
		$('#tablinks ul li:nth-child(1)').addClass('tabon');
		$('#tabcontent div.content-item:nth-child(1)').css('display', 'block');

		$('#tablinks ul li a').click(function(){
			$currentContent = $('.tabon').attr('id').substring(3);
			
			$('.tabon').removeClass('tabon');
			$(this).parents("li").addClass('tabon');
			$newID = $(this).parents("li").attr('id').substring(3);

			$('#tabcontent #content-item' + $currentContent).css('display', 'none');
			$('#content-item' + $newID).css('display', 'block');
			return false;
		});

	}
);

sfHover = function() {

try
		{	
	var sfEls = document.getElementById("topmenu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
		}
		catch(err)
		{
			// do nothing. we dont need to do this for anything other that IE anyway
		}	

}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function buildFlash (divId, swfLoc, swfName, swfWidth, swfHeight, swfVar){
  var flashVersion = 8;
 
  var so = new SWFObject(swfLoc, swfName, swfWidth, swfHeight, flashVersion, "#FFFFFF");
  so.addParam("wmode", "transparent");
  so.addParam("scale", "noscale");
  if (swfVar){
   so.addVariable("configPath", swfVar);
  }
  so.write(divId);
}

//for the RNS article
var newWin = null;
function RNSpopUp(strURL)
{
    if (newWin != null && !newWin.closed) 
    {
        newWin.close(); 
    }
    
    var strOptions="status,scrollbars,screenX=300,left=300,screenY=200,top=50,height=550,width=630"; 
    newWin = window.open(strURL, 'newWin', strOptions); 
    newWin.focus(); 
}


function bookmarksite(url, title)
{
    if (window.sidebar) // firefox
    {
	    window.sidebar.addPanel(title, url, "");
	}
    else if(window.opera && window.print)
    { // opera
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar');
	    elem.click();
    } 
    else if(document.all)// ie
    {
	    window.external.AddFavorite(url, title);
	}
}























