var F_ID;

$(document).ready(function() {
    
    // allow the sections to be clickable
    $(".sectionbox").click(function() {
        window.location = $(this).find("a:first").attr("href");
    }).hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    })
   
    // force drop link open in new window
    $(".designedby a").attr("target", "blank")
   
    // toggle the search text
    $(".searchtext").focus(function() {
        if($(this).val() == 'Search...') {
            $(this).val('')
        }
    }).blur(function() {
        if($(this).val() == '') {
            $(this).val('Search...')
        }
    })
    
    // enable link on email
    $(".contactinfo dl:first").click(function() {
        window.location = $(this).find("a:first").attr("href");
    }).hover(function() {
        $(this).addClass('hover')
    }, function () {
        $(this).removeClass('hover') 
    })
    
    // sort out the sitemap
    $(".sitemap-sectors li span:first").wrap("<a href='/sectors/'></a>");

    // Homepage 
    if($('.casestudybox').length > 0)
    {
        var SLIDE_WAIT = 7000;
        var p = 0;

        function nextFeature(){
            var prev = p;
            p = p < $('.casestudybox li').length-1 ? p+1 : 0 
            $('.casestudybox li').eq(prev).fadeOut(500, function(){
                $('.casestudybox li').eq(p).hide().fadeIn(500)
            })
        }

        function stopFeatures(){
            clearInterval(F_ID); 
        }

        function startFeatures(){
            clearInterval(F_ID); 
            F_ID = setInterval(nextFeature, SLIDE_WAIT);
        }

        // Proxy thickbox remove
        if(typeof(window.tb_remove) == 'function'){
            var _tb_remove = window.tb_remove;
            window.tb_remove = function(){
                _tb_remove();
                startFeatures();
            }
        }

        $('.casestudybox li a').click(function(){ stopFeatures() });

        if($('.casestudybox li').length > 1) startFeatures();
    }
   
});



this.removeMe = function() {
    parent.tb_remove();    
}

