document.write('<scr'+'ipt language="javascript1.1" src="http://adserver.adtechus.com/addyn/3.0/5178/1372245/0/16/ADTECH;loc=100;target=_blank;key=key1+key2+key3+key4;grp=[group];misc='+new Date().getTime()+'"></scri'+'pt>');

jQuery(document).ready(function() {


		$("#nav .nav_inner").css('width','100%')
		$("#nav .shadow").css('width','100%')

		$("#nav").mouseover(function(){
			navbar_show()
			navbar_is_over = true
		});   

		$("#nav").mouseout(function(){
			setTimeout( "navbar_hide()", 2000 )
			navbar_is_over = false
		});

		$('.module').each(function () {
			lockscroll($(this));
		});

	var lastsection = $(".block").first();
	$("#nav").hide().css('position','fixed').css('top',0).css('left',0);

	$(window).bind('scroll', function () {
		var l_nDocHeight = $(document).height();
		var l_nWinHeight = $(window).height();
		var l_nScroll = $(window).scrollTop();
		
		$('.module').each(function () {
			var moduleHeight = $(this).height();
			var moduleStart = $(this).offset().top - 1;
			var moduleEnd = moduleStart + moduleHeight;
			
			if( moduleStart < l_nScroll && moduleEnd > (l_nScroll + l_nWinHeight)){
				var thissection = $(this).attr("id");

				if( lastsection != thissection ){
		
					//refresh ad, fire analytics, set hash
					var l_oDate = new Date();
					var l_oAdFrame = $(this).find(".ad iframe");

					if(l_oAdFrame.length > 0) {
						var l_oDate = new Date();
						
						var l_oOldAdSrc = l_oAdFrame.attr("src").split("?");
						var l_oNewAdSrc = l_oOldAdSrc[0] + "?t=" + l_oDate.getTime();	
						
						var l_nAdHeight = l_oAdFrame.attr("height");
						var l_nAdWidth = l_oAdFrame.attr("width");
						
						l_oAdFrameParent = l_oAdFrame.parents('.ad');
						l_oAdFrameParent.html("");
						
						var l_sNewIframe = '<iframe width="'+l_nAdWidth+'" scrolling="No" height="'+l_nAdHeight+'" frameborder="0" src="' + l_oNewAdSrc + '" marginwidth="0" marginheight="0">';
						
						l_oAdFrameParent.html( l_sNewIframe );
					}
	
					if( typeof _gaq === "object" ){
						if(lastsection.length > 0 || thissection != "front") {
							_gaq.push(['_trackPageview', "#" + thissection ]);
						} 
					}


					if(thissection != "front")
						var hash = thissection;
					else
						var hash = "_";
					
					setHash( hash );

					lastsection = thissection;

				}
					
			}
		});

		if(l_nScroll > 500) {
			$("#nav").fadeIn("4000");
		} else {
			$("#nav").fadeOut("500");
			$("#nav .shadow").hide();
			$("#nav_dropdown_features").hide();
			$(".nav_dropdown").removeClass("active");
		}
		
		if((l_nDocHeight - l_nWinHeight) <= (l_nScroll + 5)) {
			$("#footer").fadeIn("4000");
		}
	});
	
	$(".section").each(function() {
		if(!$(this).parents("#nightlife")){
			var l_nPadding = $(window).height() - 435;
			if (l_nPadding < 60) {
				l_nPadding = 60;
			}
			if (l_nPadding > 450) {
				l_nPadding = 450;
			}
			$(this).css("padding-top", l_nPadding + "px");
		}
	});

	$(window).bind('resize',function(){
		$.each($(".static_col"), function(i, n){
				var selectedCol = $(n);
				var parOffset = selectedCol.parent().offset();
				parOffset = parOffset.left;
				if(selectedCol.hasClass("fixed")){
					selectedCol.css({'left' : parOffset});
				} else {
					selectedCol.css({'left' : '0'});
				}
		});
	});

});


		function lockscroll(element) 
		{

			$(window).bind('scroll',function(){
				
				//The module we're currently working with
				var selectedModule = element;

				//The static column we're currently working with
				var selectedCol = element.find('.static_col');
				
				if(selectedCol.length <= 0)
				{
					return false;
				}
				
				var parOffset = selectedCol.parent().offset();
				parOffset = parOffset.left;
			
				//Lowest value the margin can be is zero.
				var startpoint = 0;
			
				//Viewport points
				var viewportBegin = selectedModule.offset().top - 65
				var viewportEnd = viewportBegin + selectedModule.height();
			
				//Stop point will always be the height difference between the static column and it's parent.
				//Essentially, that's the maximum value the margin can be
				var stopPoint = (selectedModule.height() - selectedCol.height());
			
				//How much of the page have we scrolled?
				var winY = $(window).scrollTop();
				
				//Do some adjustments if our module is within the viewport
				if(winY >= viewportBegin && winY < viewportEnd)
				{
					//fix our static column to the bottom of the module if we've scroll below our viewport
					if((winY - viewportBegin) >= stopPoint)
					{
						selectedCol.removeClass('fixed').css({'bottom' : '', 'top' : stopPoint, 'left' : 0});
					}
					//fix our static column to the top of the module if we've scrolled above our viewport
					else if((winY - viewportBegin) <= 0)
					{
						selectedCol.removeClass('fixed').css({'top' : 0, 'bottom' : '', 'left' : 0});
					}
					//Animate the margin while scrolling within the viewport
					else
					{
						var offset = (winY - viewportBegin);
						
						//console.log("winY: " + winY + ", viewportBegin: " + viewportBegin + ", viewportEnd: " + viewportEnd + ", stopPoint: " + stopPoint + ", startPoint: " + startpoint + ', offset: ' + offset);
	
						selectedCol.addClass('fixed').css({'top' : 65, 'bottom' : '', 'left' : parOffset});
					}

				}
				//We're out of the viewport so lock the column back to it's start point
				else
				{
					selectedCol.removeClass('fixed').css({'top' : 0, 'bottom' : '', 'left' : 0});
				}
			
			}); //End Scroll Event
			
		}; //End Function

		
		var player;
		var exp;
		var video;
		var bcExp;
		
		
		// Brightcove Home page
		function onTemplateLoaded(pPlayer) {
			
			$('.video_brightcove').css("left", -1000 )
			
			player	= bcPlayer.getPlayer(pPlayer);
			exp		= player.getModule(APIModules.EXPERIENCE);
			video	= player.getModule(APIModules.VIDEO_PLAYER);
			video.addEventListener(BCMediaEvent.COMPLETE, onMediaComplete);
			bcExp = brightcove.getExperience(experienceID);

		}
		function onMediaComplete(evt) {
			$('.video_brightcove').css('left',-1000)
			$('.video_complete').fadeIn()
		}
		

		function watch_home_video(){
			$('.video_brightcove').css('left',0 )
			$('.film_content').hide();
			video.play();
		}

		function replay_home_video(){
			$('.video_brightcove').css('left',0)
			$('.video_complete').hide();
			video.play();
		}

		$().ready(function(){
			$('.watch').click(function(){
				watch_home_video()
			})
			$('.replay_video').click(function(){
				replay_home_video()
			})
			$('.more_video').click(function(){
				window.location = "/video"
			})
		})

