﻿
function decrypt(s) {
  var input = s;
  var out = "";
  
  for (i=0; i<input.length;i++) {
    current = input.charAt(i);
    charCode = input.charCodeAt(i);
    if ( ( (charCode > 96) && (charCode < (97+26) ) ) || ( (charCode > 64) && (charCode < 91) ) ){
      if ( (charCode > (96 + 13) ) || ( (charCode > (64 + 13) ) && (charCode < 91) ) ) {
        newCode = charCode - 13;
      }
      else {
        newCode = charCode + 13;
      }
      
      out += String.fromCharCode(newCode);
    }
    else {
      out += current;
    }
  }
  
  return out;
}

function newWindow(loc,prot,pwidth,pheight) {
  if (pwidth == null){pwidth = "775"};
  if (pheight == null){pheight = "550"};

  protocol = "http://";
  if (+prot == 1) {
    protocol = "https://";
  }
  else if (+prot == 2) {
    protocol = "";
  
  }
  windowName = "window" + new Date().getTime();
  theWindow = window.open((protocol + decrypt(loc)),windowName,"width=" + pwidth + ",height=" + pheight + ",resizable=no,location=no,scrollbars=yes,status=yes");
  theWindow.focus();
}

//Constituent Homepage Background Cross-fading
var homebg = ["bg1", "bg2", "bg3"];
var fader;
var current = 0;
function xfade(){
	var next = current + 1;
	if(next == homebg.length){
		next = 0;
	}
	fader.attr("class",homebg[next]);
	fader.fadeIn(1500, function(){
		$('body').removeClass(homebg[current]);
		current = next;
		$('body').addClass(homebg[current]);
		fader.hide();
		setTimeout("xfade()",10000);
	});
}


$(document).ready(
	function() {

		// Open links with rel="external" in new window - like ye ole' target="_blank"
		$('a[rel="external"]').click(function() {window.open( $(this).attr('href') ); return false;});
		
	}
);

function stripeTable(_table) {
  $('tbody tr:odd', _table).removeClass('even').addClass('odd');
  $('tbody tr:even', _table).removeClass('odd').addClass('even');
}

