/*

	CUDGC Main Javascript File

*/

/*

	Cufon Replacement

*/

Cufon.replace('#nav', {
	fontFamily: 'myriad',
	hover: true
});

Cufon.replace('.current-menu-item, .current-menu-parent', {
	fontFamily: 'myriad',
	textShadow: '0px 1px #8fc1dd'
});

Cufon.replace('.current-menu-item ul a', {
	fontFamily: 'myriad',
	textShadow: '0px 0px #8fc1dd',
	hover: true
});

Cufon.replace('#nav ul ul a', {
	fontFamily: 'myriad',
	hover: true
});

Cufon.replace('#footer', {
	fontFamily: 'myriad',
	textShadow: '0px -1px #fff',
	hover: true
});

Cufon.replace('h2', {fontFamily: 'myriad-condensed'});
Cufon.replace('h3')('h4')('h5');

Cufon.now();

/*

	Nivo Slider

*/

if(jQuery('#slider').length){

/*
	jQuery('#slider').nivoSlider({
		effect:'fade',
		slices: 1,
		directionNav: false,
		directionNavHide: true,
		controlNav: false,
		pauseOnHover:false
	});
*/

}

/*

	Sub Nav
	We want to show the current pages' subnav (if available)
	
	We also want to show new subnavs on click

*/

var cont = true;
var width = 0;
var top = 0;

/*

	The subnav doesn't line up with the left edge perfectly because it's
	nested inside the li.
	
	This function grabs the total widths of nav items before the current page
	and moves the subnav that many pixels to the left

*/

jQuery('#nav > ul > li').each(function(i, el){
	
	/*
	
		If we are active we need to stop the loop
	
	*/
	
	if(jQuery(el).hasClass('current-menu-item') || jQuery(el).hasClass('current-menu-parent')){
		
		/*
		
			For IE 7 we also need to add the total width of the current
			element to the total width
		
		*/
	
		if($.browser.msie && $.browser.version.substr(0,1) <= 7){
			width += jQuery(el).width();
		}
	
	}
	

	/*
	
		Otherwise we add to the total width
	
	*/
	
	
	
	if(jQuery(el).children('ul').length){

		var child = jQuery(el).children('ul');	

		child.css('margin-left', '-' + width + 'px');
		
	}
	
	width += jQuery(el).width();	

});

function fade_out_current(){

	jQuery('ul.active').fadeOut().removeClass('active');
	

}

jQuery('#nav li a').hover(
	function(){
		
		var parent = jQuery(this).parent();
		
		if(parent.children('ul').length && !parent.children('ul').hasClass('active')){
			fade_out_current();
			parent.children('ul').delay(500).fadeIn();
			parent.children('ul').addClass('active')
		}
	
	},
	function(){
	
	}
);

//jQuery('.current-menu-item > ul, .current-menu-parent > ul').css('margin-left', '-' + width + 'px');
jQuery('.current-menu-item > ul, .current-menu-parent > ul').css('display', 'block');
jQuery('.current-menu-item > ul, .current-menu-parent > ul').addClass('active');

/*

	Contact Form OverText

*/

jQuery('.wpcf7-form input[type=text]').each(function(i, el){

	var self = jQuery(this);
	var default_val = self.val();
	
	self.focus(function(){
	
		if(self.val() == default_val){
		
			self.val('');
			self.addClass('edited');
		
		}
	
	});
	
	self.blur(function(){
		
		if(self.val() == default_val || self.val() == ''){
		
			self.val(default_val);
			self.removeClass('edited');
		
		}
		
	});

});
