sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
         if (document.getElementById("sermonLists")) {
            document.getElementById("sermonLists").style.visibility="hidden";
         }
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			if (document.getElementById("sermonLists")) {
            document.getElementById("sermonLists").style.visibility="visible";
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function wmvPopup (filename, width, height){
 window.open('http://www.fellowshipnashville.com/wmvPopup.php?theFile='+filename+'&w='+width+'&h='+height,'_mediaplayer','width='+width+',height='+height);
}

function wmvPopup2 (filename,width,height){
 window.open(filename,'_mediaplayer','width='+width+',height='+height);
}



function popitup(url) {
 window.open(url,'_fellowshipOne','width=719,height=621,top=100,left=100,resizeable=yes,scrollbars=yes,menubar=no,status=no,location=no');
}

function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}


/* Created by Martin Hintzmann 2008 martin [a] hintzmann.dk
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 *
 * Version: 0.1
 *
 * Requires:
 *   jQuery 1.2+
 */
(function($) {
	$.fn.boxShadow = function(xOffset, yOffset, blurRadius, shadowColor) {
		if (!$.browser.msie) return;
		return this.each(function(){
			$(this).css({
				position:	"relative",
				zoom: 		1,
				zIndex:		"2"
			});
			$(this).parent().css({
					position:	"relative"
			});
			
			var div=document.createElement("div");
			$(this).parent().append(div);

			var _top, _left, _width, _height;
			if (blurRadius != 0) {
				$(div).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius="+(blurRadius)+", enabled='true')");
				_top = 		yOffset-blurRadius-1;
				_left =		xOffset-blurRadius-1;
				_width =		$(this).outerWidth()+1;
				_height =	$(this).outerHeight()+1;
			} else {
				_top = 		yOffset;
				_left =		xOffset;
				_width = 	$(this).outerWidth();
				_height = 	$(this).outerHeight();
			}
			$(div).css({
				top: 			_top,
				left:			_left,
				width:		_width,
				height:		_height,
				background:	shadowColor,
				position:	"absolute",
				zIndex:		1
			});
			
	  });
	};
})(jQuery);


$(document).ready(function(){
  $("li#nav_students ul li").each(function(){
    $(this).remove();
  });
  var newLinks = "<li><a href='/students/home' title='FSM Home'>FSM Home</a></li>" +
                 "<li><a href='/students/the-mix' title='The Mix'>The Mix</a></li>" +
                 "<li><a href='/students/the-foundry' title='The Foundry'>The Foundry</a></li>";
  
  $("li#nav_students ul").append(newLinks);
    
  $("li.minGuide a").click(function(){
    $("#minGuide").slideToggle();
    $(this).closest("ul").toggleClass("active");
    return false;
  });

  $("#nav_contact").nextAll("li").remove();
  $("#nav_adults_inversion-young-adults_contact-us").nextAll("li").remove();
  $("#nav_students_contact-us").nextAll("li").remove();
  
  $(".footerLinks li:first").addClass("first");
  $(".footerLinks li:last").addClass("last");
  
  /*var path = location.pathname;
  var pathLength = (path.length) - 1;
  path = path.substring(0, pathLength);
  if ( path ) {
   $('#sbRight .section a[href$="' + path + '"]').attr('class', 'selected');
   $('#sbLeft .quickLinks a[href$="' + path + '"]').attr('class', 'selected');
   $('#sermonNav a[href*="' + path + '"]').parent().attr('class', 'current');
   var eventPath = path.split("/");
   $('#sbRight .event a[href*="' + eventPath[2] + '"]').parent().remove();
  }*/
  
  //since the anchor tag title attribute is same as event title we can compare both and remove
  $("#sbRight .event").find("a").each(function(){
	//window.console.log($(this)); 
	     if($("h2.ptitle").text() === $(this).attr("title")){  
           $(this).parent().parent().remove();
		}
	});
  

  // CLEAN UP OUTPUT
  if(!$('.mediabox li').length) {
    $(".mediabox").remove();
  };
  
  $('li.td_video').each(function(){
    
    if($(this).hasClass('hasFlv')) {
      
      var onclickVal = $(this).find("a").attr("onclick").toString();
      var fnBodyString = onclickVal.match(/\bhttp\:\/\/[a-z0-9\/\:\.\-]+\b/)[0];
      var hasEmbed = fnBodyString.search("my.ekklesia360.com");
      var hasFlv = fnBodyString.search(".flv")
      //console.log("hasEmbed: " + hasEmbed);
      //console.log("hasFlv: " + hasFlv);

      if ((hasEmbed === -1) && (hasFlv === -1)) {
        $(this).remove();
      }
      else {
        $(this).next('li.backupWmv').remove();
      }
    }
  });

  var pFirst = $("#content p:first").html();
  if (pFirst === '') {
    $('#content p:first').remove();
  }


  // SITEMAPS 
  var inversion = $('body.inversion ul.sitemap2 li#sitemap_adults_inversion-young-adults');
    $('body.inversion ul#sitemap').prepend(inversion);
    $('body.inversion ul#sitemap li#sitemap_adults_inversion-young-adults').siblings().remove();
  
  var fsmSitemap = $('body.fsm ul#sitemap li#sitemap_students');
    $('body.fsm ul#sitemap').prepend(fsmSitemap);
    $('body.fsm ul#sitemap li#sitemap_students').siblings().remove();
  

  // CHANGE wmvPopup links
  // href="javascript:void(0);" onclick="wmvPopup('http://fbctnmedia.org/books/genesis/2010.03.21.wmv', 400, 320)
  $("a.wmvpopup, a.wmvPopup").each(function(){
    var file = $(this).attr("href");
    var text = $(this).html();
    var newLink = '<a href=\"javascript:void(0);\" onclick=\"wmvPopup(\''+file+'\', 320, 260)\"">'+text+'</a>';
    $(this).after(newLink);
    $(this).remove();
    // console.log(file);
  })
  
  $("a[href$=wmv]").each(function(){
    var file = $(this).attr("href");
    var text = $(this).html();
    var newLink = '<a href=\"javascript:void(0);\" onclick=\"wmvPopup2(\''+file+'\', 320, 260)\"">'+text+'</a>';
    $(this).after(newLink);
    $(this).remove();
    // console.log(file);
  })

  $("a.f1popup").each(function(){
    var file = $(this).attr("href");
    var text = $(this).html();
    var newLink = '<a href=\"javascript:void(0);\" onclick=\"popitup(\''+file+'\')\"">'+text+'</a>';
    $(this).after(newLink);
    $(this).remove();
    //console.log(file);
  })

  
  
  
  
  $('div#ie6').prependTo('body');
});
