//modal for charts
$(document).ready(function() {	
	$('a[name=modal]').click(function(e) {
		e.preventDefault();
		var id = $(this).attr('href');
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.6);	
		var winH = $(window).height();
		var winW = $(window).width();
		$(id).css('top', winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
		$(id).fadeIn(2000); 	
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		$('#mask').hide();
		$('.window').hide();
	});		
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});

// hide and show for financial results sidebar
$(function() {
	//individual header hover toggle
	$('#financial .pdf-links div.report').hover(function(){
		//hide all open document types and remove active class
		$('div.type').hide();
		$('#financial .pdf-links div.report a').removeClass('active');
		//open the div if it is closed and add the active class
		var clickedTwice = $(this).children('a').hasClass('active');
		if(clickedTwice==0)
		{
			$(this).children('a').addClass('active');
			$(this).children('div.type').show();
		}
    	}, function() { 
			$('div.type').hide();
			$('#financial .pdf-links div.report a').removeClass('active');
		});	
}); 


//hoverIntent for delay of share pop-up close
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

//modal for share
$(document).ready(function() {	
	$('a[name=share]').click(function(e) {
		e.preventDefault();
		var id = $(this).attr('href');
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		$('#share-mask').css({'width':maskWidth,'height':maskHeight,'top':0, 'left':0}).fadeIn(0).fadeTo("slow",0.2);
		$(id).slideDown(300); 
	});
	
	$('#share-links a').click(function (e) {
		$('#share-mask').hide();
		$('#share-links').slideUp();
	});	
	
	$('#share-mask').click(function () {
		$(this).hide();
		$('#share-links').slideUp();
	});	

	// when mouse is off the share box, it closes after a delay
	$("#share-mask").hoverIntent(disappear,stay);
	$("#share-mask").hoverIntent({
		sensitivity: 7, 
		interval: 1300, 
		over: disappear, 
		timeout: 500, 
		out: stay
	});
	
});

function disappear(){ $(this).hide();$('#share-links').slideUp() ;}
function stay(){ }

// share icons
function message() {
	var t = $('h1').eq(0).text();   /*  grabs the title via h1 tag */
    var u = window.location.href;  /*  grabs the page url */
	var j = "Johnson %26 Johnson Annual Report"
	var message = document.write('<ul><li class="email"><a href="javascript:emailtoFriendIRR()" title="E-mail to a Friend">E-mail to a Friend</a></li><li class="delicious"><a href="http://del.icio.us/post?url='+u+'&title='+t+'" title="Add to Delicious" target="_blank">Delicious</a></li><li class="digg" title="Digg this Page"><a href="http://digg.com/submit?phase=2&url='+u+'&title='+t+'" target="_blank">Digg</a></li><li class="diigo"><a href="http://www.diigo.com/post?url='+u+'&title=<?php the_title(); ?>" title="Share on Diigo" target="_blank">Diigo</a></li><li class="facebook" title="Share on Facebook"><a href="http://www.facebook.com/share.php?u='+u+'" target="_blank">Facebook</a></li><li class="linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&url='+u+'&title='+t+'" title="Share on LinkedIn" target="_blank">LinkedIn</a></li><li class="mixx"><a href="http://www.mixx.com/submit?page_url='+u+'" title="Share on Mixx" target="_blank">Mixx</a></li><li class="myspace"><a href="http://www.myspace.com/Modules/PostTo/Pages/?c='+u+'&t=<?php the_title(); ?>" title="Share on MySpace" target="_blank">MySpace</a></li><li class="twitter"><a href="http://twitter.com/home/?status='+u+'" title="Share on Twitter" target="_blank">Twitter</a></li><li class="yahoo"><a href="http://buzz.yahoo.com/buzz?targetUrl='+u+'&headline='+t+'" title="Share on Yahoo" target="_blank">Yahoo! Buzz</a></li></ul><br class="clear" /><p class="message">By clicking on a link above, you will leave www.jnj.com. The terms-of-use and privacy policies on other sites may differ from those on www.jnj.com.</p>'); 
}


// email page
function emailtoFriendIRR(objvalue){
var stagEurl = "http://www.jnj.com";
var siteurl = "";
var winDowOpen = window;
var newWindow = '';

if(objvalue == 'A'){

siteurl = stagEurl + "/wps/wcm/jsp/emailToFriend.jsp";
}else{

siteurl = stagEurl + "/wps/wcm/jsp/emailToFriend.jsp";
}
var mylocation = winDowOpen.parent.location; 
newWindow = window.open(siteurl+"?q="+mylocation,"mywindow","height=428px,width=391px,margin=0px,top=180px,left=240px,resizable=no, location=0, directories=no, status=0, title=no, border=0");
//newWindow = window.open("www.tcs.com");

newWindow.focus();

}


// text sizer (not jquery)
var contentClickCount=0;
var footerclickCount=0;

function performTextReSize()
{
  
  increaseTextSizeById('content',contentClickCount);
  increaseTextSizeById('footer',footerclickCount);
  
  
}

function increaseTextSizeById(divId,clickCount)
{
  if(document.getElementById(divId))
 { 
   
   if(divId=='content')
   clickCount=contentClickCount;
   else if (divId=='footer')
   clickCount=footerclickCount;
  
   clickCount=clickCount+1;
   var bodyElement="";
   if(document.getElementById(divId))
   bodyElement = document.getElementById(divId);
   if(clickCount==1)
   {
    
    bodyElement.style.fontSize="1.25em" ;
    if(document.getElementById("textReSizeClick"))
    document.getElementById("textReSizeClick").innerHTML="1.25em";
   }
   else if(clickCount==2)
   {
    bodyElement.style.fontSize="1.5em" ;
    if(document.getElementById("textReSizeClick"))
    document.getElementById("textReSizeClick").innerHTML="1.5em";

    
   }
   else if(clickCount==3)
   {
    bodyElement.style.fontSize="1em" ; 
    if(document.getElementById("textReSizeClick"))
    document.getElementById("textReSizeClick").innerHTML="1em";

   }
   if(clickCount==3)
   clickCount=0;	
   if(divId=='content')
   contentClickCount=clickCount;
   else if (divId=='footer')
   footerclickCount=clickCount; 
      
 }
}
