/*
	javascript by alan.james.m@gmail.com © Plad 2009
	utilising dojo 1.1.1
*/ 

  dojo.require("dojo.fx");

   dojo.addOnLoad(init);

   var slideshow, slideshow2, imgs, imgsLngth, i=0, qs, qsLngth, q=0,  sth_sp, lnx;

   function init(){	
		addHoverFx();
		slideshow = document.getElementById('slideshow');
		if(slideshow) imgs = slideshow.getElementsByTagName('div');
		if(imgs){
	      	imgs = slideshow.getElementsByTagName('div');
			imgsLength = imgs.length;
		   /*
	      	xfade(imgsArray,counter,dur,imgsArrayLength);
		   */
			dojo.fx.chain([ dojo.fadeIn( { beforeBegin:function(){
									imgs[0].style.opacity=0.1;
	        							imgs[0].style.filter="alpha(opacity = 1)";
								}, node:imgs[0], duration:1500, onEnd:function(){
													xfade(imgs,i,1500);
													}
			 } ) ]).play();
	}
	     
		slidequotes = document.getElementById('quotes');
		if(slidequotes) qs= slidequotes.getElementsByTagName('div');
		if(qs){
			qsLength = qs.length;
			dojo.fx.chain([ dojo.fadeIn( { beforeBegin:function(){
									qs[0].style.opacity=0.1;
	        							qs[0].style.filter="alpha(opacity = 1)";
								}, node:qs[0], duration:2500, onEnd:function(){
												xfade(qs, q, 2500);
													}
			 } ) ]).play();
			
		}     
	}

function xfade(objs,i,speed){
	var objsLngth = objs.length;
      if(i!=0){//fade out images one by one, front to back (more efficient than cross-fading):
         dojo.fx.chain([
            dojo.fadeOut({ node:objs[i],duration:speed,onEnd:function(){
                                                             i--;
                                                             xfade(objs,i,speed);
															} 
				 })
	   ]).play(speed);
      }else {//@ last image (i=0) - cross-fade it with front image, then reset all opacity to full & start again:
         dojo.fx.combine([
            dojo.fadeOut({ node:objs[i],duration:speed}),
            dojo.fadeIn({ node:objs[objsLngth-1],duration:speed,onEnd:function(){
                                       for(var j=0;j<(objsLngth);j++){                       
                                          objs[j].style.opacity=.99;
                                          objs[j].style.filter="alpha(opacity = 99)";
                                       }
                                       i=objsLngth-1;
                                       xfade(objs,i,speed);
                                   												}
				})
	   ]).play(speed*2);
      }      
   }

   function showMore(){
	document.getElementById("int1").style.display="none";
	document.getElementById("int2").style.display="block";
	
   }
   function showLess(){
	document.getElementById("int2").style.display="none";
	document.getElementById("int1").style.display="block";
	
   }
   
   function qfade(){
        dojo.fx.chain([
			dojo.fadeIn({node:qs[i],duration:1000, onEnd:function(){qs[q].style.filter="alpha(opacity = 99)";} 
			}),
			dojo.fadeOut({node:qs[q],duration:2000,
					onEnd:function(){
								
								(q!=qsLngth-1) ? q++ : q=0;
								
                                 qfade();
					} 
			})
	    ]).play(10); 

   }
   
   function addHoverFx(){
		var links= dojo.query('.navLink');
		var over=false
		links.connect('onmouseenter', function(e) {
		if(!over){
		   over=true;
		    dojo.fx.chain([
		        dojo.fadeOut({node:e.target, duration:1, onEnd:function(){
											dojo.addClass(e.target,'hovr');
										 	}
					  }),
		        dojo.fadeIn( { node:e.target, duration:1600,onEnd:function(){} } )
		    ]).play();
		}

		});

	
	    links.connect('onmouseout', function(e) {
		if (dojo.query('.inner').length>0 && over){
			over=false;
		  	dojo.fx.chain([
		        dojo.fadeOut({node:e.target, duration:1, onEnd:function(){
											dojo.removeClass(e.target,'hovr');
										 }
					  }),
		        dojo.fadeIn( { node:e.target, duration:1600,  onEnd:function(){} } )
		    ]).play();
		}else if(dojo.query('.home').length>0 && over){over=false;}
		});
	
	}
	
 
