var dw = null;
var ddw = null;

$(document).ready(function() {
    
    Cufon.replace('h1');
    Cufon.replace('.links h3');

	$("#dw").mouseover(function () {
		//$("#dw .overlay").fadeIn();
		$("#dw .overlay").css('display','block');
   });

	$("#ddw").mouseover(function () {
		//$("#ddw .overlay").fadeIn();
		$("#ddw .overlay").css('display','block');
   });

	$("#dw .overlay").mouseout(function () {
		//dw = setTimeout("$('#dw .overlay').fadeOut()", 100);
		dw = setTimeout("$('#dw .overlay').css('display','none')", 100);
   });

	$("#ddw .overlay").mouseout(function () {
		//ddw = setTimeout("$('#ddw .overlay').fadeOut()", 100);
		ddw = setTimeout("$('#ddw .overlay').css('display','none')", 100);
   });

	$("#dw .content").mouseover(function () {
		clearTimeout(dw);
   });

	$("#ddw .content").mouseover(function () {
		clearTimeout(ddw);
   });

	$("#dw .logo").mouseover(function () {
		clearTimeout(dw);
   });

	$("#dw .text").mouseover(function () {
		clearTimeout(dw);
   });

	$("#dw .links").mouseover(function () {
		clearTimeout(dw);
   });

	$("#ddw .logo").mouseover(function () {
		clearTimeout(ddw);
   });

	$("#ddw .text").mouseover(function () {
		clearTimeout(ddw);
   });

	$("#ddw .links").mouseover(function () {
		clearTimeout(ddw);
   });

	$(function() {
		if ($("#dw .images img").length > 1) {
	   	setInterval("slideDW()", 8000);
   	}
		if ($("#ddw .images img").length > 1) {
	    	setTimeout("slideDDW()", 4000);
	      setTimeout("setInterval('slideDDW()', 8000)", 4000);
   	}
	});
	

    $('#twitterstream .tweet ul').innerfade({
	    animationtype: 'fade',
	    speed: 750,
	    timeout: 5000,
	    type: 'random',
	    containerheight: '1em'
    });


});

function slideDW() {
    var $active = $('#dw .images IMG.active');

    if ( $active.length == 0 ) $active = $('#dw .images IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#dw .images IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideDDW() {
    var $active = $('#ddw .images IMG.active');

    if ( $active.length == 0 ) $active = $('#ddw .images IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#ddw .images IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
