/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
window.onload = changeNextPrevUrls;

var workOnSteelArray;

function initializeUrlArray(){
	workOnSteelArray = new Array();
	
	workOnSteelArray[0]="/workonsteel/1. Dk-Bn-Gr-1_200909.html";
	workOnSteelArray[1]="/workonsteel/2. Dk-Bn-Gr-2_200909.html";
	workOnSteelArray[2]="/workonsteel/3. M-Ol-Gr-2_200909.html";
	workOnSteelArray[3]="/workonsteel/4. M-Ol-Gr-1_200909.html";
	workOnSteelArray[4]="/workonsteel/5. D-Vrz-Al-1_200909.html";
	workOnSteelArray[5]="/workonsteel/6. D-Vrz-Al-2_200909.html";		
	workOnSteelArray[6]="/workonsteel/7. D-Bl-Vl-1_200909.html";	
	workOnSteelArray[7]="/workonsteel/8. D-Bl-Vl-2_200909.html";
	workOnSteelArray[8]="/workonsteel/9. M-Gy-Bl-Gr-1_200909.html";
	workOnSteelArray[9]="/workonsteel/10. M-Gy-Bl-Gr-2_200909.html";		
	workOnSteelArray[10]="/workonsteel/11. M-Pn-Br-1_200909.html";	
	workOnSteelArray[11]="/workonsteel/12. M-Pn-Br-2_200909.html";		
	workOnSteelArray[12]="/workonsteel/Dk-Y-Gr-1_200901.html";
	workOnSteelArray[13]="/workonsteel/Dk-Y-Gr-2_200901.html";
	workOnSteelArray[14]="/workonsteel/P-Bl-Gy-1_200903.html";
	workOnSteelArray[15]="/workonsteel/P-Bl-Gy-3_200903.html";
	workOnSteelArray[16]="/workonsteel/Dp-Gr-P-1_200903.html";
	workOnSteelArray[17]="/workonsteel/Dp-Gr-P-2_200903.html";		
	workOnSteelArray[18]="/workonsteel/M-Dk-Rd-1_200901.html";	
	workOnSteelArray[19]="/workonsteel/M-Dk-Rd-3_200901.html";

}

function changeNextPrevUrls(){
	initializeUrlArray();
	qs();
	var slideNo = parseInt(qs());
	var prevIdx = (slideNo == 0) ? 0 : (slideNo - 1);
	//alert("prevIdx=" + prevIdx);
	var nextIdx = (slideNo == (workOnSteelArray.length - 1)) ? slideNo : (slideNo + 1);
	//alert("nextIdx=" + nextIdx);
	if(prevIdx == 0 && nextIdx == 1) {
		disappear("prevhref");
	} else {
		appear("prevhref", 'PREV');
		changeUrl("prevhref", workOnSteelArray[prevIdx] + "?slide_no=" + prevIdx);
	}
	
	if((prevIdx == workOnSteelArray.length - 2) && (nextIdx == workOnSteelArray.length - 1)) {
		disappear("nexthref");
	} else {
		appear("nexthref", 'NEXT');
		changeUrl("nexthref", workOnSteelArray[nextIdx] + "?slide_no=" + nextIdx);
	}	
	
	//changeUrl("prevhref", workOnSteelArray[prevIdx] + "?slide_no=" + prevIdx);
	//changeUrl("nexthref", workOnSteelArray[nextIdx] + "?slide_no=" + nextIdx);
}

function changeUrl(id, newUrl){
	document.getElementById(id).href = newUrl;
}

function disappear(id){
	document.getElementById(id).innerHTML = '';
}

function appear(id, text){
	document.getElementById(id).innerHTML = text;
}


function qs() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	//alert(parms);
	var result =0;
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			//alert("key=" + key);
			//alert("val=" + val);
			if(key == "slide_no") {
				result = val;
				break;
			}
		}
	}
	//alert("result=" + result);
	return result;
}




