$(document).ready(function () {
	var thinkcargo = (function() {
		function promo(id) {
			var cls = this;
			var obj = $('.panel.' + id);
			var height = $(obj).find('.content').innerHeight();
			var position = $(obj).position();
			var transitionTime = 500;
			var playerID = 'myytplayer';
			this.isExpanded = false;
			this.toggle = function () {
				position = $(obj).position();
				if (!cls.isExpanded) {
					cls.expand();
				} else {
					cls.contract();
				}
			};
			this.expand = function () {
				cls.isExpanded = true;
				if (id == 'video') $('#' + playerID).show();
				$(obj).animate({
					bottom: '-=' + (height)
				}, transitionTime, function() {
					// animation complete.
				});
			};
			this.contract = function () {
				cls.isExpanded = false;
				$(obj).animate({
					bottom: '+=' + (height)
				}, transitionTime, function() {
					if (id == 'video') $('#' + playerID).hide();
				});
			};
			$(obj).find('.button').click(function (e) {
				e.preventDefault();
				cls.toggle();
			});
			$(obj).click(function (e) {
				e.stopPropagation();
			});
			$(document).click(function () {
				if (cls.isExpanded) {
					cls.contract();
				}
			});
		}
		function navigation() {
			var cls = this;
			var obj = $('#navigation');
			this.expand = function () {
				cls.isExpanded = true;
				$(obj).animate({
					bottom: '-=' + (height)
				}, transitionTime, function() {
					// animation complete.
					if (id == 'video') {
						player = document.getElementById('myytplayer');
						player.playVideo();
					}
				});
			};
			$(obj).find('a').click(function (e) {
				e.preventDefault();
			});
			$(obj).find('#charityrunLink').click(function (e) {
				$('#content .content:visible').fadeOut(function () {
					$('#charityrun').fadeIn();
				});
			});
			$(obj).find('#mediaLink').click(function (e) {
				$('#content .content:visible').fadeOut(function () {
					$('#media').fadeIn();
				});
			});
		}
		return {
			promo: promo,
			navigation: navigation
		}
	})();

	//var twitter = new thinkcargo.promo('twitter');
	//var video = new thinkcargo.promo('video');
	//var music = new thinkcargo.promo('music');
	//var nav = new thinkcargo.navigation();

	$('.infoArrow .links a').click(function (e) {
		e.preventDefault();
		e.stopPropagation();
		var className = $(this).attr('class');
		if (className == 'tw') {
			if (!twitter.isExpanded) twitter.expand();
		} else if (className == 'vid') {
			if (!video.isExpanded) video.expand();
		} else if (className == 'mus') {
			if (!music.isExpanded) music.expand();
		}
	});
	$(document).click(function (e) {
		$('.infoArrow').fadeOut();
	});
	$('.infoArrow, .col').click(function (e) {
		e.stopPropagation();
	});

/*
	$('.links a').click(function (e) {
		e.preventDefault();
		e.stopPropagation();
		var className = $(this).attr('class');
		if (className == 'tw') {
			if (!twitter.isExpanded) twitter.expand();
		} else if (className == 'vid') {
			if (!video.isExpanded) video.expand();
		} else if (className == 'mus') {
			if (!music.isExpanded) music.expand();
		}
	});
*/
});
