if (document.getElementsByTagName && document.getElementsByClassName  ) {
	// Create a link to the Javascript-only stylesheet

	var $link_element1 = document.createElement('link');
	$link_element1.setAttribute("rel","stylesheet");
	$link_element1.setAttribute("href","/assets/templates/skff/css/javascript_only.css");
	$link_element1.setAttribute("media","screen");
	

	// Append this stylesheet link to the document
	var $head_element = document.getElementsByTagName('head')[0];
	$head_element.appendChild($link_element1);
}



// Crossfader
// the starting index in the array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
var i = 0;

// the number of milliseconds between swaps.  
var wait = 3000;

// the function that performs the fade
function swapFade() {
	Effect.Fade($$('#p0 #slideshow li')[i], { duration:1.2, from:1.0, to:0.0 });
	i++;
	if (i == 2) i = 0;
	Effect.Appear($$('#p0 #slideshow li')[i], { duration:1.2, from:0.0, to:1.0 });
}





// set flag
	var runDrawing=0;
	var runPyjamas=false;
	var linkTitle=''
	var captionClosing=false;
	var captionOpening=false;

	function bounce(){
		if ($('donateBalloonContainer')){
			setTimeout(
				function(){
					new Effect.Move($('donateBalloonContainer'), {x:0,y:70,duration:4
					})
					}, 100
			)
			setTimeout(

				function(){				
					new Effect.Move($('donateBalloonContainer'), {x:-0,y:-70,duration:4,
					transition: Effect.Transitions.Bounce
					})

					}, 4100
			)
		}
	}

