/*
* @name: 	functions.site.js
* @desc:	JQuery Site Interaction
* @author: 	Matt Kircher
* @modified: 	8.3.10
*/

/* GENERAL */
function setupPage(){
		
	//feature specific settings
	addBrowserQuirks();
	
	//content header proximity (b/c it's easier with jQuery)
	$('#content :header:gt(0)').not('.subhead').css({ marginTop:'30px' });
	
	// navigation dropdowns
	$('#main-nav ul')
	.addClass('sf-menu')
	.supersubs({
		minWidth:    6,   	// minimum width of sub-menus in em units 
		extraWidth:  1	// extra width can ensure lines don't sometimes turn over 
                               	// due to slight rounding differences and font-family 
	})
	.superfish({			// call supersubs first, then superfish, so that subs are 
					// not display:none when measuring. Call before initialising 
					// containing tabs for same reason.
		delay: 700,
		animation: {opacity:'show', height:'show'},
		speed: 'fast',
		autoArrows: true,
		dropShadows: false,
		pathClass: 'selected',
		pathLevels: 999,
		onInit: function(){
			
			//remove top arrows
			$('#main-nav > ul > li > a')
			.removeClass('sf-with-ul')
			.find('span').remove(); 
			
			//activate Cufon once the menus 
			//are built if not we're not an IE client
			if($.support.leadingWhitespace){
				
				$('#main-nav').animate({ opacity:1 }, 1500);
				
				Cufon.replace("#main-nav a", { 
					fontWeight:400, 
					fontFamily:"Helvetica Neue", 
					hover:true, 
					forceHitArea:true 
				});
				Cufon.now();
			}
			
			//for IE, so superfish doesn't shutter/flicker
			$('#main-nav').css({ visibility:'visible' });
		}
	});
}

function addBrowserQuirks(){
	
	//safari & chrome
	if(window.devicePixelRatio){
		$('#contact-info .facebook, #contact-info .twitter').css({ top:'-8px' });
		$('#contact-info').css({ marginBottom:'5px' });
	}
	
	//ipad / ipod / iphone
	if((navigator.userAgent.indexOf('iPhone') >= 0) || 
	   (navigator.userAgent.indexOf('iPod') >= 0) || 
	   (navigator.userAgent.indexOf('iPad') >= 0)){
		$('body').addClass('iproduct');
	}
	
	//anything but IE
	if(jQuery.support.leadingWhitespace){
		$('#main-nav').css({ opacity:0 });	
		
		$('.sf-menu li li').css({ opacity:'0.85' });
	}
	
	//only IE
	if(!jQuery.support.leadingWhitespace){
		//for IE, so superfish doesn't shutter/flicker
		$('#main-nav ul').css({ visibility:'visible' });
		
		/*IE6 :first-child CLASSES*/
		$('#masthead-gallery ul:eq(0)').addClass('first_child');
		$('#main-nav > ul').addClass('first_menu');
		$('#main-nav > ul > li:eq(0)').addClass('first_child first_menu_item');
		$('#main-nav > .sf-menu > li:eq(0), #main-nav > .sf-menu > li.sfHover:eq(0)').addClass('first_child');
		$('#footer-nav li:eq(0), #corporate-links li:eq(0)').addClass('first_child')
		$('#main-nav > ul').addClass('top_menu');
	}
}

function doFontReplacement(){
	
	//anything but IE
	if(jQuery.support.leadingWhitespace){
		Cufon.replace("#callout p, #press-quotes, #footer-nav li.unaccented, #contact-info, #corporate-links, #content :header", { fontWeight:400, fontFamily:"Helvetica Neue", hover:true, forceHitArea:true });
		Cufon.replace("#footer-nav li.accented", { fontFamily:"Trixie Text", hover:true });
	}
	
	//only IE
	if(!jQuery.support.leadingWhitespace){
		Cufon.replace("#footer-nav li.accented", { fontFamily:"Trixie Text", hover:true });
	}
}

/* INITIALIZATION */
$(document).ready(function(){
	setupPage();
});

