(function($) {
	var TRUE = true,
		FALSE = false,
		NULL = null,
		window = self,
		undefined,
		browserVersion = parseInt($.browser.version, 10),
		hasFlash = typeof swfobject != "undefined" && swfobject.hasFlashPlayerVersion("9"),
		isIE = typeof screen.fontSmoothingEnabled != "undefined",
		isIE8 = isIE && browserVersion === 8,
		isIE7 = isIE && browserVersion === 7,
		isIE6 = isIE && browserVersion === 6,
		pngfix = function(selectors) {
			if(typeof DD_belatedPNG == "undefined") {
				return;
			}
			else {
				$(window).load(function() {
					DD_belatedPNG.fix(selectors);
				});
			}
		},
		$html = $("html");
		
	$html.addClass("js-enabled");
	hasFlash && $html.addClass("flash-enabled");
	
	// On document ready:
	$(function() {
		var $body = $("body");

		//modify logo link for mobiles
		var isMobile = navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/Android/i);
		if (isMobile) {
			var $logo = $('h1 a');
			var _href = $logo.attr('href') + '?mobile=false';
			$logo.attr('href', _href);
		}

		// Open in a new window:
		$("a.external").attr({
			target: "_blank",
			title: function() {
				var t = this.title,
					tInfo = $(this).text() + " (opens in new window)";
				if(t && t != tInfo) { return t + " " + tInfo; }
				return tInfo;
			}
		});
		//extra tweak to footer
		$('#ge-info a').not('.external').each(function() {
			$(this).attr('title',$(this).text());
		});
		
		$("a.copyright_external").attr({
			target: "_blank",
			title: function() {
				now = new Date   
			    theYear=now.getYear()   
			    if (theYear < 1900)   
			    theYear=theYear+1900  

				var copy = unescape("%A9");
				var tc = this.title,
					tcInfo = copy + " " + theYear + " General Electric Company (opens in new window)";
				if(tc && tc != tcInfo) { return tc + " " + tcInfo; }
				return tcInfo;
			}
		});
		//extra tweak to footer
		$('#ge-info a').not('.copyright_external').each(function() {
			$(this).attr('title',$(this).text());
		});
			
		// Extra accessibility features, according to WAI-ARIA specification:
		$("h1").attr({"role": "banner"});
		$("#content").attr({"role": "main"});
		$("#footer div:last").attr({"role": "contentinfo"});
		$("#header-report ul, #header-section ol, #footer ol").attr({"role": "navigation"});

		//pagination
		$('.pagination').append('<div class="paging-caption" />');
		
		$('.pagination a').each(function() {
			var $this = $(this);
			//store title then reset
			$this.attr({
				'data-title': $this.attr('title'),
				'title': ''
			})		
		}).hover(function() {
			var $this = $(this);
			if($this.hasClass('current-page')) {
				return;
			}
			var $caption = $(this).parents('ol').siblings('.paging-caption');
			$caption.html($(this).attr('data-title'));
		},function() {
			var $caption = $(this).parents('ol').siblings('.paging-caption');
			$caption.html('');
		});
		
		// Fade in financial highlights
		// 2009 summary
		$('#financial-highlights-link').click(function() {
			var $target = $($(this).attr('href'));
			$target.fadeIn();
			return false;
		}).hover(function(){
			isIE ? $(".financial-highlights p").show() : $(".financial-highlights p").fadeTo("fast", 1.0);
		},function(){
	   		$(".financial-highlights p").hide();
		});
		// patent filings
		$('#patent-filings-link').click(function() {
			var $target = $($(this).attr('href'));
			$target.fadeIn();
			return false;
		}).hover(function(){
			isIE ? $(".patent-filings p").show() : $(".patent-filings p").fadeTo("fast", 1.0);
		},function(){
	   		$(".patent-filings p").hide();
		});
		// delivering on technology investments
		$('#delivering-investments-link').click(function() {
			var $target = $($(this).attr('href'));
			$target.fadeIn();
			return false;
		}).hover(function(){
			isIE ? $(".delivering-investments p").show() : $(".delivering-investments p").fadeTo("fast", 1.0);
		},function(){
	   		$(".delivering-investments p").hide();
		});
		
		$('#close-financial-highlights').attr('alt','Close').click(function() {
			$('#'+$(this).attr('data-target')).fadeOut();
		});
		$('#close-patent-filings').attr('alt','Close').click(function() {
			$('#'+$(this).attr('data-target')).fadeOut();
		});
		$('#close-delivering-investments').attr('alt','Close').click(function() {
			$('#'+$(this).attr('data-target')).fadeOut();
		});
		
		// Swap background on table row hover
		$("table.data tbody tr").hover(function(){
			$(this).toggleClass("hover_");
		});
		
	});
	
	// Cufon font-replacement:
	Cufon.replace("#header-report ul a, div.item .pullquote, h3.related-content-title, .letter-head");
	Cufon.replace("button", {
		forceHitArea: TRUE
	});
	Cufon.replace("#header-section a, #footer ol a", {
		hover: TRUE
	});
	Cufon.replace("#header-section h2, div.item .intro > p, .story-title, .subtitle, .story-links li a", {
		fontFamily: "GEInspiraBook"
	});
	Cufon.replace("#instructions > p", {
		fontFamily: "GEInspiraBook",
		hover: TRUE
	});
	
	// IE6 helpers:
	pngfix("#home .splash-nav, #home .splash-nav li, #home div.detail, #home div.detail-content, #renew .share-this-header a, #renew .share-links a");
	isIE6 && document.createElement("abbr");
})(jQuery);
