//*****Replace align attribute with class**************************************************//
function replaceAlign() {
  if (!document.getElementsByTagName('img')) return false;
  $('img[align="left"]').addClass('left').removeAttr('align');
	$('img[align="right"]').addClass('right').removeAttr('align');
	$('img[align="middle"]').addClass('middle').removeAttr('align');
}
//*****Replace target attribute with class**************************************************//
function replaceTarget() {
  if (!document.getElementsByTagName('a')) return false;
  $('a[target]').addClass('newwindow').removeAttr('target');
}
//*****Clear search text out search box on focus**************************************************//
function clearSearchBox() {
	$('#txtSearch').focus(function() {
    if ($(this).val() == 'SEARCH') {
      $(this).val('');
	  }
  });
	$('#name').focus(function() {
    if ($(this).val() == 'NAME') {
      $(this).val('');
	  }
  });
	$('#ydurlh-ydurlh').focus(function() {
    if ($(this).val() == 'EMAIL') {
      $(this).val('');
	  }
  });
	$('#txtEmail').focus(function() {
    if ($(this).val() == 'EMAIL ADDRESS') {
      $(this).val('');
	  }
  });
	$('#txtemail').focus(function() {
    if ($(this).val() == 'EMAIL ADDRESS') {
      $(this).val('');
	  }
  });
	$('#txtPassword').focus(function() {
    if ($(this).val() == 'PASSWORD') {
      $(this).val('');
	  }
  });
}
//*****Add swfobject flash call**************************************************//
function initializeFlash() {
	if (!document.getElementById('flash-content')) return false;
	var flashvars = {};
	var params = {wmode: 'transparent'};
	var attributes = {};
	attributes.id = "flash-content";
	swfobject.embedSWF("swf/flash-home.swf", "flash-content", "745", "254", "8.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}
//*****Alternate row color on the search results**************************************************//
function alternateSearchColor() {
  $('.courses table.mp3Info tr:odd').addClass('odd');
  $('.courses table.mp3Info tr:even').addClass('even');
}
//*****Alternate row color on the search results**************************************************//
function mp3Switch() {
  $('.courses table.mp3Info tr td a.button-listen').click(function () {
    if ($(this).hasClass('button-listen')) {
      $('.courses table.mp3Info tr td a.button-playing').addClass('button-listen');
      $('.courses table.mp3Info tr td a.button-playing').removeClass('button-playing');
      $('.courses table.mp3Info tr td a.button-listen').text('Listen');
      $(this).removeClass('button-listen');
      $(this).addClass('button-playing');
      $(this).text('Playing');
    }
    return false;
  });
}
//*****homepage image carousel**************************************************//
function carouselLite() {
  if (!document.getElementById('jCarouselLite')) return false;
  $('.jCarouselLite').jCarouselLite({
    btnNext: '.next',
    btnPrev: '.prev',
    visible: 3,
    easing: 'easeinout',
    speed: 1000,
    mouseWheel: true,
    scroll: 3
  });
}
//*****Extend the footer to the bottom of the page**************************************************//
function extendFooter() {
  var footerHeight = $('#footer').height();
  var pageHeight = $(document.body).height();
  var windowHeight = $(document).height();
  var difference = windowHeight - pageHeight;
  if (pageHeight < windowHeight) {
    $('#footer').height(footerHeight + difference);
  } else {
    $('#footer').height('52px');
  }
}
//********************************Reveal/Toggle on click*********************************//
function revealCopy() {
  $('div.toggle').hide();
  $('p.reveal').addClass('inactive');
  $('.revealCopyWrap p.reveal').click(function () {	
	$(this).toggleClass('inactive');
	$(this).toggleClass('active');
  	$(this).parent().find('div.toggle').slideToggle();
  });
}
//********************************MyClassroom scripts*********************************//
function myClassroom() {
  $('table.myClassroom tr:odd').addClass('odd');
  $('table.myClassroom tr:even').addClass('even');
  //
  $('div.tabWrap').each(function (i) {
    $(this).hide();
  });
  $('ul.myClassroomTab li a').each(function (i) {
    $(this).attr('id','callTable' + i);
  });
  $('ul.myClassroomTab + div.tabWrap').show();
  
	$('ul.myClassroomTab li a').click(function(){
    $(this).parent().parent().children('li').children('a').each(function (i) {
      $(this).removeClass('selected');
    });
    $(this).parent().parent().parent().children('div').each(function (i) {
      $(this).hide();
    });
    $(this).addClass('selected');
    var position = $(this).attr('id').substr(9,2) - 0;
	  $('div.tabWrap:eq('+position+')').show();
	  return false;
	});
	//
	if ($('table.hidden').length == 1) {
	  var table = $('table.hidden');
    var position = table.position();
    $('.courses #main #registerNowOverlay').css({'left' : position.left - 20 + 'px', 'top' : position.top + 'px', 'width' : table.width() + 'px', 'height' : table.height() + 'px'});
  }
}
function trackGiving() {
	$('a#gwsblnk,li#gwsblnk a').click(function(e){
		var linkLocation = window.location.host + window.location.pathname.replace("/", "_")
		pageTracker._trackPageview('/giveonline/'+ linkLocation)
	})
}

//*****Load all functions**************************************************//
$(document).ready(function(){
  replaceAlign();
  replaceTarget();
  clearSearchBox();
  initializeFlash();
  alternateSearchColor();
  mp3Switch();
  carouselLite();
  extendFooter();
  revealCopy();
  myClassroom();
  trackGiving();
});
/*
  jQuery External Links Tracker Plugin
  Copyright (C) 2010 Paradigm New Media Group
  http://pnmg.com | http://github.com/pnmg/jquery-external-links-tracker
  GPL v2 license. See source file for more info.
*/
(function(a){a(document).ready(function(){var b=window.location.hostname;b=b.split(".");if(b.length==1){b=b[0]}else{if(b.length==4&&window.location.hostname.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)){b=window.location.hostname}else{b=b[b.length-2]+"."+b[b.length-1]}}a("a[href*='"+b+"'],a[href^='/'],a[href^='./'],a[href^='../']").live("click",function(c){if(a(this).hasClass("newwindow")){c.preventDefault();if(window.console){window.console.log("Internal link not tracked as outging: "+a(this).attr("href"))}window.open(a(this).attr("href"))}});a("a[href^='http']:not([href*='"+b+"'])").live("click",function(f){f.preventDefault();var c=this.href.replace(/^(http|https):\/\//,"").replace(/www\./i,"").replace(/\./gi,"_");var d="/outgoing/"+c;if(typeof(pageTracker)!="undefined"){pageTracker._trackPageview(d);if(window.console){window.console.log("Tracked external link: "+d)}}else{if(typeof(_gat)=="object"){_gaq.push(["_trackPageview",d]);if(window.console){window.console.log("Tracked external link: "+d)}}else{if(window.console){window.console.log("Could not track external link: "+d)}}}window.open(a(this).attr("href"))})})})(jQuery);

