/*
	Author: Andy Homan
	Date: 14/5/2010
	Version: 1.0
	(c) Process Creative
	www.processcreative.com.au
*/

$(document).ready(function () {   
	var speed = 200;

	/* Drop down Nav */
	
    $('#mainNav li').hover(
        function () {  
            //show its submenu  
            $('ul', this).stop(true, true).slideDown(speed);  
        },   
        function () {  
            //hide its submenu  
            $('ul', this).stop(true, true).slideUp(speed);           
        }  
    );  
	
	/* Gallery - Load fancybox */
	$('a.slide img').mouseover(function() {
       $(this).animate({ 
				backgroundColor: "#E3E6EB", 
				borderTopColor: "#A3ADBE",
				borderLeftColor: "#A3ADBE",
				borderRightColor: "#A3ADBE",
				borderBottomColor: "#A3ADBE"
		}, 'fast');
	});
	$('a.slide img').mouseout(function() {
		$(this).animate({ 
			backgroundColor: "#FFFFFF", 
			borderTopColor: "#DEDEDE",
			borderLeftColor: "#DEDEDE",
			borderRightColor: "#DEDEDE",
			borderBottomColor: "#DEDEDE"
		}, 'fast');
	});
		
	$("a[rel=slide]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
	});
	
	/* Crew load fancybox */
	$("a.overlay, .profile a, body.crew #crew a").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	hashCheck = function(target){
		var loc = window.location.hash;
		$('#subNav a[href='+loc+']').filter(':first').click();
		return false
	}
	
	window.setTimeout(hashCheck, 175);
	
	//hashCheck(); // if being called from an external page

	/* Crew hover effect */
	
	$('div.crewTile').append('<div class="tileOvr" />')

	// find the div.fade elements and hook the hover event
	$('div.crewTile').hover(function() {
		// on hovering over, find the element we want to fade *up*
		var fade = $('> div.tileOvr', this);
		// fade in quickly
		fade.fadeIn(250);
	}, function () {
		// on hovering out, fade the element out
		var fade = $('> div.tileOvr', this);
		// fade away slowly
		fade.fadeOut(250);
	});
	
	/* Drop cap custom kerning */
	
	$dropCaps = $('span.cap')
	
	$.each($dropCaps,function(n) {
		$dCap = $(this);
		if($dCap.index($('span')[0])){
			$dCap.wrapInner("<span />");
		}
		var capContents = $dCap.text();
		var small = new RegExp("I|J");
		var narrow = new RegExp("S|P");
		var medium = new RegExp("X|A|D|H|K|N|O|U|V|Y");
		var large = new RegExp("W|M|A");
		
		if(capContents.match(small)){
			rightKern = 0.6;
		}else if(capContents.match(narrow)) {
			rightKern = 1;
		}else if(capContents.match(medium)) {
			rightKern = 1.5;
		}else if(capContents.match(large)) {
			rightKern = 2;
		} else {
			rightKern = 1.3;
		}
		
		$dCap.css('marginRight',rightKern+'em');
	});
	
});
