/*
    Initialize Events
    ------------------------------------------------------------------------------------------------------*/ 
    $(document).ready(function(event){
        self.parent.frames.length > 0 	? parent.location = 'http://www.kingdomcounty.org':'';
    
    
        var $site_navigation    		= 0;
    
        $('a[href^="http://"]').bind('click',external_link);
        $('a[rel="submit"]').bind('click',form_submission);
        
        $('#site_navigation').bind('mouseenter',{toggle:1},toggle_navigation);
        $('#site_navigation').bind('mouseleave',{toggle:0},toggle_navigation);
        $('#site_navigation a').bind('mouseenter',{show:1},toggle_navigation);
        $('#page_navigation').bind('mouseleave',{show:0},toggle_navigation);
        
        
        $('#podcast_sections a[rel^="podcast_"]').live('click',podcast_toggle);
    });
    
    
    


/*
    Form Submission
    ------------------------------------------------------------------------------------------------------*/ 
    function form_submission(e){
    	$(this).parents('form:eq(0)').submit();
    
    
    	return false;
    }
    
    
    
/*
    Toggle User Feed
    ------------------------------------------------------------------------------------------------------*/  
    function external_link(event){
        window.open($(this).attr('href'),'KCP',"location=1,status=1,scrollbars=1,width=900,height=500");
        return false;
    }
    

/*
    Toggle Navigation
    ------------------------------------------------------------------------------------------------------*/ 
    function toggle_navigation(event){
        if(event.data.toggle){
            $site_navigation            = event.data.toggle;
        }
        
        else if(event.data.show        == 1){
            var $section                = $(this).attr('rel');
            var $current_section        = $('#site_navigation a.current').attr('rel');
            
            if($current_section        != $section){
                $('#site_navigation a').removeClass('hovered');
                $('#site_navigation a[rel="'+$section+'"]').addClass('hovered');
            
                $('#page_navigation ul:not([type="'+$section+'"])').hide();
                $('#page_navigation ul[type="'+$section+'"]').show();
            } else {
                $('#page_navigation ul.current').show();
                $('#page_navigation ul:not(".current")').hide();
            }
        }
        
        else if(event.data.show        == 0){
            $('#site_navigation a').removeClass('hovered');
            
            if($('#page_navigation ul.current').is(':hidden')){
                $('#page_navigation ul.current').show();
                $('#page_navigation ul:not(".current")').hide();
            } else {
                $('#page_navigation ul:not(".current")').hide();
            }
        }
    }
    
    
    
    
/*
    Podcast Toggle
    ------------------------------------------------------------------------------------------------------*/ 
 	function podcast_toggle(e){
 		$('#podcast_sections a[rel^="podcast_"]').removeClass('current');
 		$(this).addClass('current');
 	
 		$('#current_podcast').load(
 			'/includes/functions/podcasts.function.php?function=podcast_toggle',
 			{'id':$(this).attr('rel').replace('podcast_','')},
 			function(data){
 				$('#page_content h2').text('Selected Podcast');
 				podcast_play($('#podcast_player kbd').text(),$('#current_podcast h3').text());
 			}
 		);
 	
 	
 		return false;
 	}
 	
 	
 /*
    Podcast Play
    ------------------------------------------------------------------------------------------------------*/ 
 	function podcast_play(file,title){
       	var $flashvars   		= {playerID:'1',soundFile:file,autostart:'yes',titles:title,artists:'KCP'};
       	var $params      		= {movie:'/media/player.swf',quality:'high',menu:'false',wmode:'transparent'};
       	var $attributes  		= {};
       	swfobject.embedSWF("/media/player.swf","podcast_player","230","24","8.0.0","expressInstall.swf",$flashvars,$params,$attributes);
 	}
