// initialise plugins
jQuery(function($){

	// *** HEADLINES ***
	var headline_count;
	var headline_interval;
	var old_headline = 0;
	var current_headline = 0;

	function headline_rotate() {
		current_headline = (old_headline + 1) % headline_count;
		$("div.headline:eq(" + old_headline + ")").animate({top: -140},"slow", function() {
			$(this).css('top','140px');
		});
		$("div.headline:eq(" + current_headline + ")").show().animate({top: 14},"slow");
		old_headline = current_headline;
	}

	headline_count = $("div.headline").size();
	$("div.headlines:eq("+current_headline+")")
		.css('top','5px')
		.siblings().css('top','210px');

	headline_interval = setInterval(headline_rotate,4000); //time in milliseconds
	$('#scrollup').hover(function() {
		clearInterval(headline_interval);
	}, function() {
		headline_interval = setInterval(headline_rotate,4000); //time in milliseconds
		headline_rotate();
	});

	// *** MENU - SUPERFISH ***
	$('ul.sf-menu').superfish();

	// *** MENU ANIMATION ***
	$(".container > ul > li").hover(function(){
		if (!$(this).is('.nolink')){
			$("img", this).stop().animate({top:"-35px"},{queue:false,duration:100});
		}
	}, function() {
		if (!$(this).is('.nolink')){
			$("img", this).stop().animate({top:"0px"},{queue:false,duration:100});
		}
	});

	$(".containerbanners div a").hover(function(){
		$("img", this).stop().animate({top:"0px"},{queue:false,duration:50});
	}, function() {
		$("img", this).stop().animate({top:"-115px"},{queue:false,duration:100});
	});

	var nav = $('#externalNav'),
	updateLink = function(page){
		nav.find('.nolink').removeClass('nolink').trigger('mouseleave');
		nav.find('a[href="#' + page + '"]').closest('li:not(.dropdownitem)').addClass('nolink');
	};

	// *** SLIDERS ***
	$('#slider').anythingSlider({
		// If true, builds a list of anchor links to link to each panel
		buildNavigation: false,
		buildStartStop: false,
		buildArrows : false,
		autoPlay : false,
		pauseOnHover : false,
		resizeContents : false,
		hashTags : true,
		// Callback when the plugin finished initializing
		onInitialized: function(e, slider) {
			updateLink(slider.currentPage);
		},
		// Callback when slide completes - no event variable!
		onSlideBegin: function(e, slider) {
			updateLink(slider.exactPage);
		}
	});

	$('#news').anythingSlider({
		// If true, builds a list of anchor links to link to each panel
		buildNavigation: false,
		buildStartStop: false,
		autoPlay : true,
		width               : 230,       // if resizeContent is false, this is the default width if panel size is not defined
		height              : 100,       // if resizeContent is false, this is the default height if panel size is not defined
		resizeContents      : false     // If true, solitary images/objects in the panel will expand to fit the viewport
	});

	// *** SLIDER EXTRAS ***
	// set up Slider external links
	$('#externalNav a').click(function(){
		nav.find('.activelink').removeClass('activelink');
		var slide = $(this).addClass('activelink').attr('href').substring(1);
		$('#slider').anythingSlider(slide);
		return false;
	});

	// *** SLIDER FX ***
	$('#slider').anythingSliderFx({
		// base FX definitions
		// '.selector' : [ 'effect(s)', 'distance/size', 'time', 'easing' ] - 'time' and 'easing' are optional parameters
		//'.quoteSlide'         : [ 'top', '100%', '400', 'easeOutElastic' ],
		//'.quoteSlide'         : [ 'fade' ],
		'.quoteslide'             : [ 'top', '970px', '400', 'easeOutElastic' ],
		'.textSlide h3'       : [ 'top left', '200px', '500', 'easeOutCirc' ],
		'.textSlide img,.fade': [ 'fade' ],
		'.textSlide li'       : [ 'listLR' ]
	});

});
