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

	/****************************************************************************************************
		Primary Menu Functionality
	****************************************************************************************************/
	$('.primary_sub_nav').hide();  // hide all sub-nav menus by default
	var menuVars = {
		menu_delay: 300,
		last_primary_hover: '',
		current_primary_hover: '',
		current_sub_hover: ''
	};
	$('.primary_nav_item').mouseenter(function(){
		menuVars.current_primary_hover = $(this).attr('id');
		$(this).doTimeout('primary_hover', menuVars.menu_delay, function(){
			menuVars.last_primary_hover = $(this).attr('id');
			$(this).addClass("over");
			$('#primary_sub_'+$(this).attr('id')).data({closing: false}).fadeTo("fast",0.85);
		});
	});
	$('.primary_nav_item').mouseleave(function(){
		$(this).doTimeout('primary_hover', menuVars.menu_delay, function(){
			menuVars.current_primary_hover = '';
			if( menuVars.last_primary_hover != menuVars.current_sub_hover ) {  
				$(this).removeClass("over");
				$('#primary_sub_'+$(this).attr('id')).data({closing: true}).fadeOut("fast");
			}
		});
	});

	$('.primary_sub_nav').mouseenter(function(){
		var id_parts = $(this).attr('id').split("_");
		var parent_nav_item = $('#'+id_parts[2]);
		menuVars.current_sub_hover = id_parts[2];
		if( parent_nav_item.data('closing') ) {
			$(this).stop(true,true);
		}
		if( !parent_nav_item.hasClass('over') ) {
			parent_nav_item.addClass('over');
		}
	});
	$('.primary_sub_nav').mouseleave(function(){
		var id_parts = $(this).attr('id').split("_");
		var parent_nav_item = $('#'+id_parts[2]);
		$(this).doTimeout('primary_sub_hover', menuVars.menu_delay, function(){
			if( menuVars.current_sub_hover != menuVars.current_primary_hover ) {
				$(this).fadeOut("fast");
				$(parent_nav_item).removeClass("over");
			}
			menuVars.current_sub_hover = '';
		});
	});




	/****************************************************************************************************
		Internal Content Menu Functionality
	****************************************************************************************************/
	$('.content_menu_linkstop').hide();
	$('.content_menu_linkstop:eq(0)').show(); {
	}
		$('.content_menu_links1').hide();
	if( $('.content_menu_button:first').next().is(':hidden') == true ) {
		$('.content_menu_button:first').addClass('on');
		$('.content_menu_button:selected').next().slideDown();
		$('.content_menu_links1:eq(1)').show();
	}
		$('.content_menu_links2').hide();
	if( $('.content_menu_button:first').next().is(':hidden') == true ) {
		$('.content_menu_button:first').addClass('on');
		$('.content_menu_button:selected').next().slideDown();
		$('.content_menu_links2:eq(2)').show();
	}
		$('.content_menu_links3').hide();
	if( $('.content_menu_button:first').next().is(':hidden') == true ) {
		$('.content_menu_button:first').addClass('on');
		$('.content_menu_button:selected').next().slideDown();
		$('.content_menu_links3:eq(3)').show();
	}
	$('.content_menu_button').hover(function(){$(this).addClass('over');},function(){$(this).removeClass('over');});
	$('.content_menu_button').click(function(){
		$('.content_menu_button').removeClass('on');  // remove 'on' class from all buttons
		$('.content_menu_links').slideUp();  // close all menus no matter what
		// if the next menu isn't open, then open it 
		if( $(this).next().is(':hidden') == true ) {
			$(this).addClass('on');  // turn on this button
			$(this).next().slideDown(); // open the closest menu
		}
		});
		/****************************************************************************************************
		Accordion
	****************************************************************************************************/
$('.accordion').accordion({ 
	autoHeight: false ,
	collapsible: true ,
	navigation: true ,
	active: -1 });
	 
	$('.accordiontwo').accordion({ 
	autoHeight: false ,	
	collapsible: true ,
	navigation: true ,
	active: 2 });
	 
	$('.accordionone').accordion({ 
	autoHeight: false ,	
	collapsible: true ,
	navigation: true ,
	 active: 1 });  
	 
	$('.accordionadd').accordion({ 
	autoHeight: false ,
	collapsible: true ,
	navigation: true ,
	active: -1 })
	
	$('.accordionfirst').accordion({ 
	autoHeight: false ,
	collapsible: true ,
	navigation: true ,
	active: 0 })
	
	$('.accordionfourth').accordion({ 
	autoHeight: false ,	
	collapsible: true ,
	navigation: true ,
	 active: 3 });
	 
	 $('.accordionsixth').accordion({ 
	autoHeight: false ,	
	collapsible: true ,
	navigation: true ,
	 active: 4 });
	/****************************************************************************************************
		Pop Up Menu (channel listings, etc)
	****************************************************************************************************/
	var pkg_more_parts = [];
	var pkg_more = '';
	$('.pkg_more').hide();  // hide them all
	$('.pkg_more_link').click(
		function(){
			// console.log($(this).attr('id'));
			pkg_more_parts = $(this).attr('id').split('_');
			pkg_more = $('#'+pkg_more_parts[0]+"_"+pkg_more_parts[1]);
			pkg_more.slideToggle();
		}
	);


	/****************************************************************************************************
************************************ 
	/****************************************************************************************************
		get links with "external" class to open in new tab / window
	****************************************************************************************************/

	// get links with "external" class to open in new tab / window
	$('a.external').live('click', function(e){
		$(this).blur()
		window.open($(this).attr('href'));
		return false;  // prevent default action
	});





});
	

