//Friends of Theatre web site scripts

/**
* Included plugins
**/

/*
 * jQuery 'onImagesLoaded' plugin v1.1.1 (Updated January 27, 2010)
 * Fires callback functions when images have loaded within a particular selector.
 *
 * Copyright (c) Cirkuit Networks, Inc. (http://www.cirkuit.net), 2008-2010.
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * For documentation and usage, visit "http://includes.cirkuit.net/includes/js/jquery/plugins/onImagesLoad/1.1.1/documentation/"
 */
(function(b){b.fn.onImagesLoad=function(j){var a=this;a.opts=b.extend({},b.fn.onImagesLoad.defaults,j);a.bindEvents=function(c,e,d){if(c.length===0)a.opts.callbackIfNoImagesExist&&d&&d(e);else{var f=[];c.jquery||(c=b(c));c.each(function(h){var i=this.src;if(!b.browser.msie)this.src="";b(this).bind("load",function(){if(jQuery.inArray(h,f)<0){f.push(h);f.length==c.length&&d&&d.call(e,e)}});if(b.browser.msie){if(this.complete||this.complete===undefined)this.src=i}else this.src=i})}};var g=[];a.each(function(){if(a.opts.itemCallback){var c; c=this.tagName=="IMG"?this:b("img",this);a.bindEvents(c,this,a.opts.itemCallback)}if(a.opts.selectorCallback)this.tagName=="IMG"?g.push(this):b("img",this).each(function(){g.push(this)})});a.opts.selectorCallback&&a.bindEvents(g,this,a.opts.selectorCallback);return a.each(function(){})};b.fn.onImagesLoad.defaults={selectorCallback:null,itemCallback:null,callbackIfNoImagesExist:false}})(jQuery);

// end of onImagesLoad plugin


/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

// end of scrollTo plugin

/**
* Animate slogan in head banner
**/

jQuery(document).ready(function($){

	$("#ftslogan").newSlogan();

});
var slognbr = 1;
var slogans = new Array();
slogans[0] = "encouraging live theatre in the UK";
slogans[1] = "supporting live theatre in the UK";
slogans[2] = "promoting live theatre in the UK";

// newSlogan()
// - sets timer event to cycle through slogans
jQuery.fn.newSlogan = function(speed,callback) {
	return this.each(function(){

		slognbr = slognbr + 1;
		if (slognbr > 2) slognbr = 0;

		jQuery(this).hide().html("<p>" + slogans[slognbr] + "</p>").fadeIn();

		var t=setTimeout("jQuery('#ftslogan').newSlogan()",10000);
	});
};
	
jQuery(document).ready(function($){

/**
* Collapse/expand menu to highlight current page and parent/children
*/
	$('#ftmenu ul ul').hide();
	$('li.current_page_item:hidden').parent('ul').show();
	$('li.current_page_item ul').show();
	$('#ftmenu #eventsmenu ul').show();

/**
* Blur search box text
*/
	$('#s').focusin(function(){
		var val = $(this).val();
		$(this).val((val=='Search this site') ? '' : val);
	});
	$('#s').focusout(function(){
		var val = $(this).val();
		$(this).val((val=='') ? 'Search this site' : val);
	});
	
	

/**
* Hide Firefox button if Mozilla browser being used
**/
	if (jQuery.browser.mozilla){
		jQuery("#standards a:first").hide();
	};

/**
* Scroll to second section in page if ?review on end of URL.
**/
	if (window.location.search.substring(1) == 'review' && jQuery('div.eventdescription').size() > 1)
	{
		jQuery(window).scrollTo('div.eventdescription:eq(1)', 700, { easing:'swing'});
	}

});

/**
* Read FT twitter feed and convert <li> items into news ticker
**/

jQuery(document).ready(function($){
	var feedwidth = 0;
	var feeddur;
	var ticker;
	var feed;
	
	function FTtick(){
		$(feed).animate({left:'-=' + feedwidth}, feeddur , "linear", function() {
			$(feed).css({'left':'20px'}); FTtick();
		});
	}
	
	function runticker(){
		ticker = $('#twitterfeed');
		feed = $(ticker).find('ul');
		// init width to large value to prevent cropping
		$(feed).css({
			'width':'1500px'
		});		$(ticker).find('h3').hide();
		// calc overall size of feed
		$(feed).find('li').each(function(){
			feedwidth += $(this).outerWidth(true);
		});
		$(feed).css({
			'width':feedwidth
		});
		// calc duration at 5 chars/sec
		feeddur = feedwidth * 20;
		FTtick();
	}
	
	setTimeout (function(){
		$('#twitterfeed').load('http://friendsoftheatre.org/ftfeed.php', function(){
			runticker();
		});
	}, 5000);
		
});

