var timeout = null;

function run () {
  sloganFadeIn();
  
  timeout = setTimeout('sloganFadeOut()', 4000);
}

function sloganFadeIn () {  
  var $slogan = $('#home-slogan1');
  
  $slogan.fadeIn(500);
}

function sloganFadeOut () {
  var $slogan = $('#home-slogan1');
  
  $slogan.fadeOut(500, function () {
    slideSwitch();
  });
  
  //timeout = setTimeout('run()', 1000);
  timeout = setTimeout('slogan2FadeIn()', 1000);
}

function slogan2FadeIn () {  
  var $slogan = $('#home-slogan2');
  
  $slogan.fadeIn(500);
  timeout = setTimeout('slogan2FadeOut()', 4000);
}

function slogan2FadeOut () {
  var $slogan = $('#home-slogan2');
  
  $slogan.fadeOut(500, function () {
    slideSwitch();
  });
  
  timeout = setTimeout('run()', 1000);
}

function slideSwitch() {    
    var $active = $('#motive > img.active');

    if($active.length == 0) {
	    $active=$('#motive > img.animate');
    }

    $active.removeClass('active');

    var $next = $active.next().length ? $active.next() : $('#motive > img.animate');

    $next.addClass('active');

	$active.fadeOut(500, function () {
		$next.fadeIn(100);
	});
}

$(function() {
	timeout = setTimeout('run()', 1000);
});

