$(document).ready(function() {
	// Setup welcome message ticker
	var count = 0;
	var items = 11;
	var itemHeight = 45;
	var cycle = Math.floor(Math.random()*items);
	var startPos = "-" + (cycle * itemHeight) + "px";
	bgPos = "0 " + startPos;
	$('#languages_box p').eq(0).css({backgroundPosition: bgPos})
	setTimeout(function() { showNextLang(items, count, cycle, itemHeight); }, 3000);
	
	// Navigation drop-downs
	$("#navigation > ol > li").hover(  
         function () {  
             //show its submenu  
             $('ol', this).show();
         },   
         function () {  
             //hide its submenu  
             $('ol', this).fadeOut(100);           
         }  
     );
     
     if ($("#contactForm").length > 0) {
		$("#contactForm").formvalidation({
			errorMsgBGColor: '#f8E8E8',
			errorMsgColor: '#AD0000',
			errorMsgBorderColor: '#EABEBE',
			focusBorderColor: '#09579D',
			emailFields: $('#contactForm input:enabled.emailaddr'),
			numericFields: $('#contactForm input:enabled.numeric'),
			allFieldRows: $('.emailRow, .fieldRow')
		});
	}
	$('#header_banner li:not(.active)').css({'opacity': '0.0'});
	$('#header_banner li.active').css({'opacity': '1.0'});
	var bannerSw = setInterval( "bannerSwitch()", 5000 );
});

function showNextLang(items, count, cycle, itemHeight) {
	cycle++;
	var bgPos = "0 -" + (cycle * itemHeight) + "px";
	if (cycle >= items) {
		cycle = 0;
		bgPos = "0 0";
	}
	$('#languages_box p').eq(0).fadeOut(500, function() {
		$('#languages_box p').eq(0).css({backgroundPosition: bgPos});
		$('#languages_box p').eq(0).fadeIn(500);
	});
	
	
	setTimeout(function() { showNextLang(items, count, cycle, itemHeight); }, 3000);
}

function bannerSwitch() {
    var $active = $('#header_banner li.active');

    if ( $active.length == 0 ) $active = $('#header_banner li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#header_banner li:first');


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
    });
}