/*
* Version: 04-11-2006
* Mixed Emotions JAVASCRIPT
*
* Author: Dirty.Design - Ontwerp & nieuwe media
*
*/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function init() {
	formInputValues();
	parseLinks(); // XHTML compliant links

	if (document.getElementById("itemScrollerLayerLeft") || document.getElementById("bannerAdSenseLeft")) {
		itemscrollerLeft();
		window.onresize = itemscrollerLeft;
	}

	// <![CDATA[
	flashItemScroller = document.getElementById("itemScroller");
	if (flashItemScroller) {
		flashItemScroller.startScroller();
	}
	// ]]>
}

function addSong(str) {
	// <![CDATA[
	flashMp3Player = document.getElementById("mp3player");
	
	if (flashMp3Player) {
		flashMp3Player.addSong(str);
	}
	// ]]>
}

function goBack(str) {
	// <![CDATA[
	flashMp3Player = document.getElementById("mp3player");
	
	if (flashMp3Player) {
		flashMp3Player.goBack(str);
	}
	// ]]>
}

function parseLinks() {
	if (!document.getElementById) return;

	var a = document.getElementsByTagName('a'), i = a.length;
	while (i--) {
		if (a.item(i).getAttribute('rel') == 'external') {
			a.item(i).onclick = function() { window.open(this.href); return false; }
		}
	}
}

function formInputValues() {
	if (!document.getElementById) return;

	var defValueN_email		= 'E-mail adres';
	var defValueS_query		= 'Ik zoek...';

	var formN = document.getElementById('newsletter');
	var formS = document.getElementById('search');

	if(formN){
		formN['email'].value = defValueN_email;
		formN['email'].onfocus = function z () { if(formN['email'].value == defValueN_email) this.value = ''; }
		formN['email'].onblur = function z () { if(formN['email'].value == '') this.value = defValueN_email; }
	}

	if(formS){
		formS['query'].value = defValueS_query;
		formS['query'].onfocus = function z () { if(formS['query'].value == defValueS_query) this.value = ''; }
		formS['query'].onblur = function z () { if(formS['query'].value == '') this.value = defValueS_query; }
	}
}

function scroll(target, itemsTotal, itemsPerRow, itemsWidth, direction){

	if(!document["currentPos"+target]){
		document["currentPos"+target] = 0;
	}

	if(direction == 0){
		if(document["currentPos"+target] > 0){
			document["currentPos"+target] = document["currentPos"+target] - 1;
			document.getElementById(target).style.left = "-" + (document["currentPos"+target] * itemsWidth) + "px";
		}
	}else if (direction == 1){
		if(document["currentPos"+target] < (itemsTotal - itemsPerRow)){
			document["currentPos"+target] = document["currentPos"+target] + 1;
			document.getElementById(target).style.left = "-" + (document["currentPos"+target] * itemsWidth) + "px";
		}
	}
}

function changePhoto(album, image){
	document.getElementById('photo-photo').src = 'photoalbums/' + album + '/' + image;
}

function changeQty(page, value, id){
	window.location.href = page + '.php?changeQtyId=' + id + '&changeQtyValue=' + value;
}

function emptyCart(page){
	var empty = confirm("Wilt U uw winkelmandje legen?");
	if (empty) window.location.href = page + '.php?empty=1';
}

function toggleCat( cid ){
	var ml = document.getElementById('cid_'+cid);
	if (ml.className == 'catOn')
	ml.className = 'catOff';
	else if (ml.className == 'catOff')
	ml.className = 'catOn';
}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
	while(1)
	{
		curleft += obj.offsetLeft;
		if(!obj.offsetParent)
		break;
		obj = obj.offsetParent;
	}
	else if(obj.x)
	curleft += obj.x;
	return curleft;
}

function itemscrollerLeft() {
	if (document.getElementById("itemScrollerLayerLeft")) {
		document.getElementById("itemScrollerLayerLeft").style.left = (findPosX(document.getElementById("site-container")) - 135) + "px";
	} else {
		document.getElementById("bannerAdSenseLeft").style.left = (findPosX(document.getElementById("site-container")) - 135) + "px";
	}
}

addLoadEvent(init); // Init scripts
