$(document).ready(function() {
   // do stuff when DOM is ready
   $(".date-field").datePicker().val(new Date().asString()).trigger('change');
   render_buttons();
   fixie6png();
});

function render_buttons() {
    $('.btn').each(function() {
        var b = $(this);
        var tt = b.text() || b.val();
        if ($(this).is(':input')) {
            b = $('<a>').insertAfter(this).addClass(this.className).attr('id',this.id);
            $(b).click(function(){
                $(this).parents('form').submit();
            });
            $(this).remove();
        }
        b.text('').css({cursor:'pointer'}).append($('<span>').text(tt).append('</span>'));
    });
}

function add_notification(message) {
    if($('.messages').length > 0) {
        $('.messages').append('<li><span>' + message + '</span></li>');
    }
    else {
        $('#bd').before('<ul class="messages"><li><span>' + message + '</span></li></ul>');
    }
};

function fixie6png() {
    if ($.browser.msie && $.browser.version.substr(0,1)<7) {
        $('#testimonials_top').supersleight('', false);
        $('.prog_header_photo').supersleight('', true);
        $('.highlight_prog_header_photo').supersleight('', true);
        $('.grid-photo').supersleight('', false);
    }
}

function blockuimessage_css() {
    css = {
        top:  ($(window).height() - 500) /2 + 'px', 
        left: ($(window).width() - 500) /2 + 'px', 
        border: 'none',
        textAlign: 'left',
        padding: '0px 15px 15px 15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .8, 
        color: '#fff'
    }
    return css
}

function blockuiform_css() {
    css = {
        top:  ($(window).height() - 500) /2 + 'px', 
        left: ($(window).width() - 500) /2 + 'px', 
        border: '6px solid #CCCCCC', 
        textAlign: 'left',
        width: '460px',
        padding: '0px 15px 15px 15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .9, 
        color: '#fff'
    }
    return css
}

var current_caption = 0;

function slideSwitch(id) {
    var $active = $('#'+id+' IMG.active');

    if ( $active.length == 0 ) $active = $('#'+id+' IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#'+id+' IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    
    current_caption = current_caption + 1;
    if (current_caption == 4) current_caption = 0;
    var captions = [
        "Prices start from £350 and include meals, accommodation, airport transfers and full on-ground support",
        "Volunteer from 2 weeks up to 1 year",
        "We accept volunteers worldwide and from the age of 18 upwards",
        "You decide when you want to travel - no fixed program dates!"
    ];
    
    /*$(".slideshow-caption").animate({bottom: -100}, 500, function() {
        $(this).html(captions[current_caption]);
        $(this).animate({bottom: 6}, 500);
    });*/
    $(".slideshow-caption").animate({opacity: 0.0}, 500, function() {
        $(this).html(captions[current_caption]);
        $(this).animate({opacity: 1.0}, 500);
    });
}
