$(document).ready(function() {
	var activateMarquee = function() {
		$('#marquees li a').removeClass('active');
		switch($(this).attr('rel')) {
			case 'image':
				var url = $(this).attr('href');
				var assetMarkup = $('<img />').attr('src', url).attr('width', '685').attr('height', '339');

				break;
				
			case 'youtube':
				var youtubeId = $(this).attr('href').replace('http://www.youtube.com/watch?v=', '');
				var assetMarkup = "<object width=\"684\" height=\"338\">\n<param name=\"movie\" value=\"http://www.youtube.com/v/"+youtubeId+"&amp;hl=en&amp;fs=1&amp;fmt=8&amp;showinfo=0&amp;\"></param>\n<param name=\"allowFullScreen\" value=\"true\"></param>\n<param name=\"allowscriptaccess\" value=\"always\"></param>\n<param name=\"wmode\" value=\"opaque\"></param>\n<param name=\"showinfo\" value=\"0\"></param>\n<embed src=\"http://www.youtube.com/v/"+youtubeId+"&amp;hl=en&amp;fs=1&amp;fmt=8&amp;showinfo=0&amp;\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"684\" height=\"338\" wmode=\"opaque\"></embed>\n</object>";

				break;
				
			case 'vimeo':
				var vimeoId = $(this).attr('href').replace('http://vimeo.com/', '');
				var assetMarkup = "<iframe src=\"http://player.vimeo.com/video/"+vimeoId+"?title=0&amp;byline=0&amp;portrait=0&amp;color=6fde9f\" width=\"684\" height=\"338\" frameborder=\"0\"></iframe>"

				break;
		}
		
		$('#middle #left').html(assetMarkup);	

		$(this).addClass('active');
		return false;
	}
	
	$('#marquees li a').click(activateMarquee);
	$('#marquees li a:first').trigger('click');
	 
	
	$('#header ul li').hover(function(event) {
		$(this).find('ul').show();
	}, function(event) {
		$(this).find('ul').hide();
	});
	
	//register information page
	$('#event_id').change(function() {
		var eventId = $(this).val();
		$.ajax({
			url: '/register/get-fees',
			data: {
				event_id: eventId
			},
			beforeSend: function() {
				$('#price').attr('disable', 'disabled');
			},
			success: function(data) {
				$('#price-element').html(data);
				$('#price').attr('disable', '');
				$('#price').change(checkFeeForm);
				checkFeeForm();
			}
		})
	});
	
	var checkFeeForm = function() {	
		if($('#price')) {
			var priceId = $('#price').val();
			var price = '';
			$.post('/register/get-price', { price_id: priceId }, function(data) {
				price = data;
				
				if(price == '0') {
					$('#payment_method-element').hide();
					$('#payment_method-label').hide();
					$('#payment_method-scholarship').attr('checked', 'checked');
				} else {
					$('#payment_method-element').show();
					$('#payment_method-label').show();
					$('#payment_method-paypal').attr('checked', 'checked');
					$('#payment_method-scholarship').parent().hide();
				}
			});
		}
	};
	
	$('#price').change(checkFeeForm);
	checkFeeForm();
	
});

var buildTabs = function() {
	var tabs = $('.tab a');
	var containers = $('.container>div');

	if(tabs.length > 0) {
		//setup events
		$('.tab a').click(function(evt) {
			tabs.removeClass('active');
			$(this).addClass('active');	
			containers.hide();

			var id = $(this).attr('href');
			//console.log(id);
			var tabId = id.split('#')[1];
			//console.log(tabId);
			$('#'+tabId).show();

			return false;
		});

		containers.hide();
		
		
		var tabActive = false;
		tabs.each(function(i) {
			if($(this).hasClass('active')) {
				var id = $(this).attr('href');
				var tabId = id.split('#')[1];
				
				$('#'+tabId).show();
				console.log('found active tab:'+tabId);
				tabActive = true;
				return;
			}
		});
		
		if(tabActive == false) {
			tabs.eq(0).addClass('active');
			containers.eq(0).show();
		}

	}

	return false;
}

$(document).ready(function() {
	buildTabs();
});



