window.onload = makeDoubleDelegate(window.onload,rolloverInit);
window.onload = makeDoubleDelegate(window.onload,initLinks);
window.onload = makeDoubleDelegate(window.onload,initForm);


function makeDoubleDelegate(function1, function2) {
	return function() {
		if (function1)
			function1();
		if (function2)
			function2();
	}
}



//ROLLOVER-------------------------------------------------------------------------------
function rolloverInit() {
	for (var i=0; i<document.links.length; i++) {
	//busca tots els links.
		var linkObj = document.links[i];
		//link actual
		if (linkObj.className) {
		//entrem si el link te l'etiquetq class
		//no podem utilitzar el id de les imatges per calcular el id de la imatge cambiada, ja q el id a de ser únic
		//i totes les imatges a les quals li passer el ratolí per sobre han de tenim el mateix destí de la imatge cambiada.
		//per aixó busquem el className, + d'un element a la mateixa pag. amb la = classe.
			var imgObj = document.getElementById(linkObj.className);
			//busquem un altre element que te com a ID la etiqueta CLASS de la imatge.		
			if (imgObj) {
				setupRollover(linkObj,imgObj);
				//linkObj -> obj. al link actual
				//imgObj  -> el objecte d la imatge.
			}
		}
	}
}

function setupRollover(thisLink,textImage) {
	thisLink.imgToChange = textImage;
	//afegim una nova prop.: imgToChange al obj. del vincle
	//JS necessita saber quina imatge ha de cambiar quan el ratolí estigui a sobre, i aquí es on s' enmagtzema
		//thisLink.onmouseout = rollOut;
	thisLink.onmouseover = rollOver;	
	

	thisLink.overImage = new Image();
	thisLink.overImage.src = "http://www.surfdevils.com/upload/" + thisLink.id + ".jpg";
	//imatge amb el nom del invent
}

function rollOver() {
	this.imgToChange.src = this.overImage.src;
}

		
//INITLINKS------------------------------------------------------------------
//una var esta al codi, es dinamicxa
var thisPic = 0;
function initLinks() {
	document.getElementById("prevLink").onclick = processPrevious;
	document.getElementById("nextLink").onclick = processNext;
}
function processPrevious() {	
	if (thisPic == 0) {
		thisPic = myPix.length;
	}
	thisPic--;
	document.getElementById("textField").src = myPix[thisPic];
	return false;
}
function processNext() {
	thisPic++;
	if (thisPic == myPix.length) {
		thisPic = 0;
	}
	document.getElementById("textField").src = myPix[thisPic];
	return false;
}


//SELEXCT----------------------------------------------------------------
window.onunload = function (){}
function initForm(){
	//document.getElementById("select_model").selectedIndex = 2;
	document.getElementById("select_model").onchange = jumpPage;
}
function jumpPage(){
	var newLoc = document.getElementById("select_model");
	var newPage = newLoc.options[newLoc.selectedIndex].value;
	if (newPage != ""){window.location = newPage;}
}



//RADIO----------------------------------------------------------------
function check(op){
	window.location = op;	
}

