/**
 * @var string	Pfad zu den Galeriebildern
 */
var gallery_path = 'uploads/thumbnails/gallery/main/';

/**
 * Ändert das Bild des übergebenen Produkts durch das entsprechende Farbvariantenbild.
 * Das Bild, welches geändert werden soll muss eine eindeutige ID bestehend aus
 * product_image_pid_$product_id besitzen.
 *
 * @param int	product_uid	UID des zu ändernden Produktes
 * @param int	color_uid	UID des Farbbildes, welches angezeigt werden soll
 */
function switch_preview_pic(product_uid, color_uid) {
	var img		= document.getElementById('product_image_pid_' + product_uid);

	if (img) {
		var src		= gallery_path + 'color_uid_' + color_uid + '.jpg';
		img.src		= src;
	}
}

/**
 * Stellt ein Produktbild wieder her (Implementierung für den IE).
 * Der IE ruft diese Funktion mittels des Events onmouseleave auf, das nur dann gefeuert
 * wird, wenn das jeweilige Element wirklich verlassen wird.
 *
 * @param int	product_uid	UID des Produktes
 */ 
function restore_preview_pic_ie(product_uid) {
	var img = document.getElementById('product_image_pid_' + product_uid);

	if (img) {
		var src = gallery_path + 'product_uid_' + product_uid + '.jpg';
		img.src = src;
	}
}

/**
 * Stellt ein Produktbild wieder her.
 * Diese Methode sollte statt #restore_preview_pic(int, event) genutzt werden, da sie
 * browserunabhängig arbeitet.
 *
 * @param int	product_uid	UID des Produktes 
 */
function restore_pp(product_uid) {
	var img = document.getElementById('product_image_pid_' + product_uid);

	if (img) {
		var src = gallery_path + 'product_uid_' + product_uid + '.jpg';
		img.src = src;
	}
}

/**
 * Stellt ein Produktbild wieder her (Implementierung für alle Browser außer dem IE).
 * Alle Browser außer dem IE rufen diese Funktion mittels onmouseout auf. Durch das
 * event-Bubbling von JS muss die Event-Quelle bestimmt werden und davon abhängig, ob
 * das Bild wiederhergestellt werden soll oder nicht.  
 *
 * @param int	product_uid	UID des Produktes 
 * @param event	event		das Event
 */
function restore_preview_pic(product_uid, event) {

	/* der IE soll diese Funktion nicht benutzen */
	if (window.event && !event.target) {
		return;
	}

	/*
	 * Wir wollen das Bild nur ersetzen, wenn das div auch wirklich verlassen wurde und nicht
	 * nur auf ein Untereleent des divs gezeigt wurde.
	 */
	var target = event.target;

	/* safari bug */
	if (target.nodeType == 3) {
		target = targ.parentNode;
	}
	
	/*
	 * Prüfen, ob unsere Eventquelle auch das div ist.
	 */	
	if (target.nodeName == 'DIV') {
		var img = document.getElementById('product_image_pid_' + product_uid);

		if (img) {
			var src = gallery_path + 'product_uid_' + product_uid + '.jpg';
			img.src = src;
		}
	}
}