
//Capita Symonds General JS

//This is a 'last resort' for stripping bad markup.  This site is already very slow.
function stripBadMarkup(el) {
    var tags = document.getElementsByTagName(el);
    for (var i = 0; i < tags.length; i++) {
        if (tags[i].innerHTML === '' || tags[i].innerHTML === '&nbsp;') {
            tags[i].parentNode.removeChild(tags[i]);
        }
    }
}

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
	obj['e'+type+fn] = fn;
	obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
	obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
	obj.addEventListener( type, fn, false );
} 

var xTabs = function(){}
xTabs.prototype.switchPanel = function(el,index){
    var args = Array.prototype.slice.call(arguments);
    if (args[0]){
        jQuery('.news-e-box').hide();
                jQuery('#xtabs > li').removeClass('active');
                    jQuery('#xtabs li').eq(index).addClass('active');
        return true;
    }else{
        return false;     
    }
}

var XT = new xTabs();

$(document).ready(function() {

    if ($.browser.msie) {
        $('#secondary-nav.findAContactSearch').css('margin-top', '30px');
    }

    if (document.getElementById('capitaFlashMap')) {
        return $('.bdr-right').css('border-right', 'none');
    }

    if (typeof Cufon !== 'undefined') {
        Cufon.replace('.subsite-header2');
    }

    if (document.getElementById('findAContactHeader')) {
        stripBadMarkup('p');
    }

    $('.searchB input').val('');

    $('.ddlLocation').change(function() {
        $('.ddlRegion').val('-1');
    });

    $('.ddlRegion').change(function() {
        $('.ddlLocation').val('-1');
    });

    $('#generalContactsTab').click(function() {
        $('.news-e-box').show();
    });

    $('.newsSearch').val('Who are you looking for?');
    $('.newsSearch').focus(function() {
        $(this).val('');
    });
    //    $('.newsSearch').blur(function() {
    //        $(this).val('Who are you looking for?');
    //    });

    //Misc Styling

    $('.officeColumn :last-child').css('border-right', 'none');

    // Add color to tables

    $(".ImmTS_Default").each(function() {
        $("tr:first", this).addClass("tableHeader");
        $("th", this).addClass("tableHeader");
    }
    );

    $("#primary-nav li").hover(function() {
        if ($(this).hasClass('.re2')) {
            $("#primary-nav-wrap-outer").addClass('top-rusty');
        }
        else {
            $("#primary-nav-wrap-outer").removeClass('top-rusty');
        }

    }, function() {

        $("#primary-nav-wrap-outer").removeClass('top-rusty');

        if ($('.re2 .tn-selected')) {
            $("#primary-nav-wrap-outer").addClass('top-rusty');
        }

    });

    if ($('.re2 .tn-selected')) {
        $("#primary-nav-wrap-outer").addClass('top-rusty');
    }

    // Hide border on tabs

    $(".on").prev().addClass("hideBorder");

    $(".jshide").attr("style", "display:none;");

    $('.fSearch').attr("value", "Search");

    $('.fSearch').focus(function() {
        if (this.value == 'Search') {
            this.value = ' '
        }
    });

    $('.fSearch').blur(function() {
        if (this.value == '') {
            this.value = 'Search'
        }
    });

    // search form button rollover
    $(".searchButton").hover(function() {
        $(this).attr("src", "/images/search-btn-on.gif");
    }, function() {
        $(this).attr("src", "/images/search-btn.gif");
    });

    // search form button (large) rollover project detail
    $("#pd-search").hover(function() {
        $(this).attr("src", "/images/pd-search-on.gif");
    }, function() {
        $(this).attr("src", "/images/pd-search.gif");
    });

    // search form button (small) rollover project detail
    $("#pf-submit-button").hover(function() {
        $(this).attr("src", "/images/search-btn-on.gif");
    }, function() {
        $(this).attr("src", "/images/dl-search-btn.gif");
    });

    // search form button (large) rollover project detail
    $("#dl-goBtn").hover(function() {
        $(this).attr("src", "/images/Downloads_roll.jpg");
    }, function() {
        $(this).attr("src", "/images/dl-go.gif");
    });

    $(".dlSubmit").hover(function() {
        $(this).attr("src", "/images/search-btn-on.gif");
    }, function() {
        $(this).attr("src", "/images/dl-search-btn.gif");
    });

    //expertise keyword search
    $(".dlSubmitExp").hover(function() {
        $(this).attr("src", "/images/search-roll-large.jpg");
    }, function() {
        $(this).attr("src", "/images/exp-search-btn.gif");
    });

    // search form button (large) rollover news listing
    $(".newsSearchBtn").hover(function() {
        $(this).attr("src", "/images/newsBtn-on.gif");
    }, function() {
        $(this).attr("src", "/images/newsBtn.gif");
    });

    // search form button (small) rollover news listing
    $(".newsSubmit").hover(function() {
        $(this).attr("src", "/images/search-btn-on.gif");
    }, function() {
        $(this).attr("src", "/images/dl-search-btn.gif");
    });

    //#detect if chrome
    var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase());
    if (is_chrome) $("html").addClass("chrome-fix");


    // Alternate table row colours
    $(".ImmTS_CaptiaSymonds tr:even").addClass("evenRow");
    $(".ImmTS_CaptiaSymonds tr:odd").addClass("altRow");
});





