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

var p7HPSi=false,p7HPSa=false, p7HPSctl=[],p7HPSbuttons=[],p7HPStriggers=[],p7HPSpanels=[],p7HPSmobile=false;
function P7_HPSset(){
	var h,sh='',hd,ie=P7_HPSgetIEver();
	if(!document.getElementById || (ie>0&&ie<6)){
		return;
	}
	sh+='.p7HPSsection {float:left;}\n';
	sh+='.p7HPS_viewport {position:relative;overflow:hidden;padding:0;margin:0;}\n';
	sh+='.p7HPS_slide_wrapper {position:relative;padding:0;margin:0;}\n';
	if (document.styleSheets){
		h='\n<st' + 'yle type="text/css">\n' + sh + '\n</s' + 'tyle>';
		document.write(h);
	}
	else{
		h=document.createElement('style');
		h.type='text/css';
		h.appendChild(document.createTextNode(sh));
		hd=document.getElementsByTagName('head');
		hd[0].appendChild(h);
	}
}
P7_HPSset();
function P7_opHPS(){
	if(!document.getElementById){
		return;
	}
	p7HPSctl=arguments;
}
function P7_HPSaddLoad(){
	var ie=P7_HPSgetIEver();
	if(!document.getElementById || (ie>0&&ie<6)){
		return;
	}
	if(window.addEventListener){
		document.addEventListener("DOMContentLoaded",P7_initHPS,false);
		window.addEventListener("load",P7_initHPS,false);
		window.addEventListener("unload",P7_HPSff,false);
		window.addEventListener("load",P7_HPSauto,false);
		window.addEventListener("resize",P7_HPSrsz,false);
	}
	else if(window.attachEvent){
		document.write("<script id=p7ie_hps defer src=\"//:\"><\/script>");
		document.getElementById("p7ie_hps").onreadystatechange=function(){
			if(this.readyState=="complete"){
				if(p7HPSctl.length>0){
					P7_initHPS();
				}
			}
		};
		window.attachEvent("onload",P7_initHPS);
		window.attachEvent("onload",P7_HPSauto);
		window.attachEvent("onresize",P7_HPSrsz);
	}
}
P7_HPSaddLoad();
function P7_HPSff(){
	return;
}
function P7_initHPS(){
	var i,x,j,tA,bd,bD,tC,vP,sW,cP,cc,pA,aL;
	if(p7HPSi){
		return;
	}
	p7HPSi=true;
	if(P7_HPSisMobile()){
		P7_HPSsetClass(document.getElementsByTagName('BODY')[0],'p7HPS_mobile');
		p7HPSmobile=true;
		p7HPSctl[1]=0;
	}
	bd='html';
	bD=document.body.parentNode;
	if(/KHTML|WebKit/i.test(navigator.userAgent) || P7_HPSgetIEver()==5 ){
		bd='body';
		bD=document.body;
	}
	document.hpsEL=bd;
	bD.hpsGliderRunning=false;
	vP=document.getElementById('p7HPS_vp');
	vP.hpsIE=P7_HPSgetIEver();
	sW=document.getElementById('p7HPS_sw');
	tA=P7_HPSgetElementsByClassName(p7HPSctl[0]);
	if(vP&&sW&&tA&&tA.length>0){
		x=0;
		cc=0;
		for(i=0;i<tA.length;i++){
			if(tA[i].hash){
				tA[i].hpsID=tA[i].hash.replace('#','');
				cP=document.getElementById(tA[i].hpsID);
				if(cP){
					p7HPStriggers[x]=tA[i];
					tA[i].hpsState='closed';
					tA[i].hpsText=tA[i].firstChild.data;
					tA[i].hpsText=tA[i].innerHTML.replace(/<[^>]*>/,'');
					tA[i].hpsText=tA[i].hpsText.replace(/<\/[^>]*>/,'');
					if(!cP.hpsTrig){
						p7HPSpanels[cc]=cP.id;
						cP.hpsTrig=x;
						pA=cP.getElementsByTagName('A');
						if(pA){
							for(j=0;j<pA.length;j++){
								if(!pA[j].hspState){
									pA[j].hpsTrig=x;
									pA[j].hpsPanel=cP.id;
									pA[j].onfocus=function(){
										if(this.hpsPanel!=document.hpsCurrentPanelID){
											P7_HPStrig(p7HPStriggers[this.hpsTrig]);
										}
									};
								}
							}
						}
						cc++;
					}
					x++;
					tA[i].onclick=function(){
						return P7_HPStrig(this);
					};
					tA[i].onmouseup=function(){
						this.blur();
					};
				}
			}
		}
		sW.style.left='0px';
		sW.hpsVP=vP.id;
		sW.hpsGliderRunning=false;
		if(vP.hpsIE>1&&vP.hpsIE<7){
			vP.style.width=P7_HPSgetWinWidth()+'px';
			sW.style.overflow='hidden';
		}
		if(p7HPSmobile){
			p7HPSctl[1]=parseInt(p7HPSctl[1]/2,10);
		}
		for(i=0;i<sW.childNodes.length;i++){
			if(sW.childNodes[i].nodeType==1){
				sW.childNodes[i].style.width=vP.offsetWidth+'px';
				sW.hpsLastChild=sW.childNodes[i];
			}
		}
		if(sW.hpsLastChild){
			P7_HPSresetWidth(sW,sW.hpsLastChild);
		}
		aL=document.getElementsByTagName('*');
		k=0;
		for(i=0;i<aL.length;i++){
			aT=aL[i].getAttribute('rel');
			if(aT){
				if(aT=='p7HPSprevious'){
					aL[i].hpsAction='previous';
					aL[i].onclick=function(){
						P7_HPSctrl('previous')
						return false;
					};
				}
				else if(aT=='p7HPSnext'){
					aL[i].hpsAction='next';
					aL[i].onclick=function(){
						P7_HPSctrl('next');
						return false;
					};
				}
				p7HPSbuttons[k]=aL[i];
				k++;
			}
		}
		P7_HPSauto();
		if( p7HPSctl[1]>1){
			p7HPSa=true;
		}
	}
}
function P7_HPStrig(a,bp){
	var i,tD,vP,sW,bY,bg,tg,dur,stp,m=false,dy=20;
	if(!a||!a.hpsID){
		return m;
	}
	hs='#'+a.hpsID;
	tD=document.getElementById(a.hpsID);
	vP=document.getElementById('p7HPS_vp');
	sW=document.getElementById('p7HPS_sw');
	if(document.hpsEL=='html'){
		bY=document.body.parentNode;
	}
	else{
		bY=document.body;
	}
	if(tD){
		P7_HPSdown(a);
		bg=parseInt(sW.style.left,10);
		if(vP.scrollLeft!==0){
			bg-=vP.scrollLeft;
			sW.style.left=bg+'px';
			vP.scrollLeft=0;
		}
		tg=tD.offsetLeft*-1;
		tg=(tg>=0)?0:tg;
		sW.hpsTime=0;
		sW.hpsBegin=bg;
		sW.hpsFinish=tg;
		sW.hpsDelay=dy;
		dur=p7HPSctl[1];
		stp=parseInt(dur/dy);
		sW.hpsDuration=(sW.hpsBegin==sW.hpsFinish)?0:stp;
		bY.hpsBYTime=0;
		bY.hpsBYBegin=(p7HPSmobile)?0:bY.scrollTop;
		bY.hpsBYFinish=0;
		bY.hpsBYDelay=dy;
		dur=parseInt(p7HPSctl[1]/2);
		stp=parseInt(dur/dy);
		bY.hpsBYDuration=(bY.hpsBYBegin==bY.hpsBYFinish)?0:stp;
		if(p7HPSa && bp!=1){
			if(!sW.hpsGliderRunning){
				sW.hpsGliderRunning=true;
				sW.hpsPanelGlider=setInterval("P7_HPSpanelGlider('"+sW.id+"')",sW.hpsDelay);
			}
		}
		else{
			sW.style.left=tg+'px';
			bY.scrollTop=0;
		}
	}
	return m;
}
function P7_HPSctrl(ac,pv){
	var i,cp=0,m=true;
	for(i=0;i<p7HPSpanels.length;i++){
		if(p7HPSpanels[i]==document.hpsCurrentPanelID){
			cp=i;
			break;
		}
	}
	if(ac=='previous'){
		cp--;
	}
	else if(ac=='next'){
		cp++;
	}
	else if(ac=='first'){
		cp=0;
	}
	else if(ac=='last'){
		cp=p7HPSpanels.length-1;
	}
	else{
		cp=parseInt(ac,10);
		if(cp&&cp>0){
			cp--;
		}
		else{
			cp=0;
		}
	}
	if( p7HPSctl[2]==1){
		cp=(cp>=p7HPSpanels.length)?0:cp;
		cp=(cp<0)?p7HPSpanels.length-1:cp;
	}
	else{
		cp=(cp<0)?0:cp;
		cp=(cp>=p7HPSpanels.length-1)?p7HPSpanels.length-1:cp;
	}
	if(pv==1){
		return cp;
	}
	else{
		P7_HPStrig(p7HPStriggers[cp]);
		return false;
	}
}
function P7_HPSdown(a){
	var ptt,ntt,lc='';
	for(var i=0;i<p7HPStriggers.length;i++){
		if(p7HPStriggers[i].hpsState=='open'){
			P7_HPSremClass(p7HPStriggers[i],'down');
			p7HPStriggers[i].hpsState='closed';
		}
		if(p7HPStriggers[i]==a||p7HPStriggers[i].href==a.href){
			P7_HPSsetClass(p7HPStriggers[i],'down');
			p7HPStriggers[i].hpsState='open';
		}
	}
	document.hpsCurrentPanelID=a.hpsID;
	if(document.hpsCurrentPanelID==p7HPSpanels[0]){
		lc='first';
	}
	else if(document.hpsCurrentPanelID==p7HPSpanels[p7HPSpanels.length-1]){
		lc='last';
	}
	ptt=p7HPStriggers[P7_HPSctrl('previous',1)].hpsText;
	ptt=(ptt=='')?'Previous':ptt;
	ntt=p7HPStriggers[P7_HPSctrl('next',1)].hpsText;
	ntt=(ntt=='')?'Next':ntt;
	for(i=0;i<p7HPSbuttons.length;i++){
		if(p7HPSbuttons[i].hpsAction=='previous'){
			p7HPSbuttons[i].setAttribute('title',ptt);
		}
		else if(p7HPSbuttons[i].hpsAction=='next'){
			p7HPSbuttons[i].setAttribute('title',ntt);
		}
		if(p7HPSctl[2]!=1){
			if(lc=='first' && p7HPSbuttons[i].hpsAction=='previous'){
				P7_HPSsetClass(p7HPSbuttons[i],'off');
				p7HPSbuttons[i].removeAttribute('title');
			}
			else if(lc=='last' && p7HPSbuttons[i].hpsAction=='next'){
				P7_HPSsetClass(p7HPSbuttons[i],'off');
				p7HPSbuttons[i].removeAttribute('title');
			}
			else{
				P7_HPSremClass(p7HPSbuttons[i],'off');
			}
		}
	}
}
function P7_HPSrsz(){
	var i,bD,sW,vP,cP;
	if(!document.hpsEL){
		return;
	}
	vP=document.getElementById('p7HPS_vp');
	sW=document.getElementById('p7HPS_sw');
	if(sW){
		if(!sW.hpsGliderRunning){
			if(vP.hpsIE>1&&vP.hpsIE<7){
				vP.style.width=P7_HPSgetWinWidth()+'px';
			}
			for(i=0;i<sW.childNodes.length;i++){
				if(sW.childNodes[i].nodeType==1){
					sW.childNodes[i].style.width=vP.offsetWidth+'px';
					sW.hpsLastChild=sW.childNodes[i];
				}
			}
			if(sW.hpsLastChild){
				P7_HPSresetWidth(sW,sW.hpsLastChild);
			}
		}
		if(document.hpsCurrentPanelID){
			cP=document.getElementById(document.hpsCurrentPanelID);
			if(cP){
				sW.style.left=(cP.offsetLeft*-1)+'px';
			}
		}
	}
}
function P7_HPSauto(){
	var i,x=0,hs,m=false;
	hs=window.location.hash;
	if(hs&&hs.length>1){
		for(i=0;i<p7HPStriggers.length;i++){
			if(p7HPStriggers[i].hash==hs){
				x=i;
				break;
			}
		}
	}
	P7_HPStrig(p7HPStriggers[x],1);
}
function P7_HPSpanelGlider(d){
	var tD,bY,nl,nt;
	tD=document.getElementById(d);
	if(document.hpsEL=='html'){
		bY=document.body.parentNode;
	}
	else{
		bY=document.body;
	}
	if(tD.hpsTime<tD.hpsDuration){
		tD.hpsTime++;
		nl=P7_HPSInOutQuad(tD.hpsTime,tD.hpsBegin,tD.hpsFinish-tD.hpsBegin,tD.hpsDuration);
		tD.style.left=nl+'px';
	}
	if(tD.hpsTime>=tD.hpsDuration && bY.hpsBYTime<bY.hpsBYDuration ){
		bY.hpsBYTime++;
		nt=P7_HPSInOutQuad(bY.hpsBYTime,bY.hpsBYBegin,bY.hpsBYFinish-bY.hpsBYBegin,bY.hpsBYDuration);
		bY.scrollTop=nt;
	}
	if(tD.hpsTime>=tD.hpsDuration && bY.hpsBYTime>=bY.hpsBYDuration ){
		clearInterval(tD.hpsPanelGlider);
		tD.hpsGliderRunning=false;
	}
}
function P7_HPSInOutQuad(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_HPSresetWidth(dd,lc){
	var bf=2000;
	dd.style.width='19000px';
	dd.style.width=(lc.offsetLeft+lc.offsetWidth+bf)+'px';
}
function P7_HPSgetElementsByClassName(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_HPSgetIEver(){
	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_HPSgetWinWidth(){
	var h;
	if(document.documentElement&&document.documentElement.clientHeight){
		w=document.documentElement.clientWidth;
	}
	else if(window.innerHeight){
		if(document.documentElement.clientWidth){
			w=document.documentElement.clientWidth;
		}
		else{
			w=window.innerWidth;
		}
	}
	else if(document.body){
		w=document.body.clientWidth;
	}
	return w
}
function P7_HPSisMobile(){
	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;
}
function P7_HPSsetClass(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_HPSremClass(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;
		}
	}
}

