var mt;
var showing = "dining_room";
var st;
var picNum = 1;

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

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

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
		
//alert($active.id);
    
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 2000, function() {
            $active.removeClass('active last-active');
        });
		
	// this is to show the correct overlay on the left
	var picArr = ['dining_room','kitchen','lounge','bar'];
	setOverlay(picArr[picNum], 'fade');
	picNum++;
	if (picNum >= picArr.length) picNum = 0;
}

$(function() {
    st = setInterval( "slideSwitch()", 4500 );
});

function mouseoverTimeout(which) {
//alert('mouseover')
  clearInterval(st);
  $('#slideshow').hide();
  if (which == null || which == "") {
	which = showing;
    mt = setTimeout('showPicture("' + which + '")', 100);
  } else if (which == showing) {
	showPicture(which);
  } else {
    showing = which;
    mt = setTimeout('showPicture("' + which + '")', 100);
  }
  mt = setTimeout('showPicture("' + which + '")', 100);
  //showPicture(which);
}

function setOverlay(which, type) {
  if (type == 'fade') {
    $('#home_top_left_overlay').fadeOut(800);
    setTimeout('document.getElementById("home_top_left_overlay").className = "content_top_left_overlay_' + which + '"',800);
	$('#home_top_left_overlay').fadeIn(800);
  }
  if (type == 'show') {
	$('#home_top_left_overlay').hide();
	document.getElementById("home_top_left_overlay").className = "content_top_left_overlay_" + which;
	$('#home_top_left_overlay').show();
  }
}

function mouseoutTimeout() {
  clearTimeout(mt);	
}

function showPicture(which) {
  showing = which;
  $('#slideshow_pic').hide();
  document.getElementById('slideshow_pic').src = "images/img_home_content_" + which + ".jpg";
  document.getElementById('slideshow_pic').style.display = "block";
  $('#slideshow_pic').show();	
  setOverlay(which, 'show');
}
