// Main Functions of Babylon Central
function InitPlayVid(el, src)
	{
		el.click(function(e) {
			//debugger
			e.preventDefault();
			$("#playVideo").addClass("playing");
			$("#playVideo").flashembed({ 
				src:"flash/MBRVideoPlayer.swf",
				width: 641,
				height: 359,
				wmode: "transparent"
			   }, { 
				src: src,
				themeColor: "b50000" 
			});							   
		});	
	}
//Open Current Page | Default: Home
function openPage(page) {
	if(page+".current") {
		page.children(".pageContent").slideDown(800);		
	} 
}

//Accordion Function
function initAccordion(activators, sliders)
{
	activators.click(function (e) {
		   e.preventDefault();
		   $(this).parent().next().slideToggle();
		   $("div.current").removeClass("current");
		   $(this).parent().parent().addClass("current");
		   $(this).parent().parent().toggleClass("active")		
		   if($("#playVideo").hasClass("playing")) {
				 $("object").replaceWith("<a href=\"#\"><img src=\"images/album_cover.png\" border=\"0\" /></a>");
				 $("#playVideo").removeClass("playing");
				  InitPlayVid($("#playVideo a"), "http://babyloncentralfilm.com/flash/BabylonCentralTrailer_16x9_640x360_800k.f4v");
				  InitPlayVid($("#playInterview"),"http://babyloncentralfilm.com/flash/erichiltonintrobabyloncentral-youtube_16x9_640x360_800kbps.f4v");
				 
		   }
		   if($(this).parent().parent().hasClass("active")){
			   var elementClicked = $(this).attr("href");
				var destination = $(elementClicked).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-145}, 1000 );
				$("div.current").removeClass("current");
				$(this).parent().parent().addClass("current");
				return false;   
		   } else {}
   });
}

//Special Links
function specialLinks(activator, slide) {
		activator.click(function(e) {
			e.preventDefault();
			if(slide.hasClass("active")) {
				var elementClicked = activator.attr("href");
				var destination = $(elementClicked).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-145}, 1000 );	
				$("div.current").removeClass("current");
				slide.addClass("current");

			} else {
				var elementClicked = activator.attr("href");
				var destination = $(elementClicked).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-145}, 1000 );
				slide.children(".pageContent").slideToggle();
				slide.toggleClass("active");
				$("div.current").removeClass("current");
				slide.addClass("current");
			}
		});
}

//Up and Down Arrows
function initUpDown(selector,direction) {
	selector.click(function(e) {
		e.preventDefault();
		var current = $("div.current");
		if(direction == "up") {
			if(current == $("div#home.current")) {
				// Do nothing	
			} else {
				var elementClicked = current.prev();
				if($("#playVideo").hasClass("playing")) {
				 $("object").replaceWith("<a href=\"#\"><img src=\"images/album_cover.png\" border=\"0\" /></a>");
				 $("#playVideo").removeClass("playing");
				 InitPlayVid($("#playVideo a"), "http://babyloncentralfilm.com/flash/BabylonCentralTrailer_16x9_640x360_800k.f4v");
				 InitPlayVid($("#playInterview"),"http://babyloncentralfilm.com/flash/erichiltonintrobabyloncentral-youtube_16x9_640x360_800kbps.f4v");
		  		}
				if(elementClicked.hasClass("active")) {
					var destination = elementClicked.offset().top;
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-145}, 1000);
					elementClicked.addClass("current");
					current.removeClass("current");	
				} else {
					var elementClicked = current.prev();
					var destination = elementClicked.offset().top;
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-145}, 1000);
					elementClicked.addClass("current");
					current.removeClass("current");
					elementClicked.children(".pageContent").slideToggle();
					elementClicked.toggleClass("active");
				}
			}
		} else {
			if(current == $("div#contact.current")) {
				//Do nothing	
			} else {
				var elementClicked = current.next();
				if($("#playVideo").hasClass("playing")) {
				 $("object").replaceWith("<a href=\"#\"><img src=\"images/album_cover.png.jpg\" border=\"0\" /></a>");
				 $("#playVideo").removeClass("playing");
				 InitPlayVid($("#playVideo a"), "http://babyloncentralfilm.com/flash/BabylonCentralTrailer_16x9_640x360_800k.f4v");
				 InitPlayVid($("#playInterview"),"http://babyloncentralfilm.com/flash/erichiltonintrobabyloncentral-youtube_16x9_640x360_800kbps.f4v");
		  		}
				if(elementClicked.hasClass("active")) {
					var destination = elementClicked.offset().top;
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-145}, 1000);
					elementClicked.addClass("current");
					current.removeClass("current");	
				} else {
					var elementClicked = current.next();
					var destination = elementClicked.offset().top;
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-145}, 1000);
					elementClicked.addClass("current");
					current.removeClass("current");
					elementClicked.children(".pageContent").slideToggle();
					elementClicked.toggleClass("active");
				}
			}
		}
		
	});
}
$(document).ready(function() {
	// Get height of Wrapper
	openPage($("#home"));
	initAccordion($('h2 a'));
	//initAccordion($('#navigation a'));
	
	// Special Links
	specialLinks($("#navigation a"), $("#contact"));
	specialLinks($("#eric"), $("#bio"));
	specialLinks($("#backTop a"), $("#home"));
	
	// Up and Down
	initUpDown($("#up"), "up");
	initUpDown($("#down"), "down");
	
	// Cufon Replace
	Cufon.replace("#header ul li a, #backTop a", { fontFamily: 'HelveticaNeue-BoldCond' });
	Cufon.replace("h2 a", { fontFamily: 'HelveticaNeue-BoldCond' });
	Cufon.replace('#home h3, #about h3, #about h4, #bio h3, #production h3, #contact h3, #soundtrack h3', { fontFamily: 'helv_cond' });
	
	$("a.productionShots").fancybox({
		'transitionIn':	'elastic',
		'transitionOut':	'fade',
		'speedIn':	500,
		'speedOut':	800,
		'overlayColor':	'#000'
	});
	
	$("#viewTrailer").click(function(e) {
		$("#playVideo").addClass("playing");
		e.preventDefault();
		$("#playVideo").flashembed({ 
			src:"flash/MBRVideoPlayer.swf",
			width: 641,
			height: 359,
			wmode: "transparent"
		   }, { 
			src: "http://babyloncentralfilm.com/flash/BabylonCentralTrailer_16x9_640x360_800k.f4v",
			themeColor: "b50000" 
		});									 
	});
	$("#playInterview").click(function(e) {
		$("#playVideo").addClass("playing");
		e.preventDefault();
		$("#playVideo").flashembed({ 
			src:"flash/MBRVideoPlayer.swf",
			width: 641,
			height: 359,
			wmode: "transparent"
		   }, { 
			src: "http://babyloncentralfilm.com/flash/erichiltonintrobabyloncentral-youtube_16x9_640x360_800kbps.f4v",
			themeColor: "b50000" 
		});									 
	});
	
	//InitPlayVid($("#playVideo a"), "http://babyloncentralfilm.com/flash/BabylonCentralTrailer_16x9_640x360_800k.f4v");
	InitPlayVid($("#playInterview"),"http://babyloncentralfilm.com/flash/erichiltonintrobabyloncentral-youtube_16x9_640x360_800kbps.f4v");
	
	//Hover Images
	$(".productionGallery ul li").hover(function() {
		$(this).children(".overlay").fadeIn(500);
	}, function() {
		$(this).children(".overlay").fadeOut(500);	
	});
});
