﻿/*
*******************************************************************************
*	Copyright © Neoco; www.neoco.com
*	$Id: general.js 1924 2010-11-05 15:37:43Z alex $
*	purpose:  site-wide JavaScript
*
*******************************************************************************
*/
$(document).ready(function() {
	
	// News Ticker
	if ($('#NEO-news').length) { // implies *not* zero
		var options = {
			newsList: "#news",
		    startDelay: 10,
		    tickerRate: 60,
		    placeHolder1: "_",
		    placeHolder2: "_"
		}
		$().newsTicker(options);
	};
	
	// banner
	if ($('#NEO-slider').length) { // implies *not* zero
		$('#NEO-slider ul#tabs li').featureList({
			output		: 'ul#output li',
			pause_on_hover : false,
			transition_interval : 5000,
			start_item	: 0
		});
	};
	
	// Twitter
	if ($('#NEO-twitter').length) { // implies *not* zero
		$("#NEO-twitter .tweet p").css("display","none");
		$("#NEO-twitter .tweet").tweet({
			join_text: null,
			username: "britishcouncil",
			count: 2,
			loading_text: "loading tweets..."
		});
	};
	
	// Flickr Photo Gallery
	if ($('#NEO-photos').length) { // implies *not* zero
		$('#NEO-photos .noscript').css({'display':'none'});
		$('#NEO-photos #gallery').css({'display':'block'});
		$('#NEO-photos #descFlickr').css({'display':'block'});
		$('#NEO-photos #slideshow').css({
			//'width' : $('#NEO-photos .slideshow-container').width()+'px',
		    //'height' : $('#NEO-photos .slideshow-container').width()+'px'
		    'width' : '317px',
		    'height' : '238px'
		});	
			// grab the RSS feed from the set and make sure it has '&format=json&jsoncallback=?' at the end
			// if format says RSS change it, otherwise add the format
			// always make sure the jsoncallback is present
                $.getJSON(flickrFeed + "&format=json&jsoncallback=?", function (data) {
				$numThumbs = 5 // change this to 10 if it is the large column
				$count = 0;
				$.each(data.items, function(i,item){
					if($count<$numThumbs){
						$count++;
						var newthumb = $("ul.thumbs").children("li:first").clone();
						var baseimg = item.media.m;
								
						var thumbimg = baseimg.replace("_m.jpg", "_s.jpg");
						$(newthumb).find("img").attr("src", thumbimg).attr("alt", item.title);
									
						var disimg = baseimg.replace("_m.jpg", ".jpg");
						$(newthumb).find(".thumb").attr("href", disimg);
									
						//var lgeimg = baseimg.replace("_m.jpg", "_b.jpg");
						//$(newthumb).find(".download").children("a").attr("href", lgeimg);
									
						var title = item.title;
						var description = item.description;
								
						var desc = $("<div />").append(description);
						if ($(desc).children().size() == 3) {
							description = $(desc).children("p:last").html();
						} else {
							description = "";
						}
									
						$(newthumb).find(".image-title").empty().html(title);
						//$(newthumb).find(".image-desc").empty().html(description);
									
						$("ul.thumbs").append(newthumb);
					}
				});	
							
				$("ul.thumbs").children("li:first").remove();
							
				// Initially set opacity on thumbs and add
				// additional styling for hover effect on thumbs
				var onMouseOutOpacity = 0.67;
				$('#thumbsFlickr ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
							
				// Initialize Advanced Galleriffic Gallery
				var gallery = $('#thumbsFlickr').galleriffic({
					delay:                     5500,
					numThumbs:                 $numThumbs,
					preloadAhead:              -1,
					enableTopPager:            false,
					enableBottomPager:         false,
					maxPagesToShow:            1,
					imageContainerSel:         '#slideshow',
					controlsContainerSel:      '#controls',
					captionContainerSel:       '.caption-container',
					loadingContainerSel:       '#loading',
					renderSSControls:          false,
					renderNavControls:         false,
					enableHistory:             false,
					autoStart:                 true,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					enableKeyboardNavigation:  false,
					onSlideChange: function(prevIndex, nextIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
						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);
					}
				});						
			});
	};
	
}); // end document ready

