/********************************************
***             Window dom ready          ***
********************************************/
window.addEvent("domready", function(){
        if ($('no1')==null) return false;
        $('no1').setStyle('opacity','0');
        $('no2').setStyle('opacity','0');
        $('no3').setStyle('opacity','0');
      //  $('no4').setStyle('opacity','0');
        
        if ($('banner-no1')) $('banner-no1').setStyle('opacity','0.85');
        if ($('banner-no1')) $('banner-no2').setStyle('opacity','0');
        if ($('banner-no1')) $('banner-no3').setStyle('opacity','0');
        if ($('banner-no1')) $('banner-no4').setStyle('opacity','0');
        
        getInitial();
        autoResponde.periodical(5000);
        numOfSlides = 4;
        flow = true;
        current = "";
        
        var indexNo;
        function getInitial(){
            $('no1').fade('in');
			indexNo = 1;
        }
        
        $$(".triggers").each(function(el){
    		el.addEvent("click", function(e){
                fadeInEvent($('no' + el.id.substr(10)), el.id.substr(10));
                flow = false;
    		})
        })
        
        function fadeInEvent(el1, indexNo){
            
                var prevElement;
                var prevElementNumber;
                if (el1.id == 'no1') { 
                   // prevElement = $('banner-no' + numOfSlides);
                    prevElementNumber = $('trigger-no' + numOfSlides);         
                } else {
                   // prevElement = $('banner-no' + (indexNo-1) );
                    prevElementNumber = $('trigger-no' + (indexNo-1) );
                }
                
                
                if (current != "") {
                   // prevElement = $('banner-no' + current);
                    prevElementNumber = $('trigger-no' + current);
                }
                
                //alert(prevElement.id);
                
                //alert(prevElement.id);
                
                //turn(prevElement, $('banner-' + el1.id), 0);
                prevElementNumber.className = "";
                $('trigger-no' + indexNo).className = "selected";
    
                
                removeClasses();
                el1.fade('in');
    			indexNo = el1.id.substr(2);
                
                current = el1.id.substr(2);
    		
        }
        
        function removeClasses(){
            $$('p.context').each(function(el){
                if (el.getStyle("opacity")>0) el.fade('out');
            });
        }
        
        function autoResponde(){
            if (flow == true) {
               // prev = 'banner-no1';
            	if(indexNo > (numOfSlides-1)){
    	        	indexNo=0;
    	        }
    			indexNo++;
           		fadeInEvent($('no'+indexNo), indexNo);
           	}
        }
        

        
        function turn(el, el2, opacity) {
            var myEffects = new Fx.Morph(el, {duration: 750, transition: Fx.Transitions.Sine.easeOut, onChainComplete: turn2(el2, 0.85) });
            myEffects.start({
                'opacity': opacity,
                'margin-top': '60px'
            });
        }
        
        function turn2(el, opacity) {
            el.setStyle("margin-top", 0);
            var myEffects = new Fx.Morph(el, {duration: 750, transition: Fx.Transitions.Sine.easeOut });
            myEffects.start({
                'opacity': opacity
            });
        }
        

				        
})
