	$(document).ready(
		function(){
			bindMenu();
			bindSignUp();
			bindPlaceHolder();
			startQuotes();
			startTwitter();
			startGallery();
			startSmallGallery();
			setLinkBoxes();
			bindContactUs();
		});
	
	
	
	function bindContactUs(){
		$('#contact-us button').click(function(){
			
			comlist=new Object();
			comlist['name']=$('#contact-us #name').val();
			comlist['email']=$('#contact-us #email').val();
			comlist['comment']=$('#contact-us #comment').val();
			$('#contact-us').text('Sending comment...');
			$('#contact-us').load('../sections/_sendcontactmail.php',comlist);
			return false;
		});
		
	}
	
	var quoteMax=0;
	var quotePointer=1;
	var quoteList;
	var quoteTime=5000;
	
	function startQuotes(){
		quoteList=$('.quote-item');
		quoteMax=quoteList.length;
		setTimeout('nextQuote()',quoteTime);		
	}
	
	function nextQuote(){
		$('.quote-item:visible').stop().fadeTo('slow',0);
		quoteList.eq(quotePointer).stop().fadeTo('slow',1)
		quotePointer++;
		if(quotePointer>=quoteMax){
			quotePointer=0;
		}
		setTimeout('nextQuote()',quoteTime);		
		
	}
	
	
	
	function bindSignUp(){
		$('#sign-up-button').click(function(){
			comlist=new Object();
			comlist['name']=$('#signup-name').val();
			comlist['email']=$('#signup-email').val();
			if(comlist['name'].length>2 && comlist['email'].length>2){
				$('#signup').load('../sections/_signupcomp.php',comlist);
			}else{
				$('#signup-error').text('Please enter name and valid email address');
			}
			
			
			return false;
		});
	}

	function bindPlaceHolder(){
		$('.placeholder').each(function(){
			t=$(this);
			t.val($(this).attr('data-placeholder'));
			t.addClass('placeholder-text');
		});
		$('.placeholder').focus(function(){
			t=$(this);
			if(t.val()==t.attr('data-placeholder')){
				t.val('');
				
				
			}else{
				
			}
			t.removeClass('placeholder-text');
		});
		$('.placeholder').blur(function(){
			t=$(this);
			if(t.val()==''){
				t.val(t.attr('data-placeholder'));
				t.addClass('placeholder-text');
			}else{
				t.removeClass('placeholder-text');
			}
		});
	}
	
	var menuTimer;
	
	
	function bindMenu(){
		$('.hassubmenu').mouseover(function(){
			clearTimeout(menuTimer);
			$('#menu a').removeClass('menu-hover');
			$('.submenu').hide();
			t=$(this);
			t.addClass('menu-hover');
			n=t.next();
			xy=t.position();
			n.css({left:xy.left}).show();
		});
		
		$('.hassubmenu').mouseleave(function(){
			t=$(this);
			clearTimeout(menuTimer);
			menuTimer=setTimeout('hideMenu(t)',200);
		});
		
		$('.submenu').mouseover(function(){
			clearTimeout(menuTimer);
		});
		
		$('.submenu').mouseleave(function(){
			clearTimeout(menuTimer);
			$(this).hide();
			$('#menu a').removeClass('menu-hover');
		});
	}
	
	function hideMenu(t){
		$('#menu a').removeClass('menu-hover');
		t.next().hide();
	}
	
	function startTwitter(){
		$(".tweet:not('.cms-template-list .tweet')").tweet({
			    join_text: "auto",
			    username: "M4Children",
			    avatar_size: 0,
			    count: 10,
			    auto_join_text_default: "we said,", 
			    auto_join_text_ed: "we",
			    auto_join_text_ing: "we were",
			    auto_join_text_reply: "we replied",
			    auto_join_text_url: "we were checking out",
			    loading_text: "loading tweets...",
			    callback:startTweetFade()
			  });				
	}






	var maxTweets=0;
	var thisTweet=0;
	var tweetObj;
	var tweetHover=0;

	function startTweetFade(){
		setTimeout('delayedStartTweet()',1000);	
	}
	
	function delayedStartTweet(){
		tweetObj=$('.tweet_list li');
		maxTweets=tweetObj.size();
		fadeTweet();
			
	}

	function fadeTweet(){
		thisObj=tweetObj.eq(thisTweet);
		tweetObj.stop().animate({left:'-300'},400);
		thisObj.stop().animate({left:'300'},0);
		thisObj.stop().animate({left:'0'},400);
		thisTweet++;
		
		if(thisTweet>=maxTweets){
			thisTweet=0;
		}
		setTimeout('fadeTweet()',4000);
	}
	
	var maxImages=0;
	var thisImage=0;
	var imagesObj;
	
	function startGallery(){
		imagesObj=$('.gallery img');
		maxImages=imagesObj.length;
		gallery();
	}
	
	function gallery(){
		if($('.gallery').hasClass('gallery-active')){
			thisObj=imagesObj.eq(thisImage);
			imagesObj.stop().fadeTo('slow',0);
			thisObj.stop().fadeTo('slow',1);
			thisImage++;
			if(thisImage>=maxImages){
				thisImage=0;
			}
		}
		setTimeout('gallery()',4000);
		
	}
	
	var maxSmallImages=0;
	var thisSmallImage=0;
	var imagesSmallObj;
	
	function startSmallGallery(){
		imagesSmallObj=$('.gallerysmall img');
		maxSmallImages=imagesSmallObj.length;
		smallGallery();
	}
	
	function smallGallery(){
		if($('.gallerysmall').hasClass('gallery-active')){
			thisSmallObj=imagesSmallObj.eq(thisSmallImage);
			imagesSmallObj.stop().fadeTo('slow',0);
			thisSmallObj.stop().fadeTo('slow',1);
			thisSmallImage++;
			if(thisSmallImage>=maxSmallImages){
				thisSmallImage=0;
			}
		}
		setTimeout('smallGallery()',4000);
		
	}	
	
	function setLinkBoxes(){
		if($('#no-animation').text()!='yes'){
			$('.news-4-text,.news-2-text,.news-8-text').each(function(){
				dd=$(this).find('a');
				if(dd.length==1){
					tHref=dd.attr('href');
					dd.remove();
					$(this).wrap('<a href="'+tHref+'"></a>');
				}
			});
		}
	}
	

	
	
	
