function slideSwitch() {
    var $active = $('#agents div.active');

    if ( $active.length == 0 ) $active = $('#agents div:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#agents div:first');

    
    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}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 3000 );
});


// Gallery Rotator
$(function(){
    $('.fadein img:gt(0)').hide();
    setInterval(function(){
      $('.fadein :first-child').fadeOut()
         .next('img').fadeIn()
         .end().appendTo('.fadein');}, 
      4000);
});

$(function() {
	var theframe = $('<iframe frameborder="0" scrolling="auto"></iframe>');
	$("a[rel]").overlay({
		mask: '#000',
		onBeforeLoad: function() {
			//First get the wrap
            var wrap = this.getOverlay().find(".contentWrap");
            //Get the URL from the trigger
            var link = this.getTrigger().attr("href");
            //Add the link and style attributes to the basic iframe
            $(theframe).attr({ src: link, style: 'height:540px; width:614px; border:none;' });
            //Write the iframe into the wrap
            wrap.html(theframe);
		}
	
	});
});

