function slideSwitch() {
var $active = $('#slidewrapper div.active');
if ( $active.length == 0 ) $active = $('#slidewrapper div:last');
var $next =  $active.next().length ? $active.next()
: $('#slidewrapper div:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1500, function() {
$active.removeClass('active last-active');
});
}

$(function() {

//credit date load
var d = new Date();
$(".thisyear").html(d.getFullYear());  

//withsubmenu hover
$("#withsubmenu").hover(function(){
$("#menupopwrapper0").clearQueue();
$("#menupopwrapper0").slideUp();
var p = $(this).offset();
var h = $(this).outerHeight();
var x = p.left + "px";
var y = (p.top + h + 1) + "px";
$("#menupopwrapper").css("left",x);
$("#menupopwrapper").css("top",y);
$("#menupopwrapper").slideDown();
},function(){
$("#menupopwrapper").delay(1000).slideUp();
});

//submenu stop animation
$("#menupopwrapper > div").hover(function(){
$("#menupopwrapper").clearQueue();
},function(){
$("#menupopwrapper").delay(1000).slideUp();
});

//withsubmenu0 hover
$("#withsubmenu0").hover(function(){
$("#menupopwrapper").clearQueue();
$("#menupopwrapper").slideUp();
var p = $(this).offset();
var h = $(this).outerHeight();
var x = p.left + "px";
var y = (p.top + h + 1) + "px";
$("#menupopwrapper0").css("left",x);
$("#menupopwrapper0").css("top",y);
$("#menupopwrapper0").slideDown();
},function(){
$("#menupopwrapper0").delay(1000).slideUp();
});

//submenu0 stop animation
$("#menupopwrapper0 > div").hover(function(){
$("#menupopwrapper0").clearQueue();
},function(){
$("#menupopwrapper0").delay(1000).slideUp();
});

//start slideshow
if($("#slidewrapper").length > 0){
setInterval( "slideSwitch()", 4000 );
}

//start tickertape
oitapwrite();

//set spanish flag
var spain = $("#spanish").position();
var spaintop = (spain.top - 10) + "px";
$(".spain").css("top",spaintop); 

});
