$(document).ready(function() {
	
	// Initialize drop down menus
	$('ul.sf-menu').superfish();
	
	// HOMEPAGE ONLY 
	// intialize slideshow
	if($('#slideshowHome').length ){
		$('#slideshowHome').cycle({ 
			fx:     'fade', 
			speed:  'slow', 
			timeout: 6000
		});
	}
	
	// Display lightboxed content like video
	if( $(".openLightbox").length) {
		$(".openLightbox").colorbox({iframe:true, innerWidth:"80%", innerHeight:"80%"});
	}

	// Open slideshow from link
	$("body").delegate("a[rel]", "click", function (e) { 

			// Prevent the link from being followed
			e.preventDefault();

			// Initialize variables
			var slideshowId				= $(this).attr("rel");
			
			if (0 == $("#" + slideshowId).length) {
			
				var	slideshowContainer		= $("<div />", {css: {display: "none"}, id: slideshowId}),
					slideshowContainerHtml	= "";
			
				$.getJSON("cache/" + slideshowId + ".json", function (slideshow) { 
				
					$.each(slideshow.items, function (index, slideshowItem) { 
					
						slideshowContainerHtml	+= "<img src='" + slideshowItem.path + "' class='" + slideshowId + "' title='" + slideshowItem.caption + "'  />";
					});
					
					slideshowContainer.html(slideshowContainerHtml);
					
					$("body").append(slideshowContainer);
					
					$("#" + slideshowId + " img").colorbox({href: function () { return $(this).attr("src"); }, width:"75%", height:"85%", open: true, rel: slideshowId, scalePhotos: true});
				});
			}
			else {

				$("#" + slideshowId + " img").colorbox({href: function () { return $(this).attr("src"); }, width:"75%", height:"85%", open: true, rel: slideshowId, scalePhotos: true});			
			}
		});
});
