
/* - home.js - */
// http://www.nesoindia.org/portal_javascripts/home.js?original=1
﻿
Animator=function(startValue,endValue,f,t,r){this.step=10;this.rate=10;this.power=2;this.type=this.NONE;this.min=startValue;this.max=endValue;this.isReversing=false;this.animateFunction=f;this.terminateFunction=t;this.reversalFunction=r;this.precalc=new Array(100);for(var i=0;i<=100;i++) this.precalc[i]=this.calculate(i)}
Animator.prototype.NONE=0;Animator.prototype.EASEIN=1;Animator.prototype.EASEOUT=2;Animator.prototype.EASEINOUT=3;Animator.prototype.setStep=function(step){this.step=step}
Animator.prototype.setRate=function(rate){this.rate=rate}
Animator.prototype.setPower=function(power){this.power=power;for(var i=0;i<=100;i++) this.precalc[i]=this.calculate(i)}
Animator.prototype.setType=function(type){this.type=type;for(var i=0;i<=100;i++) this.precalc[i]=this.calculate(i)}
Animator.prototype.setAnimateFunction=function(f){this.animateFunction=f}
Animator.prototype.start=function(){if(this.interval) return;this.time=0;this.isReversing=false;this.interval=setInterval(this.method(this.animate),this.rate)}
Animator.prototype.reverse=function(){this.isReversing=(this.isReversing)?false:true}
Animator.prototype.stop=function(){if(this.interval) clearInterval(this.interval);this.interval=null}
Animator.prototype.pause=function(){if(this.interval) clearInterval(this.interval)}
Animator.prototype.resume=function(){this.interval=setInterval(this.method(this.animate),this.rate)}
Animator.prototype.isAnimating=function(){return Boolean(this.interval)}
Animator.prototype.animate=function(){if(this.time>=0&&this.time<=100){this.animateFunction(this.precalc[this.time]);this.time=(this.isReversing)?this.time-this.step:this.time+this.step} else{clearInterval(this.interval);this.interval=null;if(!this.isReversing&&this.terminateFunction) this.terminateFunction();if(this.isReversing&&this.reversalFunction) this.reversalFunction()}}
Animator.prototype.calculate=function(t){t=t/100;var factor;switch(this.type){case this.NONE:factor=this.easeNone(t);break;case this.EASEIN:factor=this.easeIn(t);break;case this.EASEOUT:factor=this.easeOut(t);break;case this.EASEINOUT:factor=this.easeInOut(t);break}
return parseInt(this.min+factor*(this.max-this.min))}
Animator.prototype.easeNone=function(t){return t}
Animator.prototype.easeIn=function(t){return Math.pow(t,this.power)}
Animator.prototype.easeOut=function(t){return 1-this.easeIn(1-t)}
Animator.prototype.easeInOut=function(t){if(t<0.5) return this.easeIn(t*2)/2;return 0.5+this.easeOut((t-0.5)*2)/2}
var strAnim=""
Rotator=function(scrollableElement,itemContainer,itemTagName,buttonContainer,visibleItems,scrollDistance,initialDelay){this.itemSize=scrollDistance;this.visibleItems=visibleItems;this.orientation=0;this.buttons=buttonContainer.getElementsByTagName("a");this.currentButton=1;this.buttons[this.currentButton].className="current";this.scrollable=scrollableElement;this.itemContainer=itemContainer
this.items=itemContainer.getElementsByTagName(itemTagName);this.totalItems=this.items.length;if(this.totalItems<=this.visibleItems) return;var rotator=this;var bottomClones=new Array(this.visibleItems);var topClones=new Array(this.visibleItems);for(var i=0;i<this.visibleItems;i++){bottomClones[i]=this.items[this.totalItems-1-i].cloneNode(true);topClones[i]=this.items[i].cloneNode(true)}
for(var i=0;i<this.visibleItems;i++){itemContainer.insertBefore(bottomClones[i],this.items[0]);itemContainer.appendChild(topClones[i])}
this.index=this.visibleItems;if(this.orientation) this.scrollable.scrollTop=this.index*this.itemSize;else this.scrollable.scrollLeft=this.index*this.itemSize;EventListener.addEvent(window.document,'mouseover',this.method(this.automatic));EventListener.addEvent(itemContainer,'mouseover', function(event){rotator.manual();cancelBubble(event)})
EventListener.addEvent(buttonContainer,'mouseover', function(event){rotator.manual();cancelBubble(event)})
EventListener.addEvent(this.buttons[0],"click",function(){this.blur();rotator.manual();rotator.back();return false})
for(var i=1;i<this.buttons.length-1;i++){EventListener.addEvent(this.buttons[i],"click",function(){this.blur();rotator.manual();rotator.goToItem(this.name);return false})}
EventListener.addEvent(this.buttons[this.buttons.length-1],"click", function(){this.blur();rotator.manual();rotator.forward();return false})
setTimeout(this.method(this.automatic),initialDelay)}
Rotator.prototype.setHorizontalMode=function(){this.orientation=0}
Rotator.prototype.setVerticalMode=function(){this.orientation=1}
Rotator.prototype.checkIndex=function(){if(this.index==0) this.index=this.totalItems;if(this.index==this.totalItems+this.visibleItems) this.index=this.visibleItems;if(this.orientation) this.scrollable.scrollTop=this.index*this.itemSize;else this.scrollable.scrollLeft=this.index*this.itemSize;this.animating=false;this.setCurrentTab()}
Rotator.prototype.setCurrentTab=function(){this.buttons[this.currentButton].className="";this.currentButton=this.index;this.buttons[this.currentButton].className="current"}
Rotator.prototype.forward=function(intStep){if(this.animating) return;if(isNaN(intStep)){intStep=1}
if(this.orientation) this.scrollForward=new Animator(this.scrollable.scrollTop,this.scrollable.scrollTop+(intStep*this.itemSize),this.method(this.animateForward),this.method(this.checkIndex));else this.scrollForward=new Animator(this.scrollable.scrollLeft,this.scrollable.scrollLeft+(intStep*this.itemSize),this.method(this.animateForward),this.method(this.checkIndex));this.scrollForward.setStep(3);this.scrollForward.setType(this.scrollForward.EASEINOUT);this.scrollForward.setRate(20);this.animating=this.scrollForward;this.index+=intStep;this.scrollForward.start()}
Rotator.prototype.animateForward=function(value){if(this.orientation) this.scrollable.scrollTop=value;else this.scrollable.scrollLeft=value}
Rotator.prototype.back=function(intStep){if(this.animating) return;if(isNaN(intStep)){intStep=-1}
if(this.orientation) this.scrollBack=new Animator((this.scrollable.offsetHeight-this.scrollable.scrollTop),(this.scrollable.offsetHeight-this.scrollable.scrollTop-intStep*this.itemSize),this.method(this.animateBack),this.method(this.checkIndex));else this.scrollBack=new Animator((this.scrollable.offsetWidth-this.scrollable.scrollLeft),(this.scrollable.offsetWidth-this.scrollable.scrollLeft-intStep*this.itemSize),this.method(this.animateBack),this.method(this.checkIndex));this.scrollBack.setStep(3);this.scrollBack.setType(this.scrollBack.EASEINOUT);this.scrollBack.setRate(20);this.animating=this.scrollBack;this.index+=intStep;this.scrollBack.start()}
Rotator.prototype.animateBack=function(value){if(this.orientation) this.scrollable.scrollTop=this.scrollable.offsetHeight-value;else this.scrollable.scrollLeft=this.scrollable.offsetWidth-value}
Rotator.prototype.automatic=function(){if(!this.auto){this.auto=setInterval(this.method(this.forward),5000,1)}}
Rotator.prototype.manual=function(){if(this.auto){clearInterval(this.auto);this.auto=null}}
Rotator.prototype.goToItem=function(itemIndex){var diff=itemIndex-this.index;if(diff<0){this.back(diff)}
if(diff>0){this.forward(diff)}
return false}
function cancelBubble(e){if(!e) var e=window.event;e.cancelBubble=true;if(e.stopPropagation) e.stopPropagation()}
Object.prototype.method=function(method){var context=this;return function(){method.apply(context,arguments);return false}}
function isChild(ancestor,candidate){while(candidate&&candidate!=ancestor.parentNode){if(candidate==ancestor) return true;try{candidate=candidate.parentNode} catch(c){return false}}
return false}


