setTimeout('rotateTestimonials()',5000);
//setupFB();

$(document).ready(function()
{
	jQuery.fn.exists=function(){return jQuery(this).length>0;};
	var thisurl=jQuery(location).attr('href');
	if($('.google-plus-one').exists())
	{
		$('.google-plus-one').each(
		function(index){
			$(this).html("<g:plusone size='medium' href='"+thisurl+"'></g:plusone>");
		});
	};
	
	if($('.fbLike').exists())
	{
		$('body').append("<div id='fb-root'>&nbsp;</div>");
		$('.fbLike').each(
		function(index){
			$(this).html("<fb:like href='"+thisurl+"' show_faces='false' font='tahoma'></fb:like>");
		});
		window.fbAsyncInit = function() {
			FB.init({appId: '107289419331332', status: true, cookie: true,xfbml: true});
		};
		(function() {
			var e = document.createElement('script'); e.async = true;
			e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js';
			document.getElementById('fb-root').appendChild(e);
		}());
	};
	
	if($('.tweet').exists())
	{
		$('.tweet').each(
		function(index){
			$(this).html("<a href='http://twitter.com/share?url="+encodeURI(thisurl)+"&amp;via=brooxdesign&amp;related=brooxdesign:%20Best%20Value%20Web%20Design%20in%20Sussex' class='twitter-share-button'>Tweet</a>");
		});
		$.ajaxSetup({async: false});
		$.getScript('http://platform.twitter.com/widgets.js');
		$.ajaxSetup({async: true});
	};
	
});

function setupFB()
{
	if(document.getElementById('fbLike')){addFBEl(document.getElementById('fbLike'));};
	
	if(document.getElementById('fb-root'))
	{
		//185550966885
		window.fbAsyncInit = function() {
		FB.init({appId: '107289419331332', status: true, cookie: true,
				 xfbml: true});
	  };
	  (function() {
		var e = document.createElement('script'); e.async = true;
		e.src = document.location.protocol +
		  '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);
	  }());
	};
}
function addFBEl(el)
{
	var elTmp=document.createElement('fb:like');
	elTmp.setAttribute('href',el.className);
	elTmp.setAttribute('show_faces','false');
	elTmp.setAttribute('font','tahoma');
	el.appendChild(elTmp);
}
function rotateTestimonials()
{
	var subHeader=document.getElementById('subHeader');
	var testimonials=subHeader.getElementsByTagName('LI');
	for(var i=0;i<testimonials.length;i++)
	{
		var thisLi=testimonials[i];
		if(thisLi.className=='current')
		{
			if(i==(testimonials.length-1)){var nextLi=testimonials[0];}else{var nextLi=testimonials[i+1];};
			nextLi.className='current';
			nextLi.style.top=140+'px';
			testimonialMoveUp(thisLi,nextLi,1);
			return;
		}
	};
}
function testimonialMoveUp(curEl,nextEl,lng)
{
	if(lng<140)
	{
		curEl.style.top='-'+lng+'px';
		nextEl.style.top=(140-lng)+'px';
		setTimeout(function(){testimonialMoveUp(curEl,nextEl,lng+1)},50);
	}
	else
	{
		curEl.className='';
		setTimeout('rotateTestimonials()',7000);
	};
}

