
//Preload des Warenkorb Hovers
cart_bg = new Image();		cart_bg.src = "templates/gamersware/img/boxes/cart/border_bg_hover.gif";
cart_bg_h = new Image();	cart_bg_h.src = "templates/gamersware/img/boxes/cart/border_bg_h_hover.gif";
cart_bg_f = new Image();	cart_bg_f.src = "templates/gamersware/img/boxes/cart/border_bg_f_hover.gif";

//Target _blank mit Script
function changeTarget() {
	var lnks = document.getElementsByTagName('a');
	for(i=0; i<lnks.length; i++) {
		if(lnks[i].getAttribute('rel') == 'external') {
			lnks[i].onclick = new Function('window.open(this.href); return false');
		}
	}
}
onload = changeTarget;


//id = id des divs, das eingeblendet werden soll
//img = falls andere grafiken für die buttons als die default grafiken 'button_less.gif' und 'button_more.gif' verwendet werden sollen.
function show_hide(id, img) {
	if(img == null) img = '';
	with(document.getElementById(id).style) {
		if(display=="none") {
			display="block";
			eval('document.images.' + id + '_but.src = "templates/gamersware/img/buttons/button_' + img + 'less.gif"');
		} else {
			display="none";
			eval('document.images.' + id + '_but.src = "templates/gamersware/img/buttons/button_' + img + 'more.gif"');
		}
	}
}
//Funktion für eingeklappte Bereiche umgekehrt, da sonst 2X geklickt werden mußte!?
function hide_show(id) {
	with(document.getElementById(id).style) {
		if(display=="block") {
			display="none";
			eval('document.images.' + id + '_but.src = "templates/gamersware/img/buttons/button_more.gif"');
		} else {
			display="block";
			eval('document.images.' + id + '_but.src = "templates/gamersware/img/buttons/button_less.gif"');
		}
	}
}
//Funktion die eingeklappte Bereiche nur einblendet
function only_show(id) {
	with(document.getElementById(id).style) {
		if(display=="none") {
			display="block";
			eval('document.images.' + id + '_but.src = "templates/gamersware/img/buttons/button_less.gif"');
		}
	}
}
//Funktion einfacher Text als linktext
function only_show_text(id) {
	with(document.getElementById(id).style) {
		if(display=="none") {		
			display="block";
		}
	}
	element = document.getElementById('hide_text').style;
	element.display = "none";
}


//Warenkorb Box ein-/ausblenden
function hide_cart(id) {
	with(document.getElementById(id).style) display="none";
}
function show_cart(id) {
	with(document.getElementById(id).style) display="block";
}



//Folgende Variablen und Funktionen für Zurück-Button oben links auf Seite
var last_hash_value = false;
var history_length = 1;
var return_val = true;

try {
	window.clearInterval(timer_active);
} catch (e) {
	//alert(e)
}
var timer_active = false;

//Für alle Browser außer Opera und IE ab 5.5, um aktuellen Hash Wert zu ermitteln, falls User Back im Browser geklickt hat.
function get_window_hash() {
	if(last_hash_value != window.location.hash) {
		//User hat im Browser Back geklickt
		history_length--;
		last_hash_value = window.location.hash;
	}
}

//Um verschiedene Anker anzuspringen. Wird von Opera und IE ab 5.5 immer benutzt. Von Firefox und anderen nur, wenn nicht nur backToTop geklickt wurde.
function goto_anchor(achor_url) {
	return_val = true;
	
	if(is_opera) {
		//Opera nimmt jeden Klick (auch mehrmalige Klicks auf die gleiche Ankermarke z.B. #backToTop) in history.length auf.
		//Auch scheint nicht wie beim Firefox die Länge von history.length beschränkt zu sein. Deshalb hier so (auch weil Version 8 und 7 mit Code im else Zweig nicht zurecht kamen)
		if(!last_hash_value) {
			history_length = history.length;
			last_hash_value = true;
		}
	} else if(is_ie5_5up) {
		//Name des Ankerpunkts aus kompletten Pfad
		var anchor_id_position = achor_url.lastIndexOf("#") + 1;
		var anchor_id = achor_url.substr(anchor_id_position);
		
		//host_path_shop wird in includes/header.php gesetzt
		top.anchors_ie.location.href = host_path_shop + 'anchors_ie.php?hash=' + anchor_id;
		window.location.href = achor_url;
		
		if(last_hash_value != anchor_id) history_length++;
		last_hash_value = anchor_id;
		
		return_val = false;
	} else {
		//Firefox scheint history.length auf 50 Einträge zu beschränken. Deshalb dieser Weg.
		//Name des Ankerpunkts aus kompletten Pfad (hier mit #)
		//Getestet für Firefox und Safari. IE 5 verhält sich in diesem Fall wie Firefox.
		var anchor_id_position = achor_url.lastIndexOf("#");
		var anchor_id = achor_url.substr(anchor_id_position);
		
		//Nicht durch Script, sondern einfach den href Teil ausführen lassen, indem return_val nicht auf true gesetzt wird.
		//window.location.href = achor_url;
		//return_val = false;
		
		//Falls schon auf backToTop geklickt wurde
		if(window.location.hash == '#backToTop' && timer_active == false) {
			history_length++;
			last_hash_value = '#backToTop';
		}
		
		if(anchor_id != last_hash_value) {
			history_length++;
			last_hash_value = anchor_id;
		}
		
		//Falls Intervall zum pollen des Window Hash Werts noch nicht gestartet wurde.
		if(timer_active == false) {
			//Wert 100 = 10 Mal pro Sekunde. Bei Wert 1000 = 1 Mal pro Sekunde hat es bei schnellem Back im Firefox nicht geklappt.
			timer_active = window.setInterval("get_window_hash()", 100);
		}
	}
}

//Für Links backToTop
function goto_top(backtotop_url) {
	//Opera und IE ab 5.5 immer mit goto_anchor(). Bei Firefox Timer bzw. setInterval() nicht bentuzen, wenn nur Links mit backToTop geklickt wurden.
	if(is_opera || is_ie5_5up || timer_active != false) goto_anchor(backtotop_url);
}

//Um History für IE ab 5.5 ermitteln zu können.
function write_history_iframe_ie() {
	if(is_ie5_5up) {
		document.write('<iframe src="anchors_ie.php?hash="' + false + ' width="0" height="0" name="anchors_ie"></iframe>');
	}
}

//Funktion für Zurück-Button links oben
function go_back() {
	//alert(timer_active);
	
	if(is_opera && last_hash_value) history_length = history.length - history_length + 1;
	
	if(history_length > 1) {
		//alert(history_length + ' Schritte L zurück');
		history.go(-history_length);
	} else if(window.location.hash == '#backToTop' && !is_ie5_5up && !is_opera) {
		//alert('Firefox und Safari nur backToTop Links ohne gestarteten Timer');
		history.go(-2);
	} else {
		//alert('1 Schritt zurück');
		history.back();
	}
}

function enlarge_entry(obj) {
	if(!document.getElementById || is_ie4 || is_ie5 || is_ie5_5) return true;
	
	var items = obj.parentNode.getElementsByTagName('div');
	for(var i=0; i<items.length; i++) {
		items[i].className = (items[i]==obj) ? 'active' : '';
	}
	return false;
}
