$(document).ready(function($) {
	if($('.MainStage').length != 0) {
		revealMainStage();
	}
	if($('.Gallery_Grid').length != 0) {
		profileGrid();
	}
	if($('.ServiceGridContainer').length != 0) {
		serviceGrid();
	}
	if($('.FlyoutGridContainer').length != 0) {
		flyoutGrid();
	}
	if($('.Gallery_SliderRow').length != 0) {
		gallerySlideshow();
	}
	
})

function revealMainStage() {
	var CurtainLeft = $('.Curtains div.Left');
	var CurtainRight = $('.Curtains div.Right');
	var MainStage = $('div.MainStage');
	CurtainLeft.css("left", "0px");
	CurtainRight.css("right", "0px");
	MainStage.hide();
	var ie = ieDetect();
	if(ie == true) {
		MainStage.css("clip", "rect(0px, 490px, 260px, 490px)").show().delay(250).animate({clip: 'rect(0px,758px,260px,222px)'}, 1250,'swing');
	} else {
		MainStage.css("clip", "rect(0px, 490px, 260px, 490px)").css("opacity", "0").show().delay(250).animate({clip: 'rect(0px,758px,260px,222px)', opacity: '1'}, 1250,'swing');
	}
	CurtainLeft.delay(250).animate({left: "-268px"}, 1250,'swing');
	CurtainRight.delay(250).animate({right: "-268px"}, 1250,'swing');
}

function profileGrid() {
	var GalleryContainer = $('.Gallery_Grid');
	var GalleryPortraits = $('.Gallery_Grid .Portrait');
	var GalleryProfileData = $('.ProfileContainer');
	var GalleryProfiles = $('.ProfileContainer .Profile');
	if(GalleryPortraits.hasClass('active')) {
		GalleryPortraits.removeClass('active');
	}
	$('.Thumbnail a').die("click");
	GalleryProfiles.hide();
	GalleryPortraits.bind({
		click: function(){
			var PortraitID = "#" + $(this).attr('id') + "Record";
			var CurrentProfile = $('.ProfileContainer .Profile .active');
			var TargetProfile = $('.ProfileContainer .Profile' + PortraitID);
			var ProfileContainer = $('.ProfileContainer');

			if(TargetProfile.hasClass('active') == false) {
				GalleryProfiles.removeClass('active').hide();
			}


			GalleryProfiles.filter(PortraitID).addClass('active').show();
			GalleryPortraits.removeClass("Current");
			$(this).addClass("Current");
			return false;
		},
		mouseenter: function(){
			var CurrentThumbnail = $(this).find('.Thumbnail');
			CurrentThumbnail.fadeOut(300);
		},
		mouseleave: function(){
			var CurrentThumbnail = $(this).find('.Thumbnail');
			CurrentThumbnail.fadeIn(100).stop(false,true);
		}
	}).filter('.NoClick').unbind();
}
function serviceGrid() {
	var ServiceGridContainer = $('.ServiceGridContainer');
	var ServiceGridNodes = $('.ServiceGridNode');
	var ServiceGridNodesRight = $('.ServiceGridNode:nth-child(4n) .ServiceGridContent');
	var ServiceGridLinks = $('.ServiceGridContent').children('a');
	ServiceGridNodes.removeClass('active').css("cursor","pointer");
	ServiceGridNodesRight.addClass('Right');
	ServiceGridLinks.die("click");
	ServiceGridNodes.bind({
		click: function(){
			$(this).removeClass('active');
			$(this).children('.ServiceGridContent').children('.ServiceGridDetail').hide();
			$(this).children('.ServiceGridContent').css({'height' : '40px', 'width' : '152px'}).stop();
			$(this).find('.CloseLink').hide();
		},
		mouseenter: function(){
			$(this).children('.ServiceGridContent').animate({
				width: '382px'
			},500,'swing').css('height', 'auto').children('.ServiceGridDetail').slideDown(500, 'swing');
			$(this).addClass('active');
			$(this).find('.CloseLink').slideDown(100);
			
		},
		mouseleave: function(){
			$(this).find('.CloseLink').hide();
			$(this).children('.ServiceGridContent').children('.ServiceGridDetail').hide();
			$(this).children('.ServiceGridContent').css({'height' : '40px', 'width' : '152px'}).stop();
			$(this).removeClass('active');
		}
	});
	
}

function flyoutGrid() {
	var GridContainer = $('.FlyoutGridContainer');
	var GridNodes = $('.GridNode');
	var GridNodesRight = $('.GridNode:nth-child(4n) .GridContent');
	var GridLinks = $('.GridContent').children('a');
	GridNodes.removeClass('active').css("cursor","pointer");
	GridNodesRight.addClass('Right');
	GridLinks.die("click");
	GridNodes.bind({
		click: function(){
			$(this).removeClass('active');
			$(this).children('.GridContent').children('.GridDetail').hide();
			$(this).children('.GridContent').css({'height' : '80px', 'width' : '152px'}).stop();
			$(this).find('.CloseLink').hide();
		},
		mouseenter: function(){
			$(this).children('.GridContent').animate({
				width: '382px'
			},500,'swing').css('height', 'auto').children('.GridDetail').slideDown(200, 'swing');
			$(this).addClass('active');
			$(this).find('.CloseLink').slideDown(100);
			
		},
		mouseleave: function(){
			$(this).find('.CloseLink').hide();
			$(this).children('.GridContent').children('.GridDetail').hide();
			$(this).children('.GridContent').css({'height' : '80px', 'width' : '152px'}).stop();
			$(this).removeClass('active');
		}
	});
}

function gallerySlideshow() {
	$('#Slideshow').cycle({ 
			fx:     'scrollHorz', 
			speed:  1000, 
			timeout: 5000, 
			next:   '.SliderControls .Next',
			prev:   '.SliderControls .Previous' 
		});
}

function ieDetect() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		return true;
	} else {
		return false;
	}
}

// Timeline jQuery //
$(document).ready(function($) {
  $('.DateTop').mouseover(function() {
	$(this).addClass('active');
	$(this).next('.PopupContainer').show();
  });
  $('.DateTop').mouseleave(function() {
	$(this).removeClass('active');
	$(this).next('.PopupContainer').hide();
  });
  $('.DateBtm').mouseover(function() {
	$(this).addClass('active');
	$(this).next('.PopupContainerBtm').show();
  });
  $('.DateBtm').mouseleave(function() {
	$(this).removeClass('active');
	$(this).next('.PopupContainerBtm').hide();
  });
});

