$(document).ready(function(){
	$('.user-menu-link.inactive').click(function(){
		$('.user-menu').show();
	});
	$('.user-menu-link.active').click(function(){
		$('.user-menu').hide();
	});
	$('.user-menu').mouseleave(function(){
		$(this).hide();
	});
	$(".photo-gallery").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: 1,
        auto: 4000
    });
   	$('.match-select span').live('click', function(){
		$(this).addClass('checked');
   	});
   	$('.match-select span.checked').live('click', function(){
		$(this).removeClass('checked');
   	});
	$("a.overlay-link[rel]").overlay({
		mask: {
			color: '#000',
			opacity: '0.8',
			loadSpeed: 'fast'
		}
	});
	$('#review-event-info').overlay({
		mask: {
			color: '#000',
			opacity: '0.8',
			loadSpeed: 'fast'
		},
		load: true,
		top: 160
	});
	$('#location').focus(function(){
		if ($(this).val()=='zipcode') {
			$(this).val('');
		}
	});
	$('#location').blur(function(){
		if ($(this).val()=='') {
			$(this).val('zipcode');
		}
	});
	
	$('.faq-list dt a').click(function(){
		$(this).addClass('active');
		$($(this).attr('rel')).slideDown('fast');
		return false;
	});
	
	
    $('#gallery').galleria({
    	thumb_quality: false,
    	image_crop: true,
    	show_counter: false,
    	clicknext: true,
    	image_position: 'center top',
    	max_scale_ratio: 1,
    	image_position: 'center',
    	data_config: function(img) {
    		return {
    			author: $(img).attr('author')
    		};
    	}
    });

	$('form').validate();
	
/* jqtransform */
	$('form').jqTransform();

/* select-matches.php functionality */
	$('.match-options').hide();
	$('#event-num-form button').click(function() {				
		if($('#event-num-form').valid()) {
			var $ul_items = $('.match-select').first().find('li');			
			$ul_items.each(function() {
				var slot = parseInt($(this).find('span').first().html());
				if (isNaN(slot) === false) {
					var event_number = parseInt($('#event_number').val());
					if (event_number == slot) {
						$('#my_number').val(slot);				
						$(this).html('<div class="active">'+ slot +'</div><strong>This is you</strong></li>')
									 .addClass('your-number');
					}
				}
			});
			
			$('.select-matches-prompt').slideUp();
			$('.match-options').fadeIn();
			return false;
		}
	});
	// za choose your matches form
    	//if($('#form-matches').valid()) {
    			var $ul_items = $('.match-select').first().find('li');			
			$ul_items.each(function() {
				var slot = parseInt($(this).find('span').first().html());
				if (isNaN(slot) === false) {
					var event_number = parseInt($('#event_number').val());
					if (event_number == slot) {
						$('#my_number').val(slot);				
						$(this).html('<div class="active">'+ slot +'</div><strong>This is you</strong></li>')
									 .addClass('your-number');
					}
				}
			});
   //}
	$('.submit-box button').click(function() {
		var $matches = $('.match-select').first().find('.checked');
		var str = '';
		$matches.each(function() {
			var val = parseInt($(this).html());
			if (isNaN(val) === false) {
				str += val +',';
			}
		});
		$('#matches').val(str);		
		$('#form-matches').Submit();
	});

/* add another school/company	 */
	$('.extra-company').hide();
	$('a.another-company').click(function(){
	   var c_class = $(this).attr('rel');
		$(this).hide();
		$('ul.company' + c_class).show();
	});
	$('.extra-school').hide();
	$('a.another-school').click(function(){
		var c_class = $(this).attr('rel');
		$(this).hide();
		$('ul.school' + c_class).show();
	});
	

});
