// JavaScript Document

$(document).ready(function() {
						   
 var isExpanded = false;
 
 var openHeight = $("#popupContainer").height();
	
 openHeight -= 30;
	
  $("#lightbox").hide();
  $("#popupContainer").hide();

  $(".newsPushContentWrap").hide();
  
  $("#lightbox").show();
	
	$("#popupContainer").show();
  
  	$("#popupContainer").animate({width:"500px", height:"150px" }, function() {
		$(".newsPushContentWrap").fadeIn('slow');
	});
	
	jQuery.fn.center = function () 
	{
		this.css("position","absolute");
		this.css("left", "50%");
		this.css("marginLeft", "-406px");
		return this;
	}

	

	
	
	/*************** READ MORE FULLY EXPAND *******************/
	
	$(".newsPushReadMore").click(function () {
	   if(!(isExpanded))
		{
				expandFully();		
		}
 	})
	
	function expandFully()
	{
		isExpanded = true; 
		
		$("#popupContainer").animate({width:"800px", height:"500px"});
		$("#popupContainer").center();
		$(".newsPushHeader").animate({width:"790px"})
		$(".pushContentWrap").css({	overflow: "auto"})
		$('.pushContentWrap').animate({height:"400px"})
		
		// Once expanded provide user ability to print the article
		
		$(".newsPushReadMore").html('Print &raquo;');
		$(".newsPushReadMore").attr('title','Print »');
		$(".newsPushReadMore").addClass('printNews');
		$(".newsPushReadMore").removeClass('newsPushReadMore');
		
		$('.printNews').click(function () {
					$('#popupContainer').jqprint();  						
		})
		
		

	}

/*****************************************************/
	$(".newsPushClose").click(function () {
	   closePush();		
 	})

$("#lightbox").click(function () {
		closePush();
})

$(document).keypress(function(e) {
if (e.keyCode == '27') {
	closePush();
	}
 })

/*****************************************************/
  
  function closePush()
  {
  		if ($(".newsPushContentWrap").is(":visible")) {
			
  			$("#popupContainer").animate({marginTop: "-="+$(this).height()},1000, function() {
				 $("#lightbox").fadeOut();
			})
		
  		}
  }
  
 });
