
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 
    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);
    }

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

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

    if ($(".casestudy-listing li").length > 3) {
        var prev = $("<a href='#' class='prev'><img src='/site_media/images/cs-prev.png' width='58' height='144' /></a>");
        var next = $("<a href='#' class='next'><img src='/site_media/images/cs-next.png' width='58' height='144' /></a>");
        $('.casestudy-listing').css('margin-left', '0px');
        $('.casestudy-listing li').css({
                'margin-left' : 0,
                'margin-right' : 21
        });
        $(".casestudy-container").append(prev).append(next).jCarouselLite({
           btnNext: ".next",
           btnPrev: ".prev"
        });
    } 


});

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


