var $timeOut;
var $j = jQuery.noConflict();

$j(document).ready(function(){
	
	$j(".sliding-content").css("display", "none");
	
    setInterval( "slideShow()", 2500 );
    $timeOut = setTimeout( "hideSlideShow()", 5000 );
    $j("#home-content").bind("mouseover", hideSlideShow);


    $j(".section-link").bind("click", function(e){
        e.stopImmediatePropagation()
        e.preventDefault(); 
        $j("#how-we-work").slideToggle();
        return false;
    });


    $j("#nav-list li a").bind("mouseover", function(){
        $j(this).parent().siblings().find("a img").animate({
            opacity: 0.4
        }, 500 );
    })

    $j("#nav-list li a").bind("mouseout", function(){
        $j("#nav-list li a img").animate({
            opacity: 1
        }, 500 );
    });


});



function hideSlideShow(){
    $j("#home-content").removeClass("pointer-cursor").unbind("mouseover");
    $j("#slideShow img").attr("title", "").attr("alt", "");
    $j("#slideShow").css('z-index',1);
    $j("#slideShow").fadeTo("slow", 0.25, showHomeContent);
}

function showHomeContent() {
    clearTimeout($timeOut);
    $j(".sliding-content").fadeIn("slow");
    $j("#how-we-work").css('z-index',20);
    $j("#client-list").css('z-index',21);
}

function clearAttributes(){
    $j("#home-content").removeClass("pointer-cursor");
}


function slideShow() {

    var $active = $j('.slideshow IMG.active');

    if ( $active.length == 0 ) $active = $j('.slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
    : $j('.slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order

    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({
        opacity: 0.0
    })
    .addClass('active')
    .animate({
        opacity: 1.0
    }, 750, function() {
        $active.removeClass('active last-active');
    });
}



