$jQ(document).ready(function() 
{
	$jQ('a[href^=http:]').click(function(event){ 
		var server = $jQ(this).attr("href").split("/");
		if( server[2] != "www.gereports.com" && server[2] != "www2.gereports.com" && server[2] != "stagegereports.geready.com" && server[2] != "previewinsidege.corporate.ge.com"){
			window.open(this.href,'window',''); return false; 
		}
	});
	
	$jQ('.widget h2.widgettitle a.rsswidget img').css("display","none");
	$jQ('#rss-5 h2.widgettitle a.rsswidget').attr("href","http://ge.geglobalresearch.com/blog/");
	$jQ('#rss-5 h2.widgettitle a.rsswidget').click(function(){window.open(this.href,'window',''); return false; });
	$jQ('#rss-4 h2.widgettitle a.rsswidget').attr("href","http://www.healthymagination.com/blog/");
	$jQ('#rss-4 h2.widgettitle a.rsswidget').click(function(){window.open(this.href,'window',''); return false; });	
	
	$jQ("#commentform").validate({
		rules:{
			author: "required",
			email:{
				required: true,
				email: true
			},
			comment: "required",
			accept: "required"
		},
		messages:{
			author: "Please enter your name.",
			email:{
				required: "Please enter a valid e-mail address.",
				email: "Please enter a valid e-mail address."
			},
			comment: "Please enter a comment.",
			accept: "Please accept GE's Blogging Policy."
		},
		highlight: function(element) {
			if($jQ(element).attr("name") != "accept" ){
				$jQ(element).css('border', '2px solid #FF0000');
			}
		},
		unhighlight: function(element) {
			$jQ(element).css('border', '2px solid #DDDDDD');
		},
		errorLabelContainer: "#messageBox",
		wrapper: "li"
		/*submitHandler: function() {
			var arrayPageURL = new Array();
			var pageURL = s.g_pageURL;
			arrayPageURL = pageURL.split("/");
			if(s.campaign!=""){
				tracklink("true", "o", "Commented - " + s.campaign + " - "+ arrayPageURL[3]);
				alert("here");
			}
			$jQ("#commentform").submit();
		}*/
	});
	
	$jQ("#subscribe").validate({
		rules:{
			"Email Address":{
				required: true,
				email: true
			}
		},
		messages:{
			"Email Address":{
				required: "Please enter a valid e-mail address.",
				email: "Please enter a valid e-mail address."
			}
		},
		highlight: function(element) {
			$jQ(element).css('border', '2px solid #FF0000');
		},
		unhighlight: function(element) {
			$jQ(element).css('border', '2px solid #DDDDDD');
		},
		errorLabelContainer: "#messageBox",
		wrapper: "li"
	});
	
	var url = "";
	url = getParam("statussubscribe");
	if(url){
	
	if(url[1] == "success"){
		$jQ('#messageBox').replaceWith('<ul id="messageBox"><li style="color:#555555;font-weight: bold;">Thank you for your information. Please complete your subscription by clicking the Confirm link in the email we are sending you.</li></ul> ');
		$jQ('#subscribe').css('display','none');
		$jQ('.text_s').css('display','none');
	}
	
	if(url[1] == "invalid"){
		
		var errCode = getParam("errorcode");
		var errText ="Please enter a valid e-mail address."
		if(errCode){
			if( errCode[1] == "1" || errCode[1] == "6" || errCode[1] == "7" || errCode[1] == "9" || errCode[1] == "10" ){
				errText = "An error has occurred while attempting to save your subscriber information.";
			}
			if( errCode[1] == "2" ){
				errText = "The list provided does not exist.";
			}
			if( errCode[1] == "3" ){
				errText = "Information was not provided for a mandatory field";
			}
			if( errCode[1] == "4" ){
				errText = "Invalid information was provided.";
			}
			if( errCode[1] == "5" ){
				errText = "Information provided is not unique.";
			}
			if( errCode[1] == "8" ){
				errText = "Subscriber already exists.";
			}
			if( errCode[1] == "12" ){
				errText = "The subscriber you are attempting to insert is on the master unsubscribe list or the global unsubscribe list.";
			}
			if( errCode[1] == "14" ){
				errText = "The query string contains ETsubscriberKey and the Subscriber Key feature is not enabled on your account.";
			}
		}
		$jQ('#messageBox').replaceWith('<ul id="messageBox"><li>'+errText+'</li></ul>');
		
	}
	
	if(url[1] == "confirmed"){
		$jQ('#messageBox').replaceWith('<ul id="messageBox"><li style="color:#555555;font-weight: bold;"><h3>Thank you for subscribing to GE Reports.</h3></li></ul> ');
		$jQ('#subscribe').css('display','none');
		$jQ('.text_s').css('display','none');
	}
	
	}
	
	//$jQ('#sidebar ul li.widget').css('margin-bottom','20px');
	
	$jQ(window).load(function() {
		$jQ(".small_img_wtext img").each(function(){
			var imgWidth = $jQ(this).width();
			$jQ(this).parent().css({'width':imgWidth});
		});
	});
	
	/*Share widget to the left of the content - scroll*/
	var currentScrollTop = 0; 
	var winHeight = $jQ(document).height() - 750  ;
	
	$jQ(window).scroll(function() {
		currentScrollTop = $jQ(window).scrollTop() + 150;
		if(currentScrollTop < winHeight){
			$jQ("#menu_container").css("margin-top", currentScrollTop+"px");	
		}else{
			$jQ("#menu_container").css("margin-top", winHeight+"px");
		}
    });
	
	/*Image gallery Plugin Call*/
	$jQ('.imagePlugin').click(function(event){
		$jQ(this).showBigImage();
	});
	
	/* CLOSE gallery Plugin Call*/
	$jQ(".closeImageDiv").live("click", function(event){	
		$jQ('.imageContainerDiv').slideUp("slow", function() { $jQ(this).remove(); });
		setTimeout(function() {$jQ('.imageContainer').remove();},600);
		return false;
	});
	
});

(function( $jQ ){
  $jQ.fn.showBigImage = function() {
  
    var hrefBigImage = $jQ(this).attr('src').split("/");
	var hrefBigImage2 = hrefBigImage[hrefBigImage.length-1].split(".");
	var bigImage = hrefBigImage2[0]+"_Big."+hrefBigImage2[1];
	var src="http://";
	for(var i=2; i<hrefBigImage.length-1; i++){
		src+=hrefBigImage[i]+"/";
	}
	src+=bigImage;
	
	$jQ("<div class='imageContainer'><div class='closeDiv' id='closeDiv'><div><div class='divLargerImage'><a class='closeImageDiv textLargerImage'>close</a></div></div></div><div class='opacityDiv' align='center'></div><div class='imageContainerDiv' align='center'><img border='0' src='"+src+"'></div></div>").insertBefore('#page');
	if ($jQ("div:display").is(":none")) {
		$jQ(".imageContainerDiv").slideDown("slow");	
	}

  };
})( jQuery );

function getParam(name){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	return results;
}


