/*
 * script.js
 *
 * Common exection JS
 *
 * Author: Terry Morgan <terry.morgan@marmaladeontoast.co.uk>
 */
var $wr = window.$wr || {};

$(document).ready(function() {
    if ($('html').hasClass('ie6') || $('html').hasClass('ie7') || $('html').hasClass('ie8')) {
        $wr.oldIe = true;
    }

    // Start up fancy AJAX search if on homepage
    // and the user has a decent browser

    if ($('.search-form').length) {
        if ($('.home').length) {
            if ( ! $wr.oldIe) {
                $wr.HomepageSearch.init();
            } else {
                $wr.JobSearch();
            }
            $wr.HomeTextTweaking();
        } else {
            $wr.JobSearch();
        }
    }

    if($('#job-apply-success').length) {
        var sucessoverlay = new $wr.Overlay();
        sucessoverlay.setType('job-apply-success');
        sucessoverlay.update("<h1>Thank you for your application</h1><h2>We'll be in touch shortly</h2>");
        sucessoverlay.load();
    }

    $('.collapsible').each(function(){
        var opts = {
            togglePosition: 'before'
        };

        new $.collapsible($(this), opts);
    });

    if ($('#slideshow').length) {
        $wr.SlideShow.init('slideshow');
    }

    $wr.ContactPanel.init();

    $.localScroll({
        duration: 500,
        easing: 'easeInOutQuad'
    });

    $('.industry-list')
        .delegate('a', 'mouseenter', function(e) {
            $('.industry-list a.active').removeClass('active');
            $(this).addClass('active');
            $('.industry-list a:not(.active)').animate({ 'color':  '#dddddd' }, {
                duration: 'fast',
                queue: false
            });
        })
        .delegate('a', 'mouseleave', function(e) {
            $('.industry-list a:not(.active)').animate({ 'color':  '#000000' }, {
                duration: 'fast',
                queue: false
            });
        });

    $('#floated-panel').portamento({
        wrapper: $('.search')
    });

    $('a[rel=external]').click(function(e){
        e.preventDefault();
        window.open($(this).attr('href'));
    });
});
