$(document).ready(function() {

    //add flash to homepage

    /*
    var data0 = "&fullRun=true&introPoints=p-3130,-160,60p-1330,58,-122p-1110,283,77p-920,-38,-180p-580,-98,21p-530,78,85&outroPoints=p150,-0.5,0p395,-77,-25p666,228,121p789,96,-27p941,-4,33p1382,193,166p3250,-290,40&cameraPoints=p480,10,-1010p-320,-20,-1780&lookAtPoints=p10,0,-10p10,0,-10&wireLength=300&durationCamera=10&durationIntro=1.5&durationSVG=1&durationOutro=1.5&retreatIntro=1&retreatSVG=30&retreatOutro=1";
    var data1 = "&fullRun=true&introPoints=p-2570,-420,-420p-680,-12,-122p-830,193,77p-1170,-58,-180p-620,-258,21p-490,-22,205&outroPoints=p150,-0.5,0p375,3,-35p586,228,41p859,96,193p731,-4,-77p992,173,-94p1790,480,-510&cameraPoints=p610,0,-1050p-580,0,-1610&lookAtPoints=p0,0,10p10,0,-370&wireLength=300&durationCamera=10&durationIntro=1.5&durationSVG=1&durationOutro=1.5&retreatIntro=1&retreatSVG=30&retreatOutro=1";
    var data2 = "&fullRun=true&introPoints=p-2620,-250,100p-1250,488,-32p-790,143,67p-830,-158,-170p-620,152,31p-360,198,215&outroPoints=p150,-0.5,0p365,-27,-105p546,158,141p679,-54,-17p941,-14,-257p842,193,86p1890,-290,280&cameraPoints=p430,-10,-1120p-460,-10,-1410&lookAtPoints=p30,-10,-20p10,-10,-10&wireLength=300&durationCamera=10&durationIntro=1.5&durationSVG=1&durationOutro=1.5&retreatIntro=1&retreatSVG=30&retreatOutro=1";

    data0 = data0.replace(/=/g, "0=");
    data1 = data1.replace(/=/g, "1=");
    data2 = data2.replace(/=/g, "2=");

    $('.flash').flash(
    {
    src: '/SiteCollectionImages/Landing%20images/preloader.swf',
    width: 960,
    height: 342,
    wmode: 'transparent',
    flashvars: {
    source: "/SiteCollectionImages/Landing%20images/world_icon.svg",
    pictures: "[/SiteCollectionImages/Landing%20images/FlashImage.jpg]",
    lineDrawingSleepTime: "0", // time in hours
    data: data0 + data1 + data2
    }

    },
    { version: 9 }
    );
    */



    //add js print button
    $('<p class="print"><a href="#">Print this page</a></p>').insertAfter('.cf ul.breadcrumbs').click(function() { window.print(); })
    $('<li class="print"><a href="#">Print this page</a></li>').insertAfter('.office-location .arr-lnk .prev').click(function() { window.print(); })


    //search tabs
    $('.tab .results-content').hide();
    var displayTab;
    var displayContent;

    if ($('#tabPosition').val() == "") {
        //do first time round
        displayContent = $('.tab:first-child .results-content'); //get first tab content to display
        displayTab = $('.tab:first-child a.lnk-tab').attr('class'); //get first tab link to highlight
        displayTab = displayTab.slice(8); //remove lnk-tab from string
        $('#tabPosition').val(displayTab) //set value first time round

    }
    else {
        displayTab = $('#tabPosition').val(); //get hidden value and display correct tab
        displayContent = $('.tab a.' + displayTab).parent('.tab').find('div.results-content', this); //get hidden field ad display content
    }

    $('.tab a.' + displayTab).addClass('on');
    $(displayContent).show()

    $('.tab a.lnk-tab').click(function() {
        $('div.results-content').hide();
        $('.tab a').removeClass('on');
        displayTab = $(this).attr('class');

        $('#tabPosition').val(displayTab.slice(8))
        $(this).addClass('on').parent('li').find('div.results-content', this).show();

        return false;

    });


    //if country has more than one city, add accordian
    if ($('div.cities').find('li').length > 1) {
        $('div.cities').addClass('contacts-con').find('ul').addClass('contacts');

    }


    //accordian style display for contacts - can show multiple
    $('ul.contacts li .vcard').hide();
    $('ul.contacts li').children('a:first-child').click(function() {
        $(this).toggleClass('open');
        $(this).parent('li').find('div.vcard', this).slideToggle();
        return false;
    });


    //sign in - show / hide publication type
    $('.pub-type').hide();
    $('.order-subscribe').empty().html('<h3>You are about to subscribe to:</h3><p>You have not selected any publications yet.</p>');


    //run subscribe function if user refreshes or returns to page
    $('fieldset.signup input[type=checkbox][checked]').each(function() {
        subscribe(this);
    });

    //run subscribe function when checkbox is clicked
    $('.signup input').click(function() {
        subscribe(this);
    })

    //removes the ms-long class from list iterator forms and hides the title field
    $('.form-row input').removeClass("ms-long");
    $('.form-row input[title=Title]').attr('disabled', 'disabled');
    $('.form-row input[title=Title]').parent().parent().hide();


    function subscribe(el) {
        $div = $(el).attr('id');
        $(el).siblings('div .' + $div).toggle();
        var $type;
        var $ul = '.order-subscribe ul';
        var $head = ''
        var $p = '.order-subscribe p';
        $($ul).remove();
        $($p).remove();


        $('.order-subscribe').append('<ul></ul>');

        $('fieldset.signup input:checkbox').each(function() {

            if ($(this).is(':checked')) {

                if ($(this).parent('div').find('div.pub-type').html() != null) {
                    if ($(this).parent('div').find('div').find("input[@type=radio]:checked").attr('class') == 'hard-copy') {
                        $type = '&#160;&#40;hard copy&#41;';
                    }
                    else {
                        $type = '&#160;&#40;via email&#41;';
                    }

                    $('.order-subscribe ul').append('<li>' + $(this).nextAll('label').eq(0).html() + $type + '</li>');
                }
                else {

                    $('.order-subscribe ul').append('<li>' + $(this).nextAll('label').eq(0).html() + '&#160;&#40;via email&#41;</li>');
                }

            }

        })
    }

    //form validation
    $('.button input').click(function() {
        $('div.form-row').removeClass('error');
        $('fieldset.signup p.error').remove();
        var error = true;
        $('input.required').each(function() {
            if ($(this).val() == "") {
                $(this).parent('div', this).addClass('error');
                error = false;
            }
        })

        $('select.required').each(function() {
            if ($(this + ':selected').val() == "#" || $(this + ':selected').val() == undefined || $(this + ':selected').val() == "") {
                if ($(this).parent('div', this).next().find('input.required-other').val() == "") {
                    $(this).parent('div', this).addClass('error');
                    error = false;

                }
            }
        })

        if (error == false) {
            $('fieldset.signup p').after('<p class="error">! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer dui est, mattis quis, lobortis ac, pellentesque in, leo. In libero lorem, bibendum sed, dignissim eu, blandit at, justo.</p>');
            return false;
        }
    })

    //Primary navigation for IE6 - actives for all browsers but others work without	
    $('#primary-nav ul li').hover(
	function() {
	    $(this).addClass('nav-hover').find('>a').addClass('hover')
	},
	function() {
	    $(this).removeClass('nav-hover').find('>a').removeClass('hover');
	});


    //table sorter - calling tablesorter plugin
    /*
    $('table.table-sort').tablesorter({
    sortList: [[0, 2]],
    dateFormat: 'dd/mm/yyyy' 
    });
    */

    $("table.table-sort").bind("sortStart", function() {
        $('table.table-sort tbody tr td').css('background', '#fff url(/style%20library/images/ll-images/bg_table_border.gif) no-repeat left bottom');
        $('table.table-sort tbody tr td.first').css('background-position', '8px 100%');
        $('table.table-sort tbody tr td.last').css('background-position', '102.5% 100%');
    }).bind("sortEnd", function() {
        $('table.table-sort tbody tr:last-child td').css('background', '#fff');
    });

    $('table.news').tablesorter({ /*news items apart from all*/
        dateFormat: "uk",
        headers:
       {
           1: {
               sorter: "shortDate"
           }
       }
    });

    $('table.txt-small').tablesorter({ /*associates*/
        headers:
       {

           1: {
               sorter: false
           },

           3: {
               sorter: false
           },
           4: {
               sorter: false
           }

       }

    });
    $('table.table-sortallnews').tablesorter({
        dateFormat: "uk",
        headers:
       {
           2: {
               sorter: "shortDate"
           }
       }

    });


    $('table.table-sortseminar').tablesorter({
        dateFormat: "uk",
        headers:
       {
           2: {
               sorter: "shortDate"
           }
       }

    });



    $('#site-search input').bind("click keyup", function() {
        if ($(this).attr('value') == 'Search this site' || $(this).attr('value') == 'Procurar neste site') {
            $(this).attr('value', '');
        }
    })

    $("ul.breadcrumbs > li:contains(Find a Lawyer)").end().find('HEAD').prepend("<META NAME='Robots' CONTENT='NOARCHIVE'>")

});

function DisableEnterKeySubmit(e) {
    var key;
    if (window.event) {
        key = window.event.keyCode;     //IE
    }
    else {
        key = e.which;     //firefox
    }

    return (key != 13);

}


function SubmitOnEnterKeyPress(buttonID, e) {
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonID);

        if (btn != null) {
            //If we find the button click it
            btn.click();
            event.keyCode = 0;
        }
    }
}

function SubmitSearchOnClick(textBoxID) {

    var txt = document.getElementById(textBoxID);

    if (txt != null) {

        if (txt.value == 'Search this site') {
            txt.value = '';
        }
    }
}





