$().ready(function() {
	var menuWidth = $('#MainMenu').width();
	$('#MainMenu .dropdownContainer').each(function() {
		var submenu = $('ul', this);
		var firstItem = $('li:first', this);
		
		var maxLeft = menuWidth - submenu.width();
		var topItemPosition = $(this).parent().position();
		
		$(this).removeClass('right');
				
		if (topItemPosition.left <= maxLeft) {
			$(firstItem).css('marginLeft', topItemPosition.left+'px');
		} else {
			$(firstItem).css('marginLeft', maxLeft+'px');
		}
	});
	
	$('#MainMenu li.hasSubmenu').hover(
		function() {
			$(this).addClass("hover");
			
		},
		function() {
			$(this).removeClass("hover");
		}
	);
	
	
	$("a.enlargeImage").fancybox({
		"hideOnContentClick": true,
		"titleShow": false
	});
	
	if (typeof(swfobject) != 'undefined') {
		var count = 0;
		$('object[type=application/x-shockwave-flash]').each(function() {
			if (!this.id) {
				count = count+1;
				this.id = 'Flash'+(count);
			}
			
			swfobject.registerObject(this.id, minimumFlashVersion, "assets/expressInstall.swf");
		});
	}
	
	
	$("a[href^='http']").not("[href*='"+window.location.host+"']").click(function() {
		if (typeof(pageTracker) !== 'undefined') {
			if ($(this).hasClass('demoLink')) {
				pageTracker._trackEvent('Demo download', this.href);
			} else {
				pageTracker._trackEvent('Outgoing link', this.href);
			}
		}	
	});

	
		
});


function info(input) {
	if (typeof console == 'object') {
		console.log(input);
	}
}








var videoPage = {
	defaultSettings: {
		"videoContainer": '#VideoContainerInner'
	},
	videoContainer: null,
	videoData: null,
	
	
	// get things going
	init: function(settings) {
		this.settings = $.extend(this.defaultSettings, settings);
		this.videoContainer = $(this.settings.videoContainer);
		
		// this should reallybe replaced with something more generic at some point
		this.videoData = new Array();
		$('.videoData').each(function() {
			var url = $('.url', this).attr('href');
			videoPage.videoData[url] = {
				"Title": $('.title', this).html(),
				"Content": $('.content', this).html(),
				"URL": url,
				"YTID": url.substr(31)
			};
		});
		
		// apply link events
		$('.videoData a').click(function() {
			videoPage.loadVideo($(this).attr('href'));
		//	$(this).blur();
			return false;
		});
		
		// load the first video
		$('.videoData a:first').click();
		
		
		
	},
	
	// put a video in
	loadVideo: function(url) {
		var videoInfo = this.videoData[url];
		
		$('.videoData').removeClass('current');
		$('a[href='+url+']').parents('.videoData').addClass('current');
		
		$(this.videoContainer).html('<a href="'+url+'" class="ytLink"></a>');
		
		$('.ytLink').ytchromeless({
			videoWidth  : this.videoContainer.innerWidth(),
			videoHeight : this.videoContainer.innerHeight()
		});
		
		videoPage.currentPlayer = $('.video-player');
		
		$('#CurrentVideoTitle').html(videoInfo.Title);
		
		if (typeof(pageTracker) !== 'undefined') {
			pageTracker._trackEvent('Video Loaded', url);
		}
	
		/*
		$('#Test').click(function() {
			console.log(videoPage.currentPlayer);
			videoPage.currentPlayer.trigger('togglePlay');
			return false;
		});
		*/
	}

	
}



