/**
 * common.js - common helper functions for www.icss.sk
 */


/**
 * Simultaneously highlight menu item and intro box on home page and vice versa
 *
 * @param string label identifies selected item (1 - 4) for booth menu and intro box
 * @param boolean out add ".hover" CSS class or take it out
 */
function hoverIntro(label, out) {

	var icsIntroSel = $("icsIntroSel" + label);
	var icsMenuSel  = $("icsMenuSel" + label);

	if ((icsIntroSel != null) && (icsMenuSel != null)) {
		if (out) {
			icsIntroSel.removeClassName("hover");
			icsMenuSel.removeClassName("hover");
		} else {
			icsIntroSel.addClassName("hover");
			icsMenuSel.addClassName("hover");
		}
	}
}

function hoverIntroMoto(label, out) {

	var icsIntroMotoSel = $("icsIntroMotoSel" + label);
	var icsMenuMotoSel  = $("icsMenuMotoSel" + label);

	if ((icsIntroMotoSel != null) && (icsMenuMotoSel != null)) {
		if (out) {
			icsIntroMotoSel.removeClassName("hover");
			icsMenuMotoSel.removeClassName("hover");
		} else {
			icsIntroMotoSel.addClassName("hover");
			icsMenuMotoSel.addClassName("hover");
		}
	}
}

/**
 * Trick browser to cache images
 *
 * @param string path
 * @param array files image filenames to preload
 */
function preloadImages(path, files) {
	if (document.images) {
		img = new Array ();
		for (i in files) {
			img[i] = new Image();
			img[i].src = path + files[i];
    }
	}
}


/**
 * Switch image's source path - load new image, try to preload
 *
 * @param object img
 * @param string path
 */
function switchImage(img, path) {
	if (document.images) {
		preload = new Image();
		preload.src = path;
		img.src = path;
	}
}
