$(document).ready(function() {
	$('#fades').cycle({
		fx: 'fade',
		next:   '#next', 
		prev:   '#prev' 
	});
	$('#customMenu a').fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'	:	600, 
		'speedOut'	:	200,
		'overlayColor'	: 	'#000',
		'titleShow'	: 	false,
		'showCloseButton': 	false,
		'type' : 'inline',
		'onStart'	: function() {
		   $.fn.brightcovestart();		
		},
		'onClosed'	: function() {
		    $('#videoFolderContainer object#brightcove').remove();
		    $('#videoFolderContainer .folderContent').append('<div id="brightcove"></div>');
		}
	});
	$('.folderContainer .close').click(function(){
		$.fancybox.close();
	});
	$('#skjema .folderContent form input[name=m_]').val('submitFormAjax');	
	$('#skjema .folderContent form').submit(function(e){
		e.preventDefault();
		$.ajax({  
			type: 'post',  
			url: '/?formsubmit=true',
			data:$(this).serialize(),
			dataType: 'json',    
			success: function(response) {  
				if(response.finished==false){
					$('#skjema .folderContent .helptext').html('<div class="red">Vennligst fyll inn felter merket med stjerne!</div>');
				}else{
					$('#skjema .folderContent form').html('<div class="green">Takk for at du sendte inn skjema!</div>');
					$.fancybox.resize();
					setTimeout(function(){ $.fancybox.close(); }, 3000);
				}				
				
			}
		}); 
	});
	
	
	var dir = 'left';
	var floating = 'false';
	$.each($('#skjema .folderContent ul li input'), function(){
		var id = 'li-'+$(this).attr('id');
		if($(this).attr('id') == 'field-24'){
			floating = 'true';
		};
		if(floating=='true'){
			if(dir=='right') {
				$(this).parent().css('float',dir);
				dir = 'left';	
			}else{
				$(this).parent().css('float',dir);
				dir = 'right';
			};
		};
		$(this).parent().addClass(id);
		
				
	});
	
});
