jQuery(document).ready(function() {
	jQuery("a[rel='external']").each( function(i) { 
		jQuery(this).attr("target","_blank");
	});
	
	$("a.thickbox").fancybox();

	$("a.advent_box").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'titleShow' 	: 	false,
		'overlayOpacity': 	0.7
	});

	jQuery(".signup input.text").focus( function() { 
		var old_val = jQuery(this).val();
		jQuery(this).val('');
	});
	
	jQuery(".signup input.text").blur( function() { 
		//var old_val = jQuery(this).val();
		jQuery(this).val(old_val);
	});
	
	jQuery(".product-full .longtext").hide();
	
	$('.longtext-show').click(function() {
		jQuery(".product-full .longtext").show('fast');
		$(this).hide();
		return false;
	});
	
	
	/* Uncheck radiobuttons */
	$(function(){
		var allRadios = $('input[type=radio]')
		var radioChecked;
		var moduleId;
		
		var setCurrent = function(e) {
			var obj = e.target;
			radioChecked = $(obj).attr('checked');
			
			var temp = e.target.parents('tr').attr('id').split("-");
			moduleId = temp[2];
		}
		
		var setCheck = function(e) {
			if (e.type == 'keypress' && e.charCode != 32) {
				return false;
			}
			
			var obj = e.target;
			
			if (radioChecked) {
				$(obj).attr('checked', false);
				//hide module
				$('#contact-row-' + moduleId).hide();
				$('#contact_person_' + moduleId).removeClass('validate[required]');
				$('#contact_phone_' + moduleId).removeClass('validate[required]');
				$('#contact_email_' + moduleId).removeClass('validate[required]');
			} 
			else {
				$(obj).attr('checked', true);
				$('#contact-row-' + moduleId).show();
			}
		}    
		
		$.each(allRadios, function(i, val) {        
			var label = $('label[for=' + $(this).attr("id") + ']');
			
			$(this).bind('mousedown keydown', function(e) {
				setCurrent(e);
			});
			
			label.bind('mousedown keydown', function(e) {
				e.target = $('#' + $(this).attr("for"));
				setCurrent(e);
			});
			
			$(this).bind('click', function(e) {
				setCheck(e);    
			});
		});
	});

	$('#toggle_filter').bind('click', function(e){
		$('#showmore').toggle();
		$('#showless').toggle();
		$('#modules').toggle('fast');
		e.preventDefault();
	});

	$('.faq a.faq-title').bind('click', function(e){
		$(this).siblings('.answer').toggle('fast');
		e.preventDefault();
	});

	$('.lightbox').fancybox();
});