function init(){



	// highlight Donate link on home page on startup 
	if ($('g1') && $('p0')){ 
		$('g1').down().addClassName('active');
	}
	$$('#p0 #getInvolvedMenu li a').each( function(link) {		

			link.onmouseover = function() {
			
						//REMOVE
						$$('#getInvolvedMenu li a').each( function(don) {						
							if (don!= link){ don.removeClassName('active');							
							}							
							
						})
						
			
						linkTitle=link.getAttribute('rel');

						//get href from link
						href=this.getAttribute('href');
						$('panelCaptionLink').setAttribute('href', href);
						$('panelCaptionImage').src='/assets/templates/skff/img/'+linkTitle+'.png';
						this.addClassName('active');						
						}
		
	});








	
	// set up effects	
	if ($('illusDrawingContainer')){
		boy=$('illusDrawingContainer');
		drawing=$('illusBoard');

				boy.onclick = function() {
					if (!runDrawing){
					runDrawing=1
					new Effect.Move(drawing,{ x: 200, y: 0, duration:1 });
					
					// new Effect.SwitchOff(drawing, {duration:1});
					//	chain effects
					
					setTimeout(
						function(){
							new Effect.Move(drawing,{ x: -200, y: 0, duration:1, transition: Effect.Transitions.Bounce,
							afterFinish:function(){runDrawing=false; }
							});
							//new Effect.Appear(drawing, {duration:1.5});
							}, 2200
					)

										
					}
				}

	}


	if ($('illusBalloon')){ // home page balloon
		$('illusBalloon').setStyle({
			display:'none'
		} )
		
		setTimeout(
			function(){
				new Effect.BlindDown($('illusBalloonContainer'), {duration:1})
				new Effect.Appear($('illusBalloon'), {duration:3.5})
				}, 500
		)

		new Draggable($('illusBalloon'), {	revert:true
						});
	}
	// hide onload and reset position
	if ($('donateBalloon')){
		$('donateBalloon').setStyle({
			display:'block'
		} )		
		$('donateBalloonString').setStyle({
			display:'none'
		} )
		$('donateBalloonWrapper').setStyle({
			top:'14px',
			left:'650px'
		} )
		

		
		/*
		setTimeout(
		
			function(){
			
				new Effect.BlindDown($('donateBalloonContainer'), {duration:5, 
				transition: Effect.Transitions.Bounce, 
				afterFinish:function(){
					$('donateBalloonWrapper').setStyle({
//						zIndex:'1000',
						height:'166px'
						
						
					})
					$('donateBalloonContainer').setStyle({
						height:'166px'						
					})
					
				}
				})
				var appearDuration=3
				if(Prototype.Browser.IE){
					appearDuration=.1 // IE fade in is clunky!
				}
				
				new Effect.Appear($('donateBalloon'), {duration:appearDuration
				})
				new Effect.Appear($('donateBalloonString'), {duration:appearDuration
				})
				
				
				
				}, 2000
				
		)
*/
					$('donateBalloonWrapper').setStyle({
//						zIndex:'1000',
						height:'166px'
						
						
					})
					$('donateBalloonContainer').setStyle({
						height:'166px'						
					})
		setInterval("bounce()", 11000);


//		new Draggable($('donateBalloon'), {	revert:true			});
	}
	
	
	
	
	
	
	if ($('illusTeddies')){
		new Draggable($('illusTeddies'), {	revert:true, 
							constraint:"horizontal"
						});
		
	}

	if ($('illusPyjamasContainer')){
		illustration=$('illusPyjamasContainer');

				illustration.onclick = function() {
				if (runPyjamas==false){
					runPyjamas=true;
					// 
					new Effect.BlindUp(illustration, {duration:1.5					
								});								
					
					//	chain effects	
					new Effect.BlindDown(illustration, {queue: 'end', duration:1.5, transition: Effect.Transitions.Elastic,
							afterFinish:function(){runPyjamas=false; }
								});								
					}


					
				}

	}
	
	
	if ($('illusFloating')){
		new Draggable($('illusFloating'), {	revert:true,							 
							constraint:"vertical"
						});
		
	}
	// FAQ
	$$('#faqContainer .faq').each( function(faqItem) {
			faqItem.next(0).setStyle({
				display:'none'
			});
			
			
			
			
			
			faqItem.onclick = function() {
				// close any open ones
				$$('#faqContainer .faq').each( function(openItems) {
					if (openItems.hasClassName('open') && openItems!=faqItem){
							new Effect.BlindUp(openItems.next(0), {
								duration:.4 
					 		});
//							$$('openItems #faqIndicator')[0].innerHTML='-';
							openItems.removeClassName('open');
					}
						
				});
					 
				
				if (!faqItem.hasClassName('open')){
					new Effect.BlindDown(faqItem.next(0), {
						duration:.7,
						transition: Effect.Transitions.sinoidal
					});
//					$$('openItems #faqIndicator')[0].innerHTML='-';
					faqItem.addClassName('open');
				
				}
				else if(faqItem.hasClassName('open')){
					new Effect.BlindUp(faqItem.next(0), {
					duration:.7 
					 });
					faqItem.removeClassName('open');
//					$$('openItems #faqIndicator')[0].innerHTML='+';
				
				
				}

			}
			
			if ($('showFAQ')){
				$('showFAQ').onclick = function(){
					toggleFAQS('show');
					return false;				
				}
				
			}
			if ($('hideFAQ')){
				$('hideFAQ').onclick = function(){
					toggleFAQS('hide');
					return false;
				}
				
			}
			
			function toggleFAQS(direction){				
				$$('#faqContainer .faq').each( function(item) {					
							if (direction=='hide'){
								if (item.hasClassName('open')){
								new Effect.BlindUp(item.next(0), {
								duration:.4 
						 		});						
								item.removeClassName('open');
								}
							} else {
								if (!item.hasClassName('open')){
								new Effect.BlindDown(item.next(0), {
									duration:.4 
						 		});						
								item.addClassName('open');							
								}
							}						
				});

			}


			
	// end of FAQ functions			
	});
//	Restore .accordion_content visibility hidden in javascript_only.css
	$$('.accordion_content').each( function(accordion) {
			accordion.setStyle({
				height:'auto',
				overflow:'auto'
			});
	});


	// preload donate captions
	/*
	if ($('p0')){
		images=new Array();

		for (i=2; i<5; i++){
		// NB first one is loaded with page
			a= new Image()
			a.src='/assets/templates/skff/img/caption' + i + '.png'
		}

	}
	*/	


	// banner image caption effect 
		if ($('panelCaption')){
		var panelCaption=$('panelCaption');

			if ( $('imageCaption') ){

				var imageCaption=$('imageCaption');
				imageCaption.setStyle({
						display:'none'
				});				
				
				panelCaption.onmouseover = function() {
				
					if (!captionOpening && !captionClosing){
						new Effect.BlindDown(imageCaption, {
										beforeStart:function(){captionOpening=true},
//										queue: { position: 'end', scope: 'captionscope',limit: 2 },
										duration:.5,
										afterFinish:function(){captionOpening=false}	
						});
					}
					
				}
				
				
				panelCaption.onmouseout = function() {
				
					if (!captionClosing) {						
						new Effect.BlindUp(imageCaption, {	
										beforeStart:function(){captionClosing=true},
										delay:2,
//										queue: { position: 'end', scope: 'captionscope',limit: 2 },
										duration:.5,
										afterFinish:function(){captionClosing=false}
				 		});
					}
					
					
				}
			}
		}


	// start crossfader on home page 
	if ($('p0')){
		setInterval('swapFade()',wait);
	}

	
	
//	end of init
}




Event.observe(window, 'load', init, false);
//addEvent(window,'load',init)