$("document").ready(function(){

    //classes
    $('#metanav li li:first-child, #nav li li:first-child, #subnav li li:first, #content .header-container li li:first').addClass('first');
	$('#nav > li:last, #nav li li:last-child, #footer .sitemap a:last').addClass('last');
	$('#nav li li:has(ul) > a').append('<span class="dd-arrow"></span>');
			
	//other
	if ($('#articles ul.media li').length == 0){
					$('#articles .media').remove();
	}
	
	if ($('ul#subnav li').length == 0){
					$('.subnav').remove();
	}

  
  	//metanav search
	$('.search-btn').click(function() {
		// keep a reference to the slide-toggle element
    var slideToggle = this;
    if ($('.search-box').is(':visible')) {
        $('.search-box').slideUp(function() {
            $(slideToggle).removeClass('active'); // remove class from slide-toggle
        });
    }
    else {
        $('.search-box').slideDown();
        $(slideToggle).addClass('active'); // add class to slide-toggle
    }
		});
   
   // limit character length for metanav blog
   $('#metanav .featured-blog-feed p a').each(function(){
    if ($(this).text().length > 18) {
      newText = ($(this).text()).substr(0, 21);
      $(this).text(newText + "…");
    }
    
  });
  
  	  // limit character length for metanav events
   $('#metanav .events .feature p a').each(function(){
    if ($(this).text().length > 30) {
      newText = ($(this).text()).substr(0, 33);
      $(this).text(newText + "…");
    }
    
  });
			
 	 //clear and restore search fields
	 $('#searchForm input#search_term').val('Enter Keyword(s) or Search Term');

	 $('#newsletter_submit').wrap('<p id="nls_wrap"></p>');
	 $('#search_term, #search_term2').removeClass('clearClick').addClass('clickClear');
	 $('#newsletter_text').removeClass('clearClick').addClass('clickClear');
   // avr 2011-06-09 ... changed to 'live' to manipulate google custom search
	 $('.clickClear').live('focus', function() {
	    startText = $(this).val();
	    $(this).val('').addClass('focus');
	 });
	 $('input.clickClear').live('blur', function() {
	    blurText = $(this).val();
	    if (blurText == '') {
	       $(this).val(startText).removeClass('focus');
	    };
	 });
	 
	//initiate nivo slider for ministries
    $(window).load(function() {
    	$('#slider').nivoSlider({
    	effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        animSpeed:700, // Slide transition speed
        pauseTime:7000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:false, // Next & Prev navigation
        pauseOnHover:true, // Stop animation while hovering
        });
	});
	 
	 //colorbox settings
	$('.login .thickbox, #comments .thickbox').colorbox({iframe:true,width:400, height:250});
	$('.slideshow').colorbox({
		slideshow:true,
		photo:true,
		preloading:true,
		slideshowSpeed:5000,
		slideshowAuto:false
		});
	$('.rsvp .thickbox, #subnav .thickbox').colorbox({iframe:true,width:450, height:570});
	$('#options .thickbox,.section .thickbox').colorbox({iframe:true,width:500, height:570});
	$(".staff-ministries-colorbox").colorbox({width:"630", inline:true});
   
   //media players
	
	$("a.videoplayer").monkmediapopup({ 
       	file:"href",
       	width:"560",
       	height:"315",
       	playlist:"true",
       	autostart:"true",
       	type:"video",
       	stretching:"fill",
       	image:"id"
      });
	 
	 $("a.audioplayer").monkmediapopup({ 
	   file:"href",
	   width:"480",
       height:"270",
	   playlist:"true",
	   autostart:"true",
	   type:"sound",
	   stretching:"fill",
	   image:"id"
	 });

	
});
