initTour();

function initTour() {
	var menu=document.getElementById("qtmenu");

	// Setup global navigation steps
	navStep.next=document.getElementById("navnext");
	navStep.prev=document.getElementById("navprev");
	navStep.next.onclick=findStep;
	navStep.prev.onclick=findStep;

	var steps=menu.getElementsByTagName("li");
	navStep.firstStep=steps[0];
	navStep.lastStep=steps[steps.length-1];

	menu.onclick=goStep;
	setStep(navStep.firstStep);
}

function goStep(e) {
	var src;
	e=e || event;
	src=e.srcElement || e.target;
	if (src.tagName=="LI") setStep(src);
}

function setStep(step) {
	if (setStep.prevStep!=step) {
		step.className="selected";
		if (setStep.prevStep) setStep.prevStep.className="";
		setStep.prevStep=step;
		showStep(step.getAttribute("content"),step.getAttribute("src"));
		navStep(step);
	}
}

function showStep(text,src) {
	document.getElementById("qtcontent").innerHTML=text;
	if (typeof enableSampleLaunch!="undefined") enableSampleLaunch();

	var podium=document.getElementById("podium"),
		sSizePath=podium.offsetWidth>960 && podium.offsetHeight>720 ? "Large/" : "Small/";
	document.getElementById("loading").style.visibility="visible";
	podium.innerHTML="";

	if (/\.swf$/i.test(src)) { // Flash - for later
	} else { // Images
		var img=document.createElement("img");
		podium.appendChild(img);
		img.onload=scalePodium;
		img.src=sSizePath+src;
	}
}

function scalePodium() {
	var obj=this!=window && this || scalePodium.curObj;
	scalePodium.curObj=obj;
	
	if (obj) {
		obj.removeAttribute("height");
		obj.removeAttribute("width");

		// Scale
		var iAvailHeight=obj.parentNode.clientHeight,
			iAvailWidth=obj.parentNode.clientWidth;
		
		obj.style.top=Math.max(3,Math.floor((iAvailHeight-obj.offsetHeight)/2))+"px";
		obj.style.left=Math.max(3,Math.floor((iAvailWidth-obj.offsetWidth)/2))+"px";
		
		// Show
		var needTrans=obj.style.visibility!="visible";
		if (needTrans && obj.filters) obj.filters[0].apply();
		obj.style.visibility="visible";
		document.getElementById("loading").style.visibility="hidden";
		if (needTrans && obj.filters) obj.filters[0].play();
	}
}

function navStep(step) {
	var visible=["disabled","enabled"];
	navStep.prev.className=visible[+(step!=navStep.firstStep)];
	navStep.next.className=visible[+(step!=navStep.lastStep)];
}

function findStep() {
	var dir=this.getAttribute("navdir")+"Sibling",
		step=setStep.prevStep[dir];

	while (step && step.tagName!="LI") step=step[dir];
	if (step) setStep(step);
}