$(function(){

	$("div#topslide").hide();
	$("div#topslide").css({height: '350px'});

	$(".top_button").click(function(){
		
		$("div#topslide").slideToggle();
		
		if($(this).hasClass('current')) {
			$("a",this).empty().append("SHOW");
			$(this).removeClass('current');
		} else {
			$("a",this).empty().append("HIDE");
			$(this).addClass('current');
		}
		
	});	


	$(".mslide_button").click(function(){
		$("div#mastheadslide").animate({
			height: "350px"
		})
		.animate({
			height: "250px"
		}, "fast")
		.css({
			'padding-top' : '1em',
			'background-color' : 'yellow'
		});		
		$(".mslide_button").toggle();

	});	

   $("#hide_mslide").click(function(){
		$("div#mastheadslide").animate({
			height: "0px",
			paddingTop : "0em"
		}, "fast")
		.css({
			'background-color' : '#fff'
		});
   });	   
   



    // for The Search Bar
	swapValues = [];
	$(".swap_value").each(function(i){
		swapValues[i] = $(this).val();
		$(this).focus(function(){
			if ($(this).val() == swapValues[i]) {
				$(this).val("");
			}
		}).blur(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swapValues[i]);
			}
		});
	});
   
   
	
	// Drop Menu
	$("#dropmenu > li > a + ul").before("<span class=\"menuexpand\">+</span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	$("#dropmenu span.menuexpand").click(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul:first").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});		
	

   
	$("#dropmenu ul > li ul").css({display: "none"}); // Opera Fix
	$("#dropmenu li ul li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn("fast");
	},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
   
	
	
	
	// DYNAMIC TABS	
	$(".tabs").tabs({ fx: { height: 'toggle', opacity: 'toggle' } });




	//QTIP
	$('ul#dropmenu > li a[title]').not("ul#dropmenu li ul li a[title]'").qtip({ 
		style: { name: 'dark', tip: true},
		position: {
		  corner: {
			 target: 'bottomMiddle',
			 tooltip: 'topMiddle'
		  }
		},
		show: { 
			effect: 'fade',
			length: '500'
		},		
		hide: { 
			effect: 'fade',
			length: '500'
		}	   
	});	

		
		
	$('.children_content').each(function(i) {
		//$(this).append(i.toString());

		var targetclass = $(this).children().attr('id');
		//$(this).append(targetclass);

		$('#'+targetclass+' .media_grouping').hoverIntent(
			function() { $('#'+targetclass+' .media_controls').fadeIn(); },
			function() { $('#'+targetclass+' .media_controls').fadeOut(); }  
		);



		////// JCycle Plulgin Stuff
		// Hide all the controls
		$('#'+targetclass+' .media_controls').hide();
		$('.pause').click(function() { $('.'+targetclass+' .media_assets').cycle('pause'); return false; });
		$('.play').click(function() { $('.'+targetclass+' .media_assets').cycle('resume'); return false; });

		// Check for hover over media elemetns


		// Initiate JCycle
		$('#'+targetclass+' .media_assets').cycle({
			fx:     'fade',
			speed:   400,
			next:   '#'+targetclass+' .next',
			prev:   '#'+targetclass+' .prev',
			timeout: 700,
			nowrap: 0 		
		});


		// Make sure it starts off paused
		$('#'+targetclass+' .media_assets').cycle('pause');		
	});
	
	
	
	// Sticky Footer
	positionFooter(); 
	function positionFooter(){
		if($(document.body).height() < $(window).height()){
			$("#footer").css({position: "absolute",top:($(window).scrollTop()+$(window).height()-$("#footer").height())+"px"})
		}	
	}

	$(window).scroll(positionFooter).resize(positionFooter)
	
		

});










	













Cufon.replace('.datebox', { fontFamily: 'helvetica rounded' } );
Cufon.replace('#page h2', { fontFamily: 'helvetica rounded' } );
//Cufon.refresh('#extra');