//Variables
var travel = 850; //Homescreen Scroller Animation Travel
var pos = 0; //Homescreen Scroller Position
var fFlag = true; //First Time Flag

//Do things (Magical Things If We're On a Mac)
$(document).ready(function() {
    /* navigationMain(); */
    $('ul.sf-menu').superfish(
    {
        autoArrows: false,
        speed: 0
    });
//Set Search Bar Text
if ($('.fieldQueryString .textBox').attr('value') == '') {
    $('.fieldQueryString.fi-FI .textBox').attr('value', 'Hae');
    $('.fieldQueryString.en-GB .textBox').attr('value', 'Search');
}
$('.fieldQueryString .textBox').focus(function() {
    if (fFlag) { $('.fieldQueryString .textBox').attr('value', ''); }
    fFlag = false;
});

});

//Main Navigation Positioning & Actions
function navigationMain() {
    //Position to Center 
    var totalw = 0;
    $('#header .siteMap ul.level0 li').each(function() {
        totalw = totalw + parseInt($(this).width());
    });
    $('.sf-menu').css('width', totalw+'px');

    //MouseOver
    $('#header .siteMap ul.level0 li a').not('#header .siteMap ul.level0 li li a').mouseover(function() {
        var obj = $(this).closest('li');

        //Clear Old Open Submenus
        $('#header .siteMap li ul').fadeOut(10);
        $('#header .siteMap li').removeClass('isopen');

        //Open This Submenu
        obj.addClass('isopen');
        obj.children('ul').fadeIn(50);
    });

    //Hide The submenus if nobody is using them
    $('#main, #footer, #header').click(function() { navigationMainHide(); });
    $('#footer, .announcementGroupShowcase, .default #main').mouseover(function() {
        navigationMainHide();
    });
}

//Hide The submenus
function navigationMainHide() {
    $('#header .siteMap li ul').fadeOut(10);
    $('#header .siteMap li').removeClass('isopen');
}

// Activate the carousel
$(document).ready(function() {
  
  // check if frontpage 
  if (frontpage == true) {
		// Count number of items 
		var numberOfItems = $('div.announcement-showcase').length;
		
		// Declare width of bullet (with margin)
		var lengthOfBullet = 17;
		
		// Calculate the total width (width * number of items)
		var totalWidth = (numberOfItems * lengthOfBullet);
		
		// Set the total length to the div.navi element
		$('div.navi').width(totalWidth);
		
		/* Activate the bonanza */
		$('#chained').scrollable({circular: true}).navigator().autoscroll({
			interval: 14000,
			steps: 1			
		});	
    }
});
