$(document).ready(function(){
  //EXIT LINK MARKING
  $("a[href^=http]").not(".noIcon").not("a[href$=.pdf]").not("[href*=.edissweb.com]").attr({title: "This link takes you to an external website."}).attr({target: "_blank"}).append("<a href=/'this().attr(href)'/><img src='/images/external.gif' alt='This link takes you to an external website.' width='15' height='11' /></a>");
  //PDF LINK MARKING
  $("a[href$=.pdf]").not(".noIcon").attr({title: "This link opens a PDF document."}).attr({target: "_blank"}).append("<a href=/'this().attr(href)'/><img src='/images/pdf.gif' alt='This link opens a PDF document.' width='27' height='10' /></a>");
  //DOC LINK MARKING
  $("a[href$=.doc]").not(".noIcon").attr({title: "This link opens a Word document."}).attr({target: "_blank"}).append("<a href=/'this().attr(href)'/><img src='/images/doc.gif' alt='This link opens a Word document.' width='27' height='10' /></a>");
  //XLS LINK MARKING
  $("a[href$=.xls]").not(".noIcon").attr({title: "This link opens a Excel document."}).attr({target: "_blank"}).append("<a href=/'this().attr(href)'/><img src='/images/xls.gif' alt='This link opens a Excel document.' width='27' height='10' /></a>");

  //TABLE STRIPING
  $(".tableStripe tr:even").addClass("even");
  $(".tableStripe tr").hover(function(){
	$(this).addClass("tableOver");
  }, function() {
	$(this).removeClass("tableOver");
  });
  //TABLE HOVER
  $(".tableHover tr").mouseover(function() {
	$(this).addClass("tableOver");}).mouseout(function() {
	  $(this).removeClass("tableOver");
  });
  //TABLE HOVER - TD HIGHLIGHT
  $(".tdHover td").hover(function(){
	$(this).addClass("tdOver");
  }, function() {
	$(this).removeClass("tdOver");
  });
  
  //ADD AND REMOVE HOVER CLASS TO SUBMIT BUTTON
  $('.buttontext').live('mouseover', function(){
	$(this).addClass('buttonHover');
  });
  $('.buttontext').live('mouseout', function(){
	$(this).removeClass('buttonHover');
  });
  
  //ADD ACTIVE CLASS TO NAVIGATION
  var path = location.pathname.substring(0);
  if ($('#sec-navi a[href$="' + path + '"]').parents().is('.sub-navi'))
  {
	  $('.sub-navi').removeClass('hide');
	  $('#sec-navi a[href$="' + path + '"]').addClass('active');
  }
  else
  {
	  var paths = (window.location.pathname);
	  paths = paths.split("/");
	  paths = paths.slice(2,3);
	  $('a[href$="/' + paths + '/"]').addClass('active');
  }
    
  //SLIDE TOGGLE, START HIDDEN - SLIDE DOWN - NEXT
  $('.slideContainerNext').removeClass('hide').hide();
  $('a.slideLinkNext').toggle(function(){
	$(this).parent().next().slideDown('fast');
  },function(){
	$(this).parent().next().slideUp('fast');
  });
  //SLIDE TOGGLE, START HIDDEN - SLIDE DOWN - PREV
  $('.slideContainerPrev').removeClass('hide').hide();
  $('a.slideLinkPrev').toggle(function(){
	$(this).parent().prev().slideDown('fast');
  },function(){
	$(this).parent().prev().slideUp('fast');
  });
  
  //POPUP WINDOW - OLD
  function launchwin(winUrl, winName, w, h){
	settings='height='+h+',width='+w+',scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=yes,dependent=no';
	window.open (winUrl, winName, settings);
  }
  //POPUP WINDOW - NEW
  jQuery.fn.popupWindow = function(options) {
	var defaults = {
	width: screen.width/2,
	height: screen.height/2,
	titlebar: false,
	scrollbars: true,
	toolbar: true,
	location: false,
	status: false,
	menubar: false,
	resizable: true,
	dependent: false
	};
	
	var options = jQuery.extend(defaults, options);
		
	Boolean.prototype.setProperty = function() {
	  if (this == true) { return "yes"; } else { return "no"; }
	};
		
	return this.each( function() {
	  jQuery(this).click( function() {
		var target = this.target;
		var href = this.href;
		var posY = (parseInt(screen.height/2)) - (parseInt(options.height/2));
		var posX = (parseInt(screen.width/2)) - (parseInt(options.width/2));
		var win = window.open(href, target, 'titlebar=' + options.titlebar.setProperty() + ', screenX='+ posX +', screenY='+ posY +', left='+ posX +', top='+ posY +', scrollbars=' + options.scrollbars.setProperty() + ', toolbar=' + options.toolbar.setProperty() + ', location=' + options.location.setProperty() + ', status=' + options.status.setProperty() + ', menubar=' + options.menubar.setProperty() + ', resizable=' + options.resizable.setProperty() + ', dependent=' + options.dependent.setProperty() + ', width='+ options.width +', height='+ options.height);
		win.focus();
		return false;
	  });
	});
  };
  //Popup Window - 960px x 600px
  $(".popup960x600").popupWindow({
	width: 960,
	height: 600,
	titlebar: true,
	status: false,
	resizable: true,
	toolbar: false,
	scrollbars: true,
	menubar: false
  });

  //STYLE SWITCHER
  $('.styleswitch').click(function(){
	switchStylestyle(this.getAttribute("rel"));
	return false;
  });
  
  var c = readCookie('style');
  if (c)
  {
	switchStylestyle(c);
  }
  
  function switchStylestyle(styleName){
	$('link[rel*=style][title]').each(function(i) {
	  this.disabled = true;
	  if (this.getAttribute('title') == styleName)
	  {
		this.disabled = false;
	  }
	});
  createCookie('style', styleName, 0);
  }
  // COOKIE FUNCTION FOR STYLE SWITCHER
  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
	{
	  var 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;
  }
  function eraseCookie(name){
	createCookie(name,"",-1);
  }
});
