
/* 
 ================================================
 PVII Page Scroll scripts
 Copyright (c) 2011 Project Seven Development
 www.projectseven.com
 Version: 1.1.4 -build 13
 ================================================
 
*/

var p7PGSi=false,p7PGSa=false, p7PGSctl=[],p7PGStriggers=[],p7PGSmobile=false;
function P7_opPGS(){
	if(!document.getElementById){
		return;
	}
	p7PGSctl=arguments;
}
function P7_PGSaddLoad(){
	if(!document.getElementById){
		return;
	}
	if(window.addEventListener){
		document.addEventListener("DOMContentLoaded",P7_initPGS,false);
		window.addEventListener("load",P7_initPGS,false);
		window.addEventListener("scroll",P7_PGSsync,false);
		window.addEventListener("unload",P7_PGSff,false);
		window.addEventListener("load",P7_PGSauto,false);
	}
	else if(window.attachEvent){
		document.write("<script id=p7ie_pgs defer src=\"//:\"><\/script>");
		document.getElementById("p7ie_pgs").onreadystatechange=function(){
			if(this.readyState=="complete"){
				if(p7PGSctl.length>0){
					P7_initPGS();
				}
			}
		};
		window.attachEvent("onload",P7_initPGS);
		window.attachEvent("onscroll",P7_PGSsync);
		window.attachEvent("onload",P7_PGSauto);
	}
}
P7_PGSaddLoad();
function P7_PGSff(){
	return;
}
function P7_initPGS(){
	var i,x,tA,bd,bD,sct,tD;
	if(p7PGSi){
		return;
	}
	p7PGSi=true;
	if(P7_PGSisMobile()){
		P7_PGSsetClass(document.getElementsByTagName('BODY')[0],'p7PGS_mobile');
		p7PGSmobile=true;
		p7PGSctl[1]=parseInt(p7PGSctl[1]/2,10);
	}
	bd='html';
	bD=document.body.parentNode;
	if(/KHTML|WebKit/i.test(navigator.userAgent) || P7_PGSgetIEver()==5 ){
		bd='body';
		bD=document.body;
	}
	document.pgsEL=bd;
	bD.pgsPageGliderRunning=false;
	tA=P7_PGSgetElementsByClassName(p7PGSctl[0]);
	if(tA&&tA.length>0){
		x=0;
		for(i=0;i<tA.length;i++){
			if(tA[i].hash){
				p7PGStriggers[x]=tA[i];
				tA[i].pgsState='closed';
				tA[i].pgsID=tA[i].hash.replace('#','');
				x++;
				tA[i].onclick=function(){
					return P7_PGStrig(this);
				};
				tA[i].onmouseup=function(){
					this.blur();
				};
			}
		}
		P7_PGSsync();
		p7PGSa=true;
	}
}
function P7_PGSsync(){
	var i,x=0,tD,bD,sct,nn=0;
	if(!document.pgsEL){
		return;
	}
	bD=(document.pgsEL=='html')?document.body.parentNode:document.body;
	if(!bD.pgsPageGliderRunning){
		sct=bD.scrollTop;
		sct=(sct<=0)?0:sct;
		if(p7PGStriggers&&p7PGStriggers.length>0){
			for(i=0;i<p7PGStriggers.length;i++){
				tD=document.getElementById(p7PGStriggers[i].pgsID);
				if(tD){
					if(sct>=tD.offsetTop && tD.offsetTop>=nn){
						x=i;
					}
					nn=(tD.offsetTop>nn)?tD.offsetTop:nn;
				}
			}
			P7_PGSdown(p7PGStriggers[x]);
		}
	}
}
function P7_PGSauto(){
	var i,hs,m=false;
	hs=window.location.hash;
	if(hs&&hs.length>1){
		for(i=0;i<p7PGStriggers.length;i++){
			if(p7PGStriggers[i].hash==hs){
				m=true;
				break;
			}
		}
		if(m){
			P7_PGStrig(p7PGStriggers[i],1);
		}
	}
}
function P7_PGSdown(a){
	for(var i=0;i<p7PGStriggers.length;i++){
		if(p7PGStriggers[i].pgsState=='open'){
			P7_PGSremClass(p7PGStriggers[i],'down');
			p7PGStriggers[i].pgsState='closed';
		}
		if(p7PGStriggers[i]==a||p7PGStriggers[i].href==a.href){
			P7_PGSsetClass(p7PGStriggers[i],'down');
			p7PGStriggers[i].pgsState='open';
		}
	}
}
function P7_PGStrig(a,bp){
	var i,tD,bD,tg,hs,dur,stp,m=false,dy=20;
	hs='#'+a.pgsID;
	tD=document.getElementById(a.pgsID);
	if(tD){
		P7_PGSdown(a);
		tg=tD.offsetTop;
		tg=(tg<=0)?0:tg;
		if(document.pgsEL=='html'){
			bD=document.body.parentNode;
		}
		else{
			bD=document.body;
		}
		bD.pgsCurrentAnchor=hs;
		if(p7PGSctl[2]==1){
			m=true;
		}
		bD.pgsTime=0;
		bD.pgsBegin=bD.scrollTop;
		bD.pgsFinish=tg;
		bD.pgsDelay=dy;
		dur=p7PGSctl[1];
		stp=dur/dy;
		bD.pgsDuration=stp;
		if(p7PGSa && bp!=1){
			if(!bD.pgsPageGliderRunning){
				bD.pgsPageGliderRunning=true;
				bD.pgsPageGlider=setInterval("P7_PGSpageGlider()",bD.pgsDelay);
			}
		}
		else{
			bD.scrollTop=tg;
			if(p7PGSctl[2]==1){
				window.location.hash=bD.pgsCurrentAnchor;
			}
		}
	}
	return m;
}
function P7_PGSpageGlider(){
	var tD,nt;
	if(document.pgsEL=='html'){
		tD=document.body.parentNode;
	}
	else{
		tD=document.body;
	}
	tD.pgsTime++;
	nt=P7_PGSInOutQuad(tD.pgsTime,tD.pgsBegin,tD.pgsFinish-tD.pgsBegin,tD.pgsDuration);
	tD.scrollTop=nt;
	if(tD.pgsTime>=tD.pgsDuration){
		clearInterval(tD.pgsPageGlider);
		tD.pgsPageGliderRunning=false;
		if(p7PGSctl[2]==1){
			window.location.hash=tD.pgsCurrentAnchor;
		}
	}
}
function P7_PGSInOutQuad(t,b,c,d){
	if((t/=d/2)<1){
		return c/2*t*t+b;
	}
	else{
		return -c/2*((--t)*(t-2)-1)+b;
	}
}
function P7_PGSgetElementsByClassName(cls){
	var i,x=0,aL,aT,rS=[];
	if(typeof(document.getElementsByClassName)!='function'){
		aL=document.getElementsByTagName('*');
		for(i=0;i<aL.length;i++){
			aT=aL[i].className;
			if(aT&&aT==cls){
				rS[x]=aL[i];
				x++;
			}
		}
	}
	else{
		rS=document.getElementsByClassName(cls);
	}
	return rS;
}
function P7_PGSgetIEver(){
	var j,v=-1,nv,m=false;
	nv=navigator.userAgent.toLowerCase();
	j=nv.indexOf("msie");
	if(j>-1){
		v=parseFloat(nv.substring(j+4,j+8));
		if(document.documentMode){
			v=document.documentMode;
		}
	}
	return v;
}
function P7_PGSsetClass(ob,cl){
	if(ob){
		var cc,nc,r=/\s+/g;
		cc=ob.className;
		nc=cl;
		if(cc&&cc.length>0){
			if(cc.indexOf(cl)==-1){
				nc=cc+' '+cl;
			}
			else{
				nc=cc;
			}
		}
		nc=nc.replace(r,' ');
		ob.className=nc;
	}
}
function P7_PGSremClass(ob,cl){
	if(ob){
		var cc,nc,r=/\s+/g;
		cc=ob.className;
		if(cc&&cc.indexOf(cl>-1)){
			nc=cc.replace(cl,'');
			nc=nc.replace(r,' ');
			nc=nc.replace(/\s$/,'');
			ob.className=nc;
		}
	}
}
function P7_PGSisMobile(){
	var i,m=false,ua=navigator.userAgent.toLowerCase();
	var dv=['iphone','ipad','ipod','android','windows ce','iemobile','windowsce','blackberry','palm','symbian','series60',
	'armv','arm7tdmi','opera mobi','opera mini','polaris','kindle','midp','mmp/','portalmmm','smm-mms','sonyericsson'];
	for(i=0;i<dv.length;i++){
		if(ua.search(dv[i])>-1){
			m=dv[i];
			break;
		}
	}
	return m;
}

