FadingObjects = [];
FadingObjectsFunction = function(i) {
	var elm = FadingObjects[i];
	if(elm) {		
	      elm.children().first().fadeOut()
	         .next().fadeIn()
	         .end().appendTo(elm.get());
	}
}



jQuery(document).ready(function($) {
	
	if($('.fadein').length) {
		$('.fadein').each(function(index) {
			$('.fadein *').addClass("posAbs");
			$(this).children().hide();
			
			var delay = 3000;
			var title = $(this).attr("title");
			if(title) {
				var lookFor = "delay=";
				if(title.indexOf(lookFor)==0) {
					delay = title.substr(lookFor.length);
				}
			}
			
			var i = FadingObjects.length;
			FadingObjects[i] = $(this);
			FadingObjectsFunction(i);
			setInterval("FadingObjectsFunction("+i+")", delay);
		});
	}
	
	if($('#js-news').length) {
	    $('#js-news').ticker({
	            speed: 0.25,           // The speed of the reveal
	            ajaxFeed: false,       // Populate jQuery News Ticker via a feed
	            feedUrl: false,        // The URL of the feed
	    	                       // MUST BE ON THE SAME DOMAIN AS THE TICKER
	            feedType: 'xml',       // Currently only XML
	            htmlFeed: true,        // Populate jQuery News Ticker via HTML
	            debugMode: false,       // Show some helpful errors in the console or as alerts
	      	                       // SHOULD BE SET TO FALSE FOR PRODUCTION SITES!
	            controls: false,        // Whether or not to show the jQuery News Ticker controls
	            titleText: '',   // To remove the title set this to an empty String
	            displayType: 'reveal', // Animation type - current options are 'reveal' or 'fade'
	            direction: 'ltr',       // Ticker direction - current options are 'ltr' or 'rtl'
	            pauseOnItems: 1000,    // The pause on a news item before being replaced
	            fadeInSpeed: 600,      // Speed of fade in animation
	            fadeOutSpeed: 300      // Speed of fade out animation
	    });
	}
	
	
	

	if($('#thumbs').length) {
		// Initially set opacity on thumbs and add
		// additional styling for hover effect on thumbs
		var onMouseOutOpacity = 0.67;
		$('#thumbs ul.thumbs li').opacityrollover( {
			mouseOutOpacity : onMouseOutOpacity,
			mouseOverOpacity : 1.0,
			fadeSpeed : 'fast',
			exemptionSelector : '.selected'
		});

		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#thumbs').galleriffic(
				{
					delay : 5000,
					numThumbs : 3,
					preloadAhead : 10,
					enableTopPager : true,
					enableBottomPager : false,
					maxPagesToShow : 5,
					imageContainerSel : '#slideshow',
					controlsContainerSel : '#controls',
					captionContainerSel : '',
					loadingContainerSel : '#loading',
					renderSSControls : false,
					renderNavControls : false,
					playLinkText : '',
					pauseLinkText : '',
					prevLinkText : '&lsaquo; Previous Foto',
					nextLinkText : 'Next Foto &rsaquo;',
					nextPageLinkText : '\u00BB',
					prevPageLinkText : '\u00AB',
					enableHistory : false,
					autoStart : true,
					syncTransitions : true,
					defaultTransitionDuration : 900,
					onSlideChange : function(prevIndex, nextIndex) {
						this.find('ul.thumbs').children().eq(prevIndex).fadeTo(
								'fast', onMouseOutOpacity).end().eq(nextIndex)
								.fadeTo('fast', 1.0);
					},
					onPageTransitionOut : function(callback) {
						this.fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn : function() {
						this.fadeTo('fast', 1.0);
					}
				});
	}
	
});

