﻿$(document).ready(function() {
    // png fixes
    $('#logo a').pngFix();
    $('#group-nav').pngFix();

    // Disclaimer mouse over
    $('#footer .disclaimer p').hover(
        function() {
            $(this).addClass('hover');
        },
        function() {
            $(this).removeClass('hover');
        }
    );

    // Toolbox - accordion
    if ($('#toolbox.accordion').length > 0) {
        $('#toolbox.accordion').accordion({
            event: 'mouseover',
            active: 1,
            autoHeight: true,
            header: '.header',
            icons: { 'header': 'icon-plus', 'headerSelected': 'icon-minus' }
        });
    }

    // Jumping accordion fix
    $('#toolbox.accordion').each(function() {
        $(this).css('height', $(this).height() + 'px');
    });

    // Claims centres - accordion
    if ($('.accordion-wide').length > 0) {
        $('.accordion-wide').accordion({
            event: 'click',
            autoHeight: false,
            header: '.header',
            icons: { 'header': 'icon-plus', 'headerSelected': 'icon-minus' }
        });
    }

    // sIFR sub stories
    if ($('#sub-stories .sub-story-title').length > 0) {
        $('#sub-stories .sub-story-title').sifr({
            font: '/flash/breeregular.swf',
            version: 3,
            fontSize: '17',
            build: 436
        });

        // Jquery sIFR  - IE Fix
        // Workaraound for dodgy IE flash player which throws Object expected error on window.close
        // See http://www.stoimen.com/blog/2009/06/24/__flash_removecallback-problem-on-ie6/
        $(window).unload(function() {
            $('#sub-stories .sub-story-title').remove();
        });
    }

    // sIFR news list, news article
    if ($('#news-list .news-title').length > 0) {
        $('#news-list .news-title').sifr({
            font: '/flash/breeregular.swf',
            version: 3,
            fontSize: '27',
            build: 436
        });

        // Jquery sIFR  - IE Fix
        $(window).unload(function() {
            $('#news-list .news-title').remove();
        });
    }

    // sIFR news list, news article
    if ($('#news-article .news-title').length > 0) {
        $('#news-article .news-title').sifr({
            font: '/flash/breeregular.swf',
            version: 3,
            fontSize: '27',
            width: '340px',
            build: 436
        });

        // Jquery sIFR  - IE Fix
        $(window).unload(function() {
            $('#news-article .news-title').remove();
        });
    }

    // sIFR broker search
    if ($('#broker-search .broker-search-title, #repairer-search .repairer-search-title').length > 0) {
        $('#broker-search .broker-search-title, #repairer-search .repairer-search-title').sifr({
            font: '/flash/breeregular.swf',
            version: 3,
            fontSize: '24',
            build: 436
        });

        // Jquery sIFR  - IE Fix
        $(window).unload(function() {
            $('#broker-search .broker-search-title, #repairer-search .repairer-search-title').remove();
        });
    }

    // sIFR team list
    if ($('#team-list .team-list-title').length > 0) {
        $('#team-list .team-list-title').sifr({
            font: '/flash/breeregular.swf',
            version: 3,
            fontSize: '21',
            build: 436
        });

        // Jquery sIFR  - IE Fix
        $(window).unload(function() {
            $('#team-list .team-list-title').remove();
        });
    }

    if ($('#team-list .team-list-sub-title').length > 0) {
        $('#team-list .team-list-sub-title').sifr({
            font: '/flash/breeregular.swf',
            version: 3,
            fontSize: '16',
            build: 436
        });

        // Jquery sIFR  - IE Fix
        $(window).unload(function() {
            $('#team-list .team-list-sub-title').remove();
        });
    }

    if ($('#content .content h1').length > 0) {
        $('#content .content h1').sifr({
            font: '/flash/breeregular.swf',
            version: 3,
            fontSize: '21',
            width: '320px',
            build: 436
        });

        // Jquery sIFR  - IE Fix
        $(window).unload(function() {
            $('#content .content h1').remove();
        });
    }

    // News sliders
    if ($('#news-slider .news-items').length > 0) {
        $('#news-slider .news-items').cycle({
            fx: 'scrollHorz',
            speed: 'slow',
            prev: '.news-prev-item',
            next: '.news-next-item',
            pause: 1,
            timeout: 10000
        });

        $('#news-slider .news-pause-item').toggle(function() {
            $(this).addClass('news-paused-item');
            $('#news-slider .news-items').cycle('pause');
        }, function() {
            $(this).removeClass('news-paused-item');
            $('#news-slider .news-items').cycle('resume');
        });
    }

    // The sliders
    if ($('#team-slider').length > 0) {
        $('#team-slider').cycle({
            fx: 'scrollHorz',
            speed: 'medium',
            prev: '.team-member-prev',
            next: '.team-member-next',
            timeout: 0
        });
    }
});