/* Author: Edd temple-Smithson

*/

$(document).ready(function () {
    /* IE pseudo class fix */
    if ($.browser.msie) {
        $('li:first-child').addClass('first');
        $('li:last-child').addClass('last');
    }

    /* Sticky Footer */
    var stickFooter = function () {
        $('#main').css('padding-bottom', $('#footer').height());
        $('#footer').css('margin-top', -($('#footer').height()));
    };
    stickFooter();
    window.onresize = function (event) {
        stickFooter();
    }

    /* Forms autoclear */
    var el = $('#q');
    if (el.val() == '') {
        el.val('Search the site');
    }
    el.focus(function (e) {
        if (e.target.value == 'Search the site')
            e.target.value = '';
    });
    el.blur(function (e) {
        if (e.target.value == '')
            e.target.value = 'Search the site';
    });

    /* Adverts */
    $.writeCapture.autoAsync();
    if (typeof frequency != 'undefined') {
        $('#jq-mpu p:nth-child(' + frequency + 'n+1)').each(function () {
            var ad = $('.jq-adverts .jq-advert:first').detach();
            $(this).prepend(ad);
        });
    }

    /* Tabs */
    $(".jq-tabs").tabs(".jq-panes > div");

    /* Accordions */
    $(".jq-accordions > h4").click(function () {
        $(this).toggleClass("closed").next("div").slideToggle();
    });
    $(".jq-accordions > h4:not(:first)").click();

});
