YRC = {};

YRC.fancyFlickr = function() {
	$(".flickr-feed a").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayOpacity':	'0.8',
		'overlayColor'  :	'#000',
		'titlePosition' :	'inside'
	});
}

YRC.fancyPhotos = function() {
	$("a[rel=fancybox]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'overlayOpacity':	'0.8',
		'overlayColor'  :	'#000',
		'titlePosition' :	'inside'
	});
}

$(document).ready(function() {
	// Set up the fancybox plugin
	YRC.fancyPhotos();
	
	var hideDelay = null;
	
	// Handle the About submenu
	$("a.nav-about").closest("li").mouseenter(
		function() {
			clearTimeout(hideDelay);
			
			$("#about-submenu").slideDown(500, "easeInOutQuint");
		}
	).mouseleave(
		function() {
			hideDelay = setTimeout(function() {
				$("#about-submenu").slideUp(500, "easeInOutQuint");
				hideDelay = null;
			}, 1000);
		}
	);
	
	$("a[rel*=external]").live("click", 
		function(e) {
			e.preventDefault();
			
			//Find the link target & open it in a new window
			var href = $(this).attr("href");
			window.open(href);
		}
	);
	// Handle the flickr feed
	if ($(".flickr-feed").length) {
		
		$('#our-residential-work-stage').jflickrfeed({
			limit: 100,
			qstrings: {
				id: '65716501@N03',
				tags: 'residential'
			},
			useTemplate: false,
			itemCallback: function(item){
				$(this).append("<li><a rel='fancybox' href='" + item.image + "' title='" + item.title + "'><img src='" + item.image_m + "' alt='" + item.title + "'/><strong>" + item.title + "</strong></a></li>");
			}
		}, YRC.fancyFlickr);
		
		$('#our-commercial-work-stage').jflickrfeed({
			limit: 100,
			qstrings: {
				id: '65716501@N03',
				tags: 'commercial'
			},
			useTemplate: false,
			itemCallback: function(item){
				$(this).append("<li><a href='" + item.image + "' title='" + item.title + "'><img src='" + item.image_m + "' alt='" + item.title + "'/><strong>" + item.title + "</strong></a></li>");
			}
		}, YRC.fancyFlickr);
		
	}	
});

