// Faq box code

// first=true; to open first box on load, first=false; to have them all closed
var first=true;

var colHeight=0;var ocolHeight=0;var boxHeight=0;var curHeight=0;var ocurHeight=0;var obj;var objo;var oid=-1;var timer;var timer2;var cid;var allclosed=true;var imBusy=false;
// functions that deal with opening a box
function openbox(id) {	
	if (imBusy==false) {
		imBusy=true;obj=faqAmount[id-1];boxHeight=faqItem[id-1];colHeight=qHeight[id-1];curHeight=colHeight;cid=id;
		// call to close open box after opening a new one
		if (id!=oid && allclosed==false) { closeBox(oid); } else { imBusy=false; }
		if ((obj.offsetHeight-1)<=colHeight) { allclosed=false;obj.firstChild.className+=" qhover";openAni(); } 
		else { allclosed=true;objo=obj;ocolHeight=colHeight;closeBox(oid); }
	}
}
function openAni() { timer=setInterval("moveDown();",5); }
function moveDown() {
	if (curHeight<boxHeight) { curHeight=curHeight+10;obj.style.height=curHeight+"px";} 
	else { clearInterval(timer);obj.style.height=boxHeight+"px";oid=cid; }
}
// functions that deal with closing a box
function closeBox(oid) {
	objo=faqAmount[oid-1];ocolHeight=qHeight[oid-1];ocurHeight=faqItem[oid-1];	
	objo.firstChild.className=objo.firstChild.className.replace(new RegExp(" qhover\\b"), "");	
	closeAni();
}
function closeAni() { timer2=setInterval("moveUp();",5); }
function moveUp() {
	if (ocurHeight>ocolHeight) { ocurHeight=ocurHeight-10;objo.style.height=ocurHeight+"px"; } 
	else { clearInterval(timer2);objo.style.height=ocolHeight+"px";imBusy=false; }
}
// get heights for each box both open(=faqItem) and closed(=qHeight), close all boxes and if required, open the first (var first=true;) or any specific box using #[number] in the url
var faqItem=new Array();var qHeight=new Array();var faqAmount;
function boAccordion() {
	if (document.getElementById('faqContainer')) {
		document.getElementById('faqContainer').onclick=function() { document.getElementById('blurme').focus(); }
		faqAmount=document.getElementById('faqContainer').getElementsByTagName("li");
		var stopit=faqAmount.length;
		for(var i=1; i<=stopit; i++) {		
			faqItem.push(faqAmount[i-1].offsetHeight);
			qHeight.push(faqAmount[i-1].firstChild.offsetHeight);
			faqAmount[i-1].nr = i;
			//faqAmount[i-1].onclick=function() { openbox(this.nr); }
			faqAmount[i-1].firstChild.onclick=function() { openbox(this.parentNode.nr); }
		}
		for(var i=1; i<=faqItem.length; i++) { faqAmount[i-1].style.height=qHeight[(i-1)]+"px";	}	
		if (location.hash) { var id=location.hash;id=id.replace(/#/,"");openbox(id); } 
		else if (first==true) { openbox(1); }
	}
}
//onload=boAccordion;

// vertical image scroller
// items visible when scroller does not move
var vitemsshown=1;
// width of each item within the scroller
var vmyitem=165;
// amount of items to be scrolled when moved
var vscrollby=1;
// choose to switch carousel on (true) of off (false)
var vcarousel=true;
// choose speed of carousel
var vcarspeed=4000;
// choose step speed of carousel
var vstep=2;

var myImgs=new Array();var myThumbs=new Array();var myBlocks=new Array();
function getvContent() {
	if (document.getElementById('vinner')) {
		myThumbs=document.getElementById('vinner').getElementsByTagName("div");		
		var stopit2=myThumbs.length;
		if (myThumbs.length > vitemsshown) {
			for(var k=0; k<vitemsshown; k++) { var y=myThumbs[k].cloneNode(true);document.getElementById('vinner').appendChild(y); }			
		}
		vmoveinplace();
	}
}
var vscrollnr;var vmybox;var vmytop;var vthetop;var vtimer;var vtrgt;var vbusy=false;var waiting;var vstrt=true;
function vmoveinplace() {
	vscrollnr=(vscrollby*vmyitem);
	if (document.getElementById('vinner')) {
		document.getElementById('vinner').style.top='0px';
		var i=document.getElementById('vinner').getElementsByTagName('div');
		vmybox=-(((i.length-1)*vmyitem)-(vitemsshown*vmyitem));
		var acttop=0;
		for (x=0;x<i.length;x++) {
			if (i[x].className=='active') { acttop=-(x*vmyitem);	}
		}
		if (acttop>-(vmyitem*vitemsshown)) {
			document.getElementById('vinner').style.top=acttop+'px'; 
		} else { document.getElementById('vinner').style.top=-(vmyitem*vitemsshown)+'px'; }
		vmytop=document.getElementById('vinner').style.top;
		vthetop=parseInt(vmytop);
		// deals with automatic scrolling
		if (vcarousel==true && vstrt==false) { waiting=setTimeout("vmoveDown()",1); }
		if (vcarousel==true && vstrt==true) { vstrt=false;waiting=setTimeout("vmoveDown()",vcarspeed); }
		if (vcarousel==true) { 
			document.getElementById('vinner').onmouseover=function() { vcarousel=false;clearTimeout(waiting); }
			document.getElementById('vinner').onmouseout=function() { vcarousel=true;waiting=setTimeout("vmoveDown()",1); } 
		}
	}
}
function vmoveDown() {	
	vtrgt=vthetop-vscrollnr;
	if (vtrgt>=vmybox && vbusy==false) { vtimer=setInterval("vmoveBottom("+vtrgt+");",5);vbusy=true; }
	else if (vbusy==false) { 
		var lastitems=(vmybox+(-vthetop))/vmyitem;
		if (lastitems<=0) { 
			vscrollnr=-((lastitems*vmyitem)-vmyitem);
			vtrgt=vthetop-vscrollnr;
			vtimer=setInterval("vmoveBottom("+vtrgt+");",5);
			vbusy=true; 
		} else { 
			vmoveinplace();
			if (vcarousel==false) { vmoveDown(); }	
		}	 
	}
}
function vmoveBottom(vtrgt) {
	if (vthetop>vtrgt) {	vthetop=vthetop-vstep; document.getElementById('vinner').style.top=(vthetop+'px');	} 
	else { 
		clearInterval(vtimer); 
		if (vthetop<vtrgt){ document.getElementById('vinner').style.top=(vtrgt+'px');vthetop=vtrgt; }
		vbusy=false;
		if (vcarousel==true) { waiting=setTimeout("vmoveDown()",vcarspeed); }
	}	
}
function vmoveUp() {		
	var startpoint=vmybox;	
	if (vthetop==0) { vthetop=startpoint;document.getElementById('vinner').style.top=(startpoint+'px'); }
	vtrgt=vthetop+vscrollnr;
	if (vtrgt<0 && vbusy==false) { vtimer=setInterval("vmoveTop("+vtrgt+");",5);vbusy=true; }
	else if (vbusy==false) { 
		var lastitems=vthetop/vmyitem;
		if (lastitems<0) { 
			vscrollnr=-(lastitems*vmyitem);
			vtrgt=vthetop+vscrollnr;
			vtimer=setInterval("moveTop("+vtrgt+");",5);
			vbusy=true; 
		} else { vmoveinplace();vmoveUp(); }		 
	}
}
function vmoveTop(vtrgt) {
	if (vthetop<vtrgt) {	vthetop=vthetop+vstep; document.getElementById('vinner').style.top=(vthetop+'px');	} 
	else { 
		clearInterval(vtimer); 
		if (vthetop>vtrgt){ document.getElementById('vinner').style.top=(vtrgt+'px');vthetop=vtrgt; }
		vscrollnr=(vscrollby*vmyitem);
		vbusy=false; 
	}	
}
//onload=getvContent;

// FLOW PLAYER CODE
function playVideo() {
	if (typeof(videoloc) != "undefined" && videoloc != "") {
		$f("div.player", "swf/flowplayer-3.1.2.swf",  {
			wmode: 'opaque',
			clip: {
				url: videoloc,
				autoPlay: true, 
				autoBuffering: true
				
			},			
			plugins: {     
				controls: null 
			},			
			// canvas coloring and custom gradient setting
			canvas: {
				backgroundColor:'#efefef',
				backgroundGradient: [0.1, 0]
            }	,	
			play: { opacity: 0 }	
		});
	}
}

function InitAll() {
	boAccordion();
	getvContent();
	playVideo();
}
onload=InitAll;