/* Text changer - light version.
Let your text's font size customizable.
by Marco Rosella - http://www.centralscrutinizer.it/en/design/js-php/text-changer
                v0.2 - May 18, 2006
*/

window.onload = function(){
	textChanger.init(); 	
     $('#tab000').show();
     HackIssues();
     truncateHomeAudio();
     Popmeup();
     AddExitMsg();
}

function HackIssues()
{
    $('.pageTitle[id*=IssueTitle] ~ br').remove();
    $('.pageTitle[id*=IssueTitle]').remove(); 
    $('table[id*=SocialTagsTable]').remove();
    
    //$('.primary-int').find('a[href$=8297], a[href$=8298], a[href$=8292], a[href$=8293], a[href$=5163], a[href$=4158], a[href$=5165], a[href$=8300], a[href$=8299], a[href$=8294], a[href$=8295], a[href$=8296], a[href$=8288], a[href$=8289], a[href$=8290], a[href$=8291]').before('&nbsp;&nbsp;&nbsp; ');
}

function truncateHomeAudio()
{
    $('#tab3 .tab-text table:eq(2) ~ br').remove();
    $('#tab3 .tab-text table:eq(2) ~ span').remove();
    $('#tab3 .tab-text table:gt(2)').remove();
}

function Popmeup()
{
    if(readCookie('popupSignup') == null)
    {
	    $('#modalPopup').click();
	    createCookie('popupSignup','show',365);
	    createCookie('samesession','true');
	}
	else if(readCookie('popupSignup') == 'show' && readCookie('samesession') == null)
	{
	    $('#modalPopup').click();
	    createCookie('popupSignup','hide',365);
	}
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


var textChanger = {
	cpanel : 'textchanger',  //set here the id of the element (div, p) within you want to insert the control panel
	element : 'pagewidth',   	 //set here the id of the element (div, p) within you want to change the text
	defaultFS : 1,         //set here the default font size in 'em'
	init: function() {
		var cpel = document.getElementById(textChanger.cpanel);
		var el = document.getElementById(textChanger.element);
		if (cpel == null || el == null) {alert('The elements with the \"'+textChanger.cpanel+'\" and/or \"'+textChanger.element+'\" ID do not exist in HTML source.');} else {
		var u = document.createElement('ul');
		cpel.appendChild(u);
		u.innerHTML = 
		'<li id="decrease"><a href="#" title="Decrease font size">A</a></li>'+
		'<li id="reset"><a href="#" title="Default font size">A</a></li>'+
		'<li id="increase"><a href="#" title="Increase font size">A</a></li>'
		var sz = textChanger.getCookie();
		el.style.fontSize = sz ? sz + 'em' : textChanger.defaultFS + 'em';
		var incr = document.getElementById('increase');
		incr.onclick = function(){textChanger.changeSize(1); return false;};
		var decr = document.getElementById('decrease');
		decr.onclick = function(){textChanger.changeSize(-1); return false;};
		var reset= document.getElementById('reset');
		reset.onclick = function(){textChanger.changeSize(0); return false;};
		}
	} ,

	changeSize: function(val) {
		var el = document.getElementById(textChanger.element);
		var size = el.style.fontSize.substring(0,3);
		var fSize = parseFloat(size,10);
		if (val == 1) {
			fSize += 0.11;
			if (fSize > 2.0) fSize = 2.0;
		} 
		if (val == -1) {
			fSize -= 0.11;
			if (fSize < 0.5) fSize = 0.5;
		}		
		if (val == 0) {
			fSize = 1;
		}
		el.style.fontSize = fSize + 'em';
		textChanger.updateCookie(fSize);
		} ,
		
	updateCookie: function(vl) {
		var today = new Date();
		var exp = new Date(today.getTime() + (365*24*60*60*1000)); //the cookie will expire in one year  
		document.cookie = 'textChangerL=size=' + vl + ';' +'expires=' + exp.toGMTString() + ';' +'path=/';
	} ,

	getCookie: function() { 
		var cname = 'textChangerL=size=';	
		var start = document.cookie.indexOf(cname);
		var len = start + cname.length;
		if ((!start) && (cname != document.cookie.substring(0,cname.length))) {return null;}
		if (start == -1) return null;
		var end = document.cookie.indexOf(";",len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	}
}

// JavaScript External Link Exit Message
function exitMsg(){
     var answer = confirm("You are now leaving the Congresswoman Maxine Waters website. Thank you for visiting. Neither my office nor the U.S. House of Representatives is responsible for the content of the non-House site you are about to access.")

if (!answer)
return false;

return true;
//end of Exit Message
}


// Check whether links are external:
// (Only works with elements that have href):
$.extend($.expr[':'],{
    external: function(a,i,m) {
        if(!a.href) {return false;}
        return a.hostname && a.hostname !== window.location.hostname;
    }
});

/* --- Add Exit Message ---*/
function AddExitMsg()
{
    $('a:external').click(function(){
        return(exitMsg());
    });
}
