/* Author: jfreeman | elevatoragency.com */

// Initiate after DOM loads
$(document).ready(function(){
	// check for mobile
	var isAndroid = navigator.userAgent.match(/Android/i) != null;
	var isWebOs = navigator.userAgent.match(/webOS/i) != null;
	var isIphone = navigator.userAgent.match(/iPhone/i) != null;
	var isIpod = navigator.userAgent.match(/iPod/i) != null;
	var isIpad = navigator.userAgent.match(/iPad/i) != null;
	
	// add class to body for mobile
	if (isAndroid) {$('body').addClass('isAndroid')};
	if (isWebOs) {$('body').addClass('isWebOs')};
	if (isIphone) {$('body').addClass('isIphone')};
	if (isIpod) {$('body').addClass('isIpod')};
	if (isIpad) {$('body').addClass('isIpad')};
	

	// turn on elements when dom is ready
		$('#mainNav').css({
			'visibility':'visible',
			'overflow' : 'visible'
		});
				
	// Init on pageload
		var mainNavLi=$('#mainNav > ul').children('li');
		$(mainNavLi[mainNavLi.length-1]).addClass('last');
		$('#trayInner').hide();
		$('ul.sf-menu').superfish({
			delay : 1200,
		  onShow : function(){
		  	$('a.selected').parent().removeClass('sfHover');
		  	$('a.selected').siblings('ul').css({'display':'none','visibility':'hidden'});
		  },
		  onHide : function(){
		  	$('a.selected').parent().addClass('sfHover');
		  	$('a.selected').siblings('ul').css({'display':'block','visibility':'visible'});
		  }
		});
		$('#mainNav > ul > li').hide();
		animatedNavLoad();
		function animatedNavLoad() {
			$('#mainNav > ul > li').delay(1000).each(function(i){
				$(this).delay(200*i).fadeIn('slow');
			});
		}
	
	// display subnav
		$('a.selected').parent().addClass('sfHover');
		$('a.selected').siblings('ul').css({'display':'block','visibility':'visible'});
	
	// build and animate tray
		var originalTrayHeight=$('#tray').height(),
			originalPaddingTop=$('#tray').css('padding-top'),
			originalPaddingBot=$('#tray').css('padding-bottom');
		$('#tray').css({height : '20px','padding' : 0});
		$('#tray').prepend('<span id="trayToggle" class="closed">Show</span>');
		if (document.getElementById('introSlideShow')) {
			introAnimation();
		} else {
			var loadTrayAtStartup=setTimeout('$(document).load().toggleTray("open")',2500);
			$('#trayToggle').click(function(){
				$(this).toggleTray();
			});	
		}
		$.fn.toggleTray = function(which) {
			clearTimeout(loadTrayAtStartup);
			if (which=='open' || $('#tray').height()!=originalTrayHeight) {
				$('#tray').clearQueue().animate({
					'height' : originalTrayHeight + 'px',
					'padding-top' : originalPaddingTop,
					'padding-bottom' : originalPaddingBot
				},'fast','swing',function(){
					$('#trayInner').fadeIn('slow');
					$('#trayToggle').text('Hide').removeClass('closed').addClass('opened');					
				});
				$('#nextSlideButton').fadeOut('fast');
			} 
			else if (which=='close' || $('#tray').height()==originalTrayHeight) {
				$('#trayInner').clearQueue().fadeOut('fast',function(){
					$('#tray').animate({
						'height' : '20px',
						'padding-top' : 0,
						'padding-bottom' : 0
					},'fast','swing', function(){
						$('#trayToggle').text('Show').removeClass('opened').addClass('closed');
					});
				});
				if ($('#videosToggle').hasClass('inactive') || !document.getElementById('videosToggle')) {
					$('#nextSlideButton').fadeIn('fast');
				}
			}
		}
		function introAnimation(callback) {
			var introSlides = $('.introSlide')
			var introSlideText = $('.introSlideText');
			var introSlideImage = $('.introSlideImage')
			$(introSlides[0]).fadeIn(500,function(){
				$(introSlideText[0]).fadeIn(1500,function(){
					$(introSlides[0]).delay(800).fadeOut(2500);
					$(introSlides[1]).delay(800).fadeIn(2500, function(){
						$(introSlideText[1]).fadeIn(1500,function(){
							$(introSlides[1]).delay(500).fadeOut(2500);
							$(introSlides[2]).delay(500).fadeIn(2500, function(){
								$(introSlideText[2]).fadeIn(1500,function(){
									$(introSlides[2]).delay(500).fadeOut(2500);
									$(introSlides[3]).delay(500).fadeIn(2500,function(){
										$(introSlideText[3]).fadeIn(1500,function(){
											$(introSlides[3]).delay(500).fadeOut(2500);
											$(introSlides[4]).delay(500).fadeIn(2500,function(){
												$(introSlideText[4]).delay(800).fadeIn(2500);
												$(introSlideImage[4]).animate({
													'bottom' : '-602px',
													'left' : 0
												},3000,'swing',function(){
									//$(introSlideImage[5]).height(1200);
													$(introSlides[4]).delay(1000).fadeOut(2500);
													$(introSlides[5]).delay(1000).fadeIn(2500,function(){
														$(introSlideText[5]).fadeIn(1500);
														$(introSlideImage[5]).animate({
														    'top' : '-150px',
														    'right' : '-1080px',
														    height : '1200px'
														},3000,'swing',function(){
														    $('#skipIntro').fadeOut('slow');
														    $('#introSlideShow').delay(2500).fadeOut('slow');
														    var introOpenTray = setTimeout(function(){
														    	$('#trayToggle').click(function(){
														    	    $(this).toggleTray();
														    	}).toggleTray('open');	
														    },2700);
														});
													});
												});
											});
										});
									});
								});
							});
						});
					});
				})
			});
		}	
			
	// category nav hovers
		var catNavImages = $('.image');
		$(catNavImages).each(function(){
			$(this).append('<span class="catHover"></span>');
		});
		$('.image').mouseover(function(){
			$(this).children('.catHover').fadeTo('fast',0.5,function(){
				if (!$.support.opacity) {
					$(this).get(0).style.removeAttribute('filter');
				}
			});		
		});
		$('.image').mouseout(function(){
			$(this).children('.catHover').fadeTo('slow',0);		
		});
		
	// map hover
		var thisPoiTop;
		$('.mapPoi span, .poiDotFromDB').mouseenter(function(){
			if (!($(this).parent().hasClass('poiactive'))) {
				var thisPoiInfo = $(this).parent().attr('id') || $(this).attr('id');
					thisPoiInfo = thisPoiInfo.replace('mapPoi','poiInfoWrap');
					thisPoiInfo = thisPoiInfo.replace('poiDotFromDB','poiInfoWrap');
					thisPoiInfo = '#' + thisPoiInfo;
				thisPoiTop = $(thisPoiInfo).css('top');
				thisPoiTop = thisPoiTop.replace('px','');
				$(this).parent().addClass('poiactive');
				if (thisPoiTop==0) {
					$(thisPoiInfo).fadeTo('fast',0.8);
				} else {
					$(thisPoiInfo).stop(true,true).css({
						'display' : 'block',
						'opacity' : 0
					}).animate({
						'opacity' : 0.8,
						'top' : (parseInt(thisPoiTop) + 10) + 'px',
						'left' : $(thisPoiInfo).css('left')
					},'fast','swing');
				}
			}
		});
		$('.mapPoi span, .poiDotFromDB').mouseleave(function(){
			if ($(this).parent().hasClass('poiactive')) {
				var thisPoi = $(this).parent();
				var thisPoiInfo = $(this).parent().attr('id');
					thisPoiInfo = thisPoiInfo.replace('mapPoi','poiInfoWrap');
					thisPoiInfo = '#' + thisPoiInfo;
				var resetPosTop = $(this).parent().css('top');
					resetPosTop = resetPosTop.replace('px','');
					resetPosTop = (parseInt(resetPosTop) - 10) + 'px';
				var resetPosLeft = $(this).parent().css('left');
					resetPosLeft = resetPosLeft.replace('px','');
					resetPosLeft = (parseInt(resetPosLeft) + 20) + 'px';			
				
				var removePoiInfo = setTimeout(function(){
					$(thisPoiInfo).stop(true,true).fadeTo('fast',0,function(){
						$(this).css({
							'top' : resetPosTop,
							'left' : resetPosLeft
						}).hide();
						$(thisPoi).removeClass('poiactive');
					});		
				},0);
			}
		});
	
	
	// panoramic	
		var theSlider = $('#slider'),
			theMovement,
			theDistance;
		
		if (isIpad || isIphone || isIpod) {
			$('.panArrow').click(function(){
	    		var whichOne = $(this).attr('id');
	    		theDistance=700;
				
				var currentPosition = $(theSlider).css('left');
			        currentPosition = currentPosition.replace('px','');
			        currentPosition = parseInt(currentPosition);
			        	     
			    if (whichOne=='panLeft') {
				    $(theSlider).animate({'left' : (currentPosition - theDistance) + 'px'},'slow','swing');
			    } else {
				    $(theSlider).animate({'left' : (currentPosition + theDistance) + 'px'},'slow','swing');
			    }
			});
		} else {
			$('.panArrow').mousedown(function(){
	    		var whichOne = $(this).attr('id');
	    		theDistance=0;
				
				theMovement = setInterval(function(){
					while (theDistance<3) {
						theDistance+=0.1;
					}
					var currentPosition = $(theSlider).css('left');
			    		currentPosition = currentPosition.replace('px','');
			    		currentPosition = parseInt(currentPosition);
			    			     
			    	if (whichOne=='panLeft') {
						$(theSlider).css({'left' : (currentPosition - theDistance) + 'px'});
			    	} else {
						$(theSlider).css({'left' : (currentPosition + theDistance) + 'px'});
			    	}
				},10);
			});
			$('.panArrow').mouseup(function(){
				clearInterval(theMovement);
			});
			
			$('.panArrow').mouseout(function(){
				clearInterval(theMovement);
			});
		}
						
	
	
	// colorbox popups
		$('.popup').colorbox({
			width: 700,
			height : 600,
			href : this.href
		});
		
	// main image up/down scroller
		var theMainImageScrollWrap = $('#colMainImageSlider');
		
		if (isIpad || isIphone || isIpod) {
			$('#tempContentMainImageScroll .scrollButton').click(function(){
	    		var whichOne = $(this).attr('id');
	    		var maxTop = $('#colMainImageWrap').height()-$('#colMainImageSlider').outerHeight();
	    		var minTop = 0;
	    		theDistance=50;
				
				var currentPosition = $(theMainImageScrollWrap).css('top');
			        currentPosition = currentPosition.replace('px','');
			        currentPosition = parseInt(currentPosition);
			        	     
			    if (whichOne=='scrollDown') {
		    		if (currentPosition > maxTop) {
					    $(theMainImageScrollWrap).animate({'top' : (currentPosition - theDistance) + 'px'},'slow','swing');
			    	}
			    } else {
		    		if (currentPosition < minTop ) {
					    $(theMainImageScrollWrap).animate({'top' : (currentPosition + theDistance) + 'px'},'slow','swing');
			    	}
			    }
			});
		} else {
			$('#tempContentMainImageScroll .scrollButton').mousedown(function() {
	    		var whichOne = $(this).attr('id');
	    		var maxTop = $('#colMainImageWrap').height()-$('#colMainImageSlider').outerHeight();
	    		var minTop = 0;
	    		theDistance=0;
				
				theMovement = setInterval(function(){
					while (theDistance<3) {
						theDistance+=0.1;
					}
					var currentPosition = $(theMainImageScrollWrap).css('top');
			    		currentPosition = currentPosition.replace('px','');
			    		currentPosition = parseInt(currentPosition);
			    		
			    	if (whichOne=='scrollDown') {
			    		if (currentPosition > maxTop) {
							$(theMainImageScrollWrap).css({'top' : (currentPosition - theDistance) + 'px'});
			    		}
			    	} else {
			    		if (currentPosition < minTop) {
							$(theMainImageScrollWrap).css({'top' : (currentPosition + theDistance) + 'px'});
			    		}
			    	}
				},10);
			});
			$('#tempContentMainImageScroll .scrollButton').mouseup(function(){
				clearInterval(theMovement);
			});
			
			$('#tempContentMainImageScroll .scrollButton').mouseout(function(){
				clearInterval(theMovement);
			});
		}

	// map legend controls
		var theMapWrap = $('#mainImageNoSlideWrap');
		
		if (isIpad || isIphone || isIpod) {
			$('#tempMapLegend .scrollButton').click(function(){
	    		var whichOne = $(this).attr('id');
	    		//var maxTop = $('#colMainImageWrap').height()-$('#colMainImageSlider').outerHeight();
	    		var maxTop = -539;
	    		var minTop = 0;
	    		theDistance=150;
				
				var currentPosition = $(theMapWrap).css('top');
			        currentPosition = currentPosition.replace('px','');
			        currentPosition = parseInt(currentPosition);
			        	     
			    if (whichOne=='scrollDown') {
		    		if (currentPosition > maxTop) {
					    $(theMapWrap).animate({'top' : (currentPosition - theDistance) + 'px'},'slow','swing');
			    	}
			    } else {
		    		if (currentPosition < minTop) {
					    $(theMapWrap).animate({'top' : (currentPosition + theDistance) + 'px'},'slow','swing');
			    	}
			    }
			});
		} else {
			$('#tempMapLegend .scrollButton').mousedown(function() {
	    		var whichOne = $(this).attr('id');
	    		var maxTop = -539;
	    		//var maxTop = $('#colMainImageWrap').height()-$('#colMainImageSlider').outerHeight();
	    		var minTop = 0;
	    		theDistance=0;
				
				theMovement = setInterval(function(){
					while (theDistance<3) {
						theDistance+=0.1;
					}
					var currentPosition = $(theMapWrap).css('top');
			    		currentPosition = currentPosition.replace('px','');
			    		currentPosition = parseInt(currentPosition);
			    		
			    	if (whichOne=='scrollDown') {
			    		if (currentPosition > maxTop) {
							$(theMapWrap).css({'top' : (currentPosition - theDistance) + 'px'});
			    		}
			    	} else {
			    		if (currentPosition < minTop) {
							$(theMapWrap).css({'top' : (currentPosition + theDistance) + 'px'});
			    		}
			    	}
				},10);
			});
			$('#tempMapLegend .scrollButton').mouseup(function(){
				clearInterval(theMovement);
			});
			
			$('#tempMapLegend .scrollButton').mouseout(function(){
				clearInterval(theMovement);
			});
		}
		$('.poiLegendPoi').click(function(){
			var whichCat = $(this).attr('id');
				whichCat = whichCat.replace('poiCatLegend',''),
				iconButton = $(this).find('span.poiDotInnerNumber');
			
			if ($(this).hasClass('active')) {
				$(this).removeClass('active');
				$('.poiCat' + whichCat).removeClass('active').fadeOut('fast');
				$(iconButton).text('-');
			} else {
				$(this).addClass('active');
				$('.poiCat' + whichCat).css('opacity','1').fadeIn('fast').addClass('active');
				$(iconButton).text('+');
			}
		});
		$('.poiLegendPoi').mouseenter(function(){
			var whichCat = $(this).attr('id');
				whichCat = whichCat.replace('poiCatLegend',''),
				iconButton = $(this).children('span.poiLegendIcon');
			
			if ($('.poiCat' + whichCat).hasClass('active')) {
				$('.poiCat' + whichCat).fadeTo('fast',0.1,function(){
					if (!$.support.opacity) {
						$(this).get(0).style.removeAttribute('filter');
					}
				});
			}
		});
		$('.poiLegendPoi').mouseleave(function(){
			var whichCat = $(this).attr('id');
				whichCat = whichCat.replace('poiCatLegend',''),
				iconButton = $(this).children('span.poiLegendIcon');
			
			if ($('.poiCat' + whichCat).hasClass('active')) {
				$('.poiCat' + whichCat).fadeTo('fast',1, function(){
					if (!$.support.opacity) {
						$(this).get(0).style.removeAttribute('filter');
					}
				});
			}
		});
		var poiMaxTop, poiMinTop;
		var legendPoiWraps = $('.legendCatPoiAllWrap');
		var openPois = setTimeout(function() {
			$(legendPoiWraps[0]).slideDown('slow','swing',function(){
				$(this).prev().addClass('open');
	    		poiMaxTop = $('#legendCat').height()-$('#legendCatInner').outerHeight();
	    		poiMinTop = 0;
			});
		},500);
		$('.legendCatPoiCategory').click(function(){
			if ($(this).hasClass('open')) {
				$(this).next().slideUp('slow','swing',function(){
	    			poiMaxTop = $('#legendCat').height()-$('#legendCatInner').outerHeight();
	    			poiMinTop = 0;
				});
				$(this).removeClass('open');
			} else {
				$('.open').next().slideUp('slow', 'swing', function(){
					$('.open').removeClass('open');
				});
				$(this).addClass('open').next().slideDown('slow','swing',function(){
	    			poiMaxTop = $('#legendCat').height()-$('#legendCatInner').outerHeight();
	    			poiMinTop = 0;
				});
			}
		});
		var theLegendPoiWrap = $('#legendCatInner');
		if (isIpad || isIphone || isIpod) {
			$('.legendArrow').click(function(){
	    		var whichOne = $(this).attr('id');
	    		theDistance=150;
				
				var currentPosition = $(theLegendPoiWrap).css('top');
			        currentPosition = currentPosition.replace('px','');
			        currentPosition = parseInt(currentPosition);
			        	     
			    if (currentPosition < poiMaxTop+1) {
			        $('#legendArrowDown').addClass('inactive').removeClass('active');
			    } else {
			        $('#legendArrowDown').addClass('active').removeClass('inactive');
			    }
			    if (currentPosition > poiMinTop-1) {
			        $('#legendArrowUp').addClass('inactive').removeClass('active');
			    } else {
			        $('#legendArrowUp').addClass('active').removeClass('inactive');
			    }

			    if (whichOne=='legendArrowDown') {
		    		if (currentPosition > poiMaxTop) {
					    $(theLegendPoiWrap).animate({'top' : (currentPosition - theDistance) + 'px'},'slow','swing');
			    	}
			    } else {
		    		if (currentPosition < poiMinTop) {
					    $(theLegendPoiWrap).animate({'top' : (currentPosition + theDistance) + 'px'},'slow','swing');
			    	}
			    }
			});
		} else {
			$('.legendArrow').mousedown(function() {
	    		var whichOne = $(this).attr('id');
	    		theDistance=0;
				
				theMovement = setInterval(function(){
					while (theDistance<3) {
						theDistance+=0.1;
					}
					var currentPosition = $(theLegendPoiWrap).css('top');
			    		currentPosition = currentPosition.replace('px','');
			    		currentPosition = parseInt(currentPosition);
			    	
			    	if (currentPosition < poiMaxTop+1) {
			    		$('#legendArrowDown').addClass('inactive').removeClass('active');
			    	} else {
			    		$('#legendArrowDown').addClass('active').removeClass('inactive');
			    	}
			    	if (currentPosition > poiMinTop-1) {
			    		$('#legendArrowUp').addClass('inactive').removeClass('active');
			    	} else {
			    		$('#legendArrowUp').addClass('active').removeClass('inactive');
			    	}
			    	if (whichOne=='legendArrowDown') {
			    		if (currentPosition > poiMaxTop) {
							$(theLegendPoiWrap).css({'top' : (currentPosition - theDistance) + 'px'});
			    		}
			    	} else {
			    		if (currentPosition <= poiMinTop) {
							$(theLegendPoiWrap).css({'top' : (currentPosition + theDistance) + 'px'});
			    		}
			    	}
				},10);
			});
			$('.legendArrow').mouseup(function(){
				clearInterval(theMovement);
			});
			
			$('.legendArrow').mouseout(function(){
				clearInterval(theMovement);
			});
		}
		
		// news gallery popups
		$('a[rel="newsGallery"]').colorbox({
			slideshow : true,
			speed : 500,
			slideshowSpeed : 2000
		});
		$(".newsVideo").colorbox({inline:true, width:"50%"});

	// media page
		var thisVideo,
			videoFirstLoad = true,
			isRunning;

		var galleryAudio = $('audio').get(0); 
		$('#videosToggle').click(function(){
		    if ($(this).hasClass('inactive')) {
		    	$('#mediaWrapTrayPhoto').fadeOut('fast', function(){
		    		$('#mediaWrapTrayVideo').fadeIn('fast').removeClass('inactive').addClass('active');
		    		$('#photosToggle').removeClass('active').addClass('inactive');
		    		$('#videosToggle').removeClass('inactive').addClass('active');
		    		$('#mediaWrapTrayPhoto').removeClass('active').addClass('inactive');
		    		$('#slideshowWrap').fadeOut('fast',function(){
		    			$(this).css({'z-index':0});
		    			$('#videoWrap').fadeTo('fast',1).css({'z-index':1,'left':'0'});
		    		});
		    		$('#nextSlideButton').fadeOut('fast');
					if (isIpod || isIpad || isIphone) {
						if (videoFirstLoad=true) {
							var buffered = setTimeout(function(){
								$('#loadingChapters').fadeOut('slow',function(){
									$('.videoThumb').fadeIn('slow');
								});
							},videoThumbsBuffered[videoThumbsBuffered.length-1].getAttribute('alt')*400);
						}
						$('#loadingChapters').show();
					}
		    	});
		    }
		    return false;
		});
		$('#photosToggle').click(function(){
		    if ($(this).hasClass('inactive')) {
		    	$('#mediaWrapTrayVideo').fadeOut('fast', function(){
		    		$('#mediaWrapTrayPhoto').fadeIn('fast').removeClass('inactive').addClass('active');
		    		$('#videosToggle').removeClass('active').addClass('inactive');
		    		$('#photosToggle').removeClass('inactive').addClass('active');
		    		$('#mediaWrapTrayVideo').removeClass('active').addClass('inactive');
		    		$('#videoWrap').fadeTo('fast',0,function(){
		    			$(this).css({'z-index':0});
		    			$('#slideshowWrap').fadeIn('fast').css({'z-index':1});
		    		}).css('left','-9999px');
		    	});
		    }
		    return false;
		});
		
		$(galleryAudio).bind('play',function() {
			$("#audioToggle").addClass('audioOn');   
		}).bind('pause ended', function() {
			$("#audioToggle").removeClass('audioOn');    
		});   
		    
		$("#audioToggle").click(function() {
	    	if ($('html').hasClass('audio')) {
				if (galleryAudio.paused) {
					galleryAudio.play();
				} else {
					galleryAudio.pause();
				}
			} else {
				if ($('#audioToggle').hasClass('audioOn')) {
					$('#audioEmbed').remove();
					$('embed').remove();
					$('#audioToggle').remove();
				} else {
		    		//$('#videoWrap').append(''+
    				//	'<audio id="galleryAudio" autoplay="autoplay" loop="loop" style="visibility:hidden;">' +
    				//	'	<source src="/libraries/multimedia/music/video-music.mp3" type="audio/mpeg" /> ' +
    				//	'	<source src="/libraries/multimedia/music/video-music.ogg" type="audio/ogg" /> ' +
					//	'	<embed style="visibility:hidden;" type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3523697345-audio-player.swf?autoPlay=true" quality="best" flashvars="audioUrl=http://' + window.location.hostname + '/libraries/multimedia/music/video-music.mp3" width="500" height="27"></embed>' +
    				//	'</audio>' +
    				//	''
		    		//);
					//$('#audioToggle').addClass('audioOn');
				}
			}   
		});
	
	// HTML5 video	
	if (isIpod || isIpad || isIphone) {
		$('#flashFallback').css({'display':'none'});
		if (document.getElementById('mediaWrapMainPhoto')) {
			var thisVideo = VideoJS.setup('video1');
			thisVideo.play();
			var videoThumbsBuffered = $('.videoThumb img');
			$('.videoThumb').hide();
		}
	} else {
		if (document.getElementById('video1')) {
			$('#videoWrap1').remove();
    		if ($('#videoWrap1').hasClass('architecture')) {
    			$f("flashFallback", "/libraries/multimedia/flowplayer.commercial-3.2.7.swf", {
    				key: '#$473c4de86324d13f369',
    				clip: {
    				  	provider: 'rtmp',
    				  	netConnectionUrl: 'rtmp://s1jdv1c9no0v9p.cloudfront.net/cfx/st',
    				  	url: 'videos/architecture-gallery.compressed'
    				  },
    				plugins : {
						rtmp : {
							url : '/libraries/multimedia/flowplayer.rtmp-3.2.3.swf'
    				  	},
						controls: {
							fullscreen: false,
							height: 30,
							autoHide: true
						}
    				},
    				onFinish : function(){
    					isRunning = false;
    				},
    				onStart : function(){
    					isRunning = true;
    				}
    			});
    		} else {
    			$f("flashFallback", "/libraries/multimedia/flowplayer.commercial-3.2.7.swf", {
    				key: '#$473c4de86324d13f369',
    				clip : {
    					provider: 'rtmp',
    					netConnectionUrl: 'rtmp://s1jdv1c9no0v9p.cloudfront.net/cfx/st',
    					url: 'videos/interiors-gallery.compressed'
    				},
    				plugins : {
						rtmp : {
							url : '/libraries/multimedia/flowplayer.rtmp-3.2.3.swf'
    				  	},
						controls: {
							fullscreen: false,
							height: 30,
							autoHide: true
						}
    				},
    				onFinish : function(){
    					isRunning = false;
    				},
    				onStart : function(){
    					isRunning = true;
    				}
    			});
    		}
    	}
	}
	$('#videosToggle').click(function (){
	  if ($(this).hasClass('inactive')) {
		if (isIpad || isIpod || isIphone) {
	  		thisVideo.currentTime(0);
	    	thisVideo.play();
		} else {
   			$f().play();
		}
	  	$('.videoThumb').removeClass('activeVideoThumb');
	  	$('#videoThumb1').addClass('activeVideoThumb');
	  }
	});
	$('.videoThumbOverlay').click(function(){
		if (isIpad || isIpod || isIphone) {
	    	thisVideo.currentTime($(this).siblings('img').attr('alt'));
	    	thisVideo.play();
		} else {
			if (isRunning==true) {
		    	$f().seek($(this).siblings('img').attr('alt'));
			} else {
				$f().play();
				$f().seek($(this).siblings('img').attr('alt'));
			}
		}
	    $('.videoThumb').removeClass('activeVideoThumb');
	    $(this).parent().addClass('activeVideoThumb');
	});
		
	// contact form validation
	$('#contactForm').submit(function(){
		return validateContactForm();
	});
	function validateContactForm() {
		var inputFirstName = $('#inputFirstName').val(),
			inputLastName = $('#inputLastName').val(),
			inputEmail = $('#inputEmail').val(),
			inputCity = $('#inputCity').val(),
			inputZip = $('#inputZip').val(),
			inputPhone = $('#inputPhone').val(),
			formPass = true,
			formError='';
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		// reset form errors on each submit
		$('#inputFirstName, #inputLastName, #inputEmail, #inputCity, #inputZip, #inputPhone').css({'background':'#f4f4f4'});
			
		if (inputFirstName=='' || inputFirstName==null) {
			$('#inputFirstName').css({'background':'pink'});
			formError+='&middot; First Name is required<br />';
			formPass = false;
		}
		if (inputLastName=='' || inputLastName==null) {
			$('#inputLastName').css({'background':'pink'});
			formError+='&middot; Last Name is required<br />';
			formPass = false;
		}
		if (inputCity=='' || inputCity==null) {
			$('#inputCity').css({'background':'pink'});
			formError+='&middot; City is required<br />';
			formPass = false;
		}		
		if (inputEmail=='' || reg.test(inputEmail)==false) {
			$('#inputEmail').css({'background':'pink'});
			formError+='&middot; Email is required and must be formatted properly<br />';
			formPass = false;
		}
		if (inputZip=='' || inputZip==null) {
			$('#inputZip').css({'background':'pink'});
			formError+='&middot; Zip/Postal Code is required<br />';
			formPass = false;
		}
		if (inputPhone=='' || inputPhone==null) {
			$('#inputPhone').css({'background':'pink'});
			formError+='&middot; Phone is required<br />';
			formPass = false;
		}
		
		if (formPass==false) {
			$('#formStatusMessage').html('<div class="formErrorWrap">' + formError + '</div>');
			return false;
		} else {
			//$('#formStatusMessage').html('<div class="formSuccessWrap">Thank you for your interest.  We will contact you soon.</div>');
			return true;
		}
	}
});

