
/* 
 ================================================
 PVII Page Scroll scripts
 Copyright (c) 2011 Project Seven Development
 www.projectseven.com
 Version: 1.1.3 -build 12
 ================================================
 
*/

var shwdPGSi=false,shwdPGSa=false, shwdPGSctl=[],shwdPGStriggers=[],shwdPGSmobile=false;
function shwd_opPGS(){
	if(!document.getElementById){
		return;
	}
	shwdPGSctl=arguments;
}
function shwd_PGSaddLoad(){
	if(!document.getElementById){
		return;
	}
	if(window.addEventListener){
		document.addEventListener("DOMContentLoaded",shwd_initPGS,false);
		window.addEventListener("load",shwd_initPGS,false);
		window.addEventListener("scroll",shwd_PGSsync,false);
		window.addEventListener("unload",shwd_PGSff,false);
		window.addEventListener("load",shwd_PGSauto,false);
	}
	else if(window.attachEvent){
		document.write("<script id=shwdie_pgs defer src=\"//:\"><\/script>");
		document.getElementById("shwdie_pgs").onreadystatechange=function(){
			if(this.readyState=="complete"){
				if(shwdPGSctl.length>0){
					shwd_initPGS();
				}
			}
		};
		window.attachEvent("onload",shwd_initPGS);
		window.attachEvent("onscroll",shwd_PGSsync);
		window.attachEvent("onload",shwd_PGSauto);
	}
}
shwd_PGSaddLoad();
function shwd_PGSff(){
	return;
}
function shwd_initPGS(){
	var i,x,tA,bd,bD,sct,tD;
	if(shwdPGSi){
		return;
	}
	shwdPGSi=true;
	if(shwd_PGSisMobile()){
		shwd_PGSsetClass(document.getElementsByTagName('BODY')[0],'shwdPGS_mobile');
		shwdPGSmobile=true;
		shwdPGSctl[1]=parseInt(shwdPGSctl[1]/2,10);
	}
	bd='html';
	bD=document.body.parentNode;
	if(/KHTML|WebKit/i.test(navigator.userAgent) || shwd_PGSgetIEver()==5 ){
		bd='body';
		bD=document.body;
	}
	document.pgsEL=bd;
	bD.pgsPageGliderRunning=false;
	tA=shwd_PGSgetElementsByClassName(shwdPGSctl[0]);
	if(tA&&tA.length>0){
		x=0;
		for(i=0;i<tA.length;i++){
			if(tA[i].hash){
				shwdPGStriggers[x]=tA[i];
				tA[i].pgsState='closed';
				tA[i].pgsID=tA[i].hash.replace('#','');
				x++;
				tA[i].onclick=function(){
					return shwd_PGStrig(this);
				};
				tA[i].onmouseup=function(){
					this.blur();
				};
			}
		}
		shwd_PGSsync();
		shwdPGSa=true;
	}
}
function shwd_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(shwdPGStriggers&&shwdPGStriggers.length>0){
			for(i=0;i<shwdPGStriggers.length;i++){
				tD=document.getElementById(shwdPGStriggers[i].pgsID);
				if(tD){
					if(sct>=tD.offsetTop && tD.offsetTop>=nn){
						x=i;
					}
					nn=(tD.offsetTop>nn)?tD.offsetTop:nn;
				}
			}
			shwd_PGSdown(shwdPGStriggers[x]);
		}
	}
}
function shwd_PGSauto(){
	var i,hs,m=false;
	hs=window.location.hash;
	if(hs&&hs.length>1){
		for(i=0;i<shwdPGStriggers.length;i++){
			if(shwdPGStriggers[i].hash==hs){
				m=true;
				break;
			}
		}
		if(m){
			shwd_PGStrig(shwdPGStriggers[i],1);
		}
	}
}
function shwd_PGSdown(a){
	for(var i=0;i<shwdPGStriggers.length;i++){
		if(shwdPGStriggers[i].pgsState=='open'){
			shwd_PGSremClass(shwdPGStriggers[i],'down');
			shwdPGStriggers[i].pgsState='closed';
		}
		if(shwdPGStriggers[i]==a||shwdPGStriggers[i].href==a.href){
			shwd_PGSsetClass(shwdPGStriggers[i],'down');
			shwdPGStriggers[i].pgsState='open';
		}
	}
}
function shwd_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){
		shwd_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(shwdPGSctl[2]==1){
			m=true;
		}
		bD.pgsTime=0;
		bD.pgsBegin=bD.scrollTop;
		bD.pgsFinish=tg;
		bD.pgsDelay=dy;
		dur=shwdPGSctl[1];
		stp=dur/dy;
		bD.pgsDuration=stp;
		if(shwdPGSa && bp!=1){
			if(!bD.pgsPageGliderRunning){
				bD.pgsPageGliderRunning=true;
				bD.pgsPageGlider=setInterval("shwd_PGSpageGlider()",bD.pgsDelay);
			}
		}
		else{
			bD.scrollTop=tg;
			if(shwdPGSctl[2]==1){
				window.location.hash=bD.pgsCurrentAnchor;
			}
		}
	}
	return m;
}
function shwd_PGSpageGlider(){
	var tD,nt;
	if(document.pgsEL=='html'){
		tD=document.body.parentNode;
	}
	else{
		tD=document.body;
	}
	tD.pgsTime++;
	nt=shwd_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(shwdPGSctl[2]==1){
			window.location.hash=tD.pgsCurrentAnchor;
		}
	}
}
function shwd_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 shwd_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 shwd_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 shwd_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 shwd_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 shwd_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','zune'];
	for(i=0;i<dv.length;i++){
		if(ua.search(dv[i])>-1){
			m=dv[i];
			break;
		}
	}
	return m;
}

