$(document).ready(function() {


    $('#content table tr:odd').addClass('odd');
    $('.name').val('Enter Name');
    $('.name').click(function() {
    if ($('.name').val() == "Enter Name")
        $('.name').val('');
    });


    $(document).pngFix();
    if (jQuery().accordion) {
        $("#home-accordion").accordion();
        $("#rhs-accordion").accordion({ collapsible: true,active: false });
    }
    if (jQuery().cycle) {
    
        $(".top-img").cycle({

            fx: 'fade',
            speed: 3000

        });
    }

    if (isViewAll($("#rhs-contacts li:last").text())) {
        $("#rhs-contacts li:last a").addClass('view-all');
    }

    if (isViewAll($("#rhs-practice-area li:last").text())) {
        $("#rhs-practice-area li:last a").addClass('view-all');
    }

    var $divPub = $('#rhs-publications > p');
    var $elPub = $divPub.eq($divPub.length - 2);


    if (isViewAll($elPub.text())) {
        $elPub.addClass('view-all');
    }

    var $divNews = $('#rhs-news > p');
    var $elNews = $divNews.eq($divNews.length - 2);


    if (isViewAll($elNews.text())) {
        $elNews.addClass('view-all');
    }

    if (isViewAll($("#rhs-brochures li:last").text())) {
        $("#rhs-brochures li:last a").addClass('view-all');
    }




    $('.news-panel .holder:last').addClass('last');

    if (jQuery().tabs) {
        $("#tabs").tabs();
    }

    if ($('#tabRankings').text().length > 50) {
        $("#tabs a.last").show()
    }
    else {
        $("#tabs a.last").hide()
    }

    if ($('#tabExperience').text().length > 50) {
        $("#tabs a.liExperience").show()
    }
    else {
        $("#tabs a.liExperience").hide()
    }


    $("ul#actions li:first").addClass("first");



    $('#breadcrumb span:first').addClass('start');

    $('.faqs dd').hide(); // Hide all DDs inside .faqs
    $('.faqs dt').hover(function() { $(this).addClass('hover') }, function() { $(this).removeClass('hover') }).click(function() { // Add class "hover" on dt when hover
        $(this).next().slideToggle('normal');
        $(this).toggleClass('open'); // Toggle dd when the respective dt is clicked
    });

    $('.expand a').click(function() {
        $('.faqs dd').slideToggle('normal');
        $('.faqs dt').toggleClass('open');
    });

    $('.faqs:last').css('border', 'none');



    var highestCol = Math.max($('#holder-1').height(), $('#holder-2').height(), $('#holder-3').height(), $('#holder-4').height(), $('#holder-5').height(), $('#holder-6').height(), $('#holder-7').height(), $('#holder-8').height(), $('#holder-9').height());
    $('.overview-holder').height(highestCol);


    var url = document.location.href;
    if (url.indexOf("/staff/") != -1) {
        $(".rootGroup li a").each(function() {
            if ($(this).text() == "Our People") {
                $(this).addClass("active");
            }
        });

    }



    var url = document.location.href;
    if (url.indexOf("/trainee-blog/") != -1) {

        $(".quote").hide();


    }

    $("a").each(function() {
        var url = $(this).attr("href");

        if (url.indexOf(location.hostname) == -1 && url.indexOf("http://") > -1) {
            $(this).attr("target", "_blank").addClass("external");
        }

        if (url.lastIndexOf(".") > 0) {
            if (url.substring(url.lastIndexOf("."), url.length) == ".ashx") {
                $(this).attr("target", "_blank").attr("title", "Opens new window").addClass("external");
            }
        }
    });

    if (window.location.href.indexOf("/tax.aspx") > -1 || window.location.href.indexOf("/private_client.aspx") > -1) {
        $("#budgetlogo").html("<a href=\"http://www.williamfry.ie/gns/tax/budget-2012.aspx\"  ><img style=\"padding-top:10px; width:200px; height:96px;\" src=\"../images/budget2012.jpg\" width=\"200\" height=\"96\"></a><a href=\"http://www.williamfry.ie/gns/tax/finance-bill-2011.aspx\"  ><img style=\"padding-top:10px; width:200px; height:96px;\" src=\"../images/finance-bill-small.jpg\" width=\"200\" height=\"96\"></a>")
    }

    if (window.location.href.indexOf("/foreign_direct_investment") > -1 || window.location.href.indexOf("/investing_in_ireland.aspx") > -1) {
        $("#budgetlogo").html("<a href=\"http://www.williamfry.ie/publication-article/investing_in_ireland_-_english_french_german_italian_and_chinese_guides.aspx\" target=\"_blank\"  ><img style=\"padding-top:10px; width:200px; height:96px;\" src=\"../images/invest-ireland-small-graphi.jpg\" width=\"200\" height=\"96\"></a>")
    }

 if (window.location.href.indexOf("/myra_garrett.aspx") > -1) {
        $("#lawyeraward").html("<img  src=\"http://www.williamfry.ie/images/Leading-Lawyer-Rosette.jpg\"  alt=\"Leading Lawyer Rosette\"/>");
    }

    if (window.location.href.indexOf("/insurance_reinsurance.aspx") > -1) {
        $("#budgetlogo").html("<a href=\"http://www.williamfry.ie/gns/insurance-reinsurance/solvency-ii.aspx \"  ><img style=\"padding-top:10px; width:200px; height:96px;\" src=\"../images/solvency-II.jpg\" width=\"200\" height=\"96\"></a>")
    }
    
});


    function bookmark() {
        var title = document.title;
        var url = document.location.href;

        if (document.all) {
            if (window.external != undefined && window.external != null) {
                window.external.AddFavorite(url, title);
            }
            else {
                alert("Sorry! Your browser doesn't support this function.\n Press CTRL+D or select 'Bookmark This Page' from your 'Bookmarks' menu.");
            }
        }
        else {
            window.sidebar.addPanel(title, url, '');
        }
    }
    
    function emailme() {
        var title = document.title;
        var url = document.location.href;
        var subject = "William Fry Website";
        var bodyText = "I saw this page and thought you might like to see it " + url;

        window.location.href = "mailto:?subject=" + subject + "&body=" + bodyText;

    }
       
    function createLinks() {
        document.write('<ul id="actions">');
            document.write('<li><a href="javascript:self.print()">print page</a></li>');
            document.write('<li><a href="javascript:emailme()">email page</a></li>');
            
         document.write('</ul>');
    }

    var clickmessage = "Sorry, you are not permitted to right click on this image"

    function protectImages() {
        if (document.all)
            document.oncontextmenu = disableclick
        else if (document.getElementById)
            document.oncontextmenu = disableclick
        else if (document.layers)
            associateimages()
    }

    function isViewAll(str) {
  
        if (str.indexOf("View All") > -1) {
            return true
        }
        else {
            return false;
        }
    }

