$(document).ready(function() {		
    
    //SERMON Tracking
    $('.jp-download').click(function(){
        _gaq.push(['_trackEvent', 'Sermons', 'Downloaded', $(this).text()]);  
    });    
    
    $('.jp-play').click(function(){
        _gaq.push(['_trackEvent', 'Sermons', 'Play', $(this).closest('li').children('.jp-download').text()]); 
    });
    
    $('.jp-pause').click(function(){
        _gaq.push(['_trackEvent', 'Sermons', 'Pause', $(this).closest('li').children('.jp-download').text()]);  
    });        
    
    // hide all pages
    $('.page_two_column, .page_one_column').hide();
    
    
    if ($('#contact-us').length > 0) {
        $('#contact-us').show();
    } else {
        //show only home
        $('#home').show();          
    }
    
    // Clear search bar on click and add/remove class
    var defaultValue = $('.widget-container #s').val();
    $('.widget-container #s').click(function(){
        $('.widget-container #s').removeClass("blur");
        if(this.value == defaultValue){
            $('.widget-container #s').val("");
        }
        return false;
    });
    $('.widget-container #s').blur(function(){
        $('.widget-container #s').addClass("blur");
        if(this.value == ""){
            $('#s').val(defaultValue);
        }
    });  
    
    // address click
    $('#address_link').click(
      function () {
        window.open('http://maps.google.com/?q=28325+Kemptown+Road,+Damascus,+MD+20872+Montgomery+United+Methodist+Church')
      }
    );      
    
    // header menu rollover
    $('.menu_images').children('img:nth-child(2)').hide();
    
    $(".menu_images").hover(
      function () {                
        $(this).siblings('div').children('img:nth-child(2)').fadeIn(500); 
      },
      function () { 
        $(this).siblings('div').children('img:nth-child(2)').stop(true, true).fadeOut(500);  
      }
    );   
    
    // header menu click    
    $(".menu_images").click(
      function () {
        $('.page_two_column, .page_one_column').hide();
        
        var id = $(this).attr('id');
        if ( id == 'menu_youth' ) { $('#youth').show(); }
        if ( id == 'menu_ce' ) { $('#christian-education').show(); }
        if ( id == 'menu_mo' ) { $('#mission-outreach').show(); }
        if ( id == 'menu_history' ) { $('#history').show(); }
      }
    );   
    
    // footer menu click    
    $(".menu-footer ul.menu li a").click(
      function () {
        var id = $(this).attr('id');
        if (id.length) {        
            $('.page_two_column, .page_one_column').hide();
            if ( id == 'footer_menu_youth' ) { $('#youth').show(); }
            if ( id == 'footer_menu_ce' ) { $('#christian-education').show(); }
            if ( id == 'footer_menu_mo' ) { $('#mission-outreach').show(); }
            if ( id == 'footer_menu_history' ) { $('#history').show(); }
            if ( id == 'footer_menu_sm' ) { $('#sports-ministry').show(); }   
            if ( id == 'footer_menu_sif' ) { $('#sisters-in-faith').show(); } 
        }                   
      }
    );        
    
    // other menu rollover
    $('#other_menu_sm').hover(
      function () {        
        $(this).addClass('hover'); 
      },
      function () {
        $(this).removeClass('hover');   
      }
    ); 
    
    $('#other_menu_sif').hover(
      function () {        
        $(this).addClass('hover'); 
      },
      function () {
        $(this).removeClass('hover');   
      }
    );     
    
    // other menu click
    $('#other_menu_sm').click(
      function () {
        $('.page_two_column, .page_one_column').hide();
        $('#sports-ministry').show();
      }
    );    
    
    $('#other_menu_sif').click(
      function () {
        $('.page_two_column, .page_one_column').hide();
        $('#sisters-in-faith').show();
      }
    );     
    
    $('#other_menu_cu').hover(
      function () {
        $(this).addClass('hover'); 
      },
      function () {
        $(this).removeClass('hover');   
      }
    );     
    
    // header gallery slideshow
    $('#header_gallery img:gt(0)').hide();
    setInterval(function(){
      $('#header_gallery :first-child').fadeOut()
         .next('img').fadeIn()
         .end().appendTo('#header_gallery');}, 
      7000);

	
});
