$(function() {
    
    $('.slideshow').cycle(); // Jerome, homepage slideshow

    $('#vacancy_cycle').cycle({
        fx: 'scrollUp',
        timeout: 5000
    });
        
    //$('#registration_form').jqTransform();

    // registrationform
    if (jQuery().formwizard) {
        $("#registration_form").formwizard({ 
            //formPluginEnabled: true,
            historyEnabled : true,
            //validationEnabled: true,
            formOptions: {
                //success: function(data){$("#status").fadeTo(500,1,function(){ $(this).html("You are now registered!").fadeTo(5000, 0); })}
            },
            validationOptions : {
                errorPlacement: function(error, element) {
                    offset = element.offset();
                    error.insertBefore(element);
                    error.addClass('error_message');  // add a class to the wrapper
                    error.css('position', 'absolute');
                    error.css('left', offset.left + element.outerWidth());
                    error.css('top', offset.top - 40);                
                }
    	 	}
         });
     
        var arrow = document.createElement('div');
     	$(arrow).addClass('error_arrow');
     	$('.error_message').append(arrow);
     	$(arrow).addClass('error_arrow_bottom');
     	$(arrow).html('<div class="line1"><!-- --></div><div class="line2"><!-- --></div><div class="line3"><!-- --></div><div class="line4"><!-- --></div><div class="line5"><!-- --></div><div class="line6"><!-- --></div><div class="line7"><!-- --></div><div class="line8"><!-- --></div><div class="line9"><!-- --></div><div class="line10"><!-- --></div>');

        $("#registration_form").bind("step_shown", function(event, data) {
            $.scrollTo($('body'));
            if (!data.isFirstStep) $("#registration_form").siblings().hide(); // just show page info for first step
        });

        $(".ui-formwizard-button").click(function() {
     		$('.error').addClass('error_message');
     	});
 	
     	// misc tidy up
     	$('#registration_form h3').css('margin-top', '0');
     	$('#step2 h3').hide();
     	$('.info_icon').parent().next().addClass('info_panel');
     	$('.info_icon').parent().next().hide();
     	$('.info_icon').click(function() {
     	    $(this).parent().next().toggle();
     	});
     	
     	$('#subnav > li a:first').css('border-top', '1px solid #333');
        $('.post .article:first').css('margin-top', '0');
        if (location.href.indexOf('/dvr2') > 0) $('#subnav').css('visibility', 'hidden');
        if ($('#subnav .current').length > 1) {
            $('#subnav li.current a:first').css('background', 'none');
        }
        


        
        
        
        
        //$('.date_input').datepicker({ dateFormat: 'dd/mm/yy' });
        
        $('#id_entitlement_ready').click(function() {
            if ($(this).is(':checked')) $('#id_entitlement_reason').addClass('required');
            else $('#id_entitlement_reason').removeClass('required');
        });
        
        $('#id_health_issues, #id_criminal_record').click(function() {
            if ($(this).is(':checked')) $(this).next().next().show().children().filter('label').addClass('required');
            else $(this).next().next().hide().children().filter('label').removeClass('required');
        }).click();
        
        $('.step h3').not(':first-child').css('margin-top', '3em');
        $('.short_label:last').css('padding-right', '0');
        
        $('#id_supply_type_0, #id_supply_type_1, #id_supply_type_2').click(function() {
            var ii = $(this).attr('id');
            ii = ii.charAt(ii.length-1);
            $('.revealed').hide();
            $('#id_supply_type_revealed_' + ii).show(); 
            //console.log($('#id_supply_type_revealed_' + ii).length);
            // var ii;
            // if ($(this).is(':checked')) {
            //     ii = $(this).attr('id');
            //     ii = ii.charAt(ii.length-1);
            //     $('.revealed').hide();
            //     $('#id_supply_type_revealed_' + ii).show();
            //}
        }).click();
    }
    
    // IE6 nav fix
    // $('#subnav ul li.current a:not(:first)').css('background', 'none');
    // $('#subnav ul li.current a:not(:first)').css('background', 'none');
});
