
function navigationFolding(){ 
    var nav = document.getElementById('navigation');
    var items = nav.getElementsByTagName('LI');
    for(var i = 0; i < items.length; i++) {
        if(items[i].className != '' && items[i].className != 'current') {
            
            items[i].childNodes[0].setAttribute('href', '#');
            
            items[i].onclick = function() {
                this.blur();
                if(this.id == 'navigation-reset') {
                    document.body.id = 'home';
                    foldAllItems(items, 1);
                } else {
                    document.body.id = '';
                    foldAllItems(items, 0);
                    expandItem(this);
                }
                return false;
            }
        }
    }
}

function foldAllItems(items, reset) {
    for(var i = 0; i < items.length; i++) {
        items[i].className = items[i].className.replace('expanded', '');
        items[i].className = items[i].className.replace('folded', '');
        if(!reset) {
            items[i].className += ' folded';
        }
    }
}

function expandItem(item) {
    item.className = item.className.replace('folded', '');
    if(item.className != '') {
        item.className += ' expanded';
    }
}

function clearSearchBox() {
    if(document.getElementById('keyword-heading')) {
        document.getElementById('keyword-heading').onfocus = function() {
            if(!clearSearchBoxHeadingBool) {
                this.value = '';
                clearSearchBoxHeadingBool = true;
            }
        }
    }
    if(document.getElementById('keyword-home')) {
        document.getElementById('keyword-home').onfocus = function() {
            if(!clearSearchBoxHomeBool) {
                this.value = '';
                clearSearchBoxHomeBool = true;
            }
        }
    }
}

var clearSearchBoxHeadingBool = false;
var clearSearchBoxHomeBool = false;

function imageViewer() {
    if(document.getElementById('product-image')) {
        var thumbdiv = document.getElementById('product-thumbs');
        var thumbs = thumbdiv.getElementsByTagName('IMG');
        for(i = 0; i < thumbs.length; i++) {
            thumbs[i].onclick = function() {
            		var bigimg = document.getElementById('product-image').src;
                document.getElementById('product-image').src = this.src.replace('/tb', '');
                var pos = bigimg.lastIndexOf('/');
                var imgurl = bigimg.substring((pos+1), bigimg.length);
                this.src = '/img/product/tb/'+imgurl;
            };
            
            thumbs[i].onmouseover = function() {
            	this.style.cursor = 'pointer';
            }
            
            thumbs[i].onmouseout = function() {
            	this.style.cursor = 'default';
            }
        }
    }
}

window.onload = function() {
    // navigationFolding();
    clearSearchBox();
    imageViewer();
}

/* AJAX om de dropdown bij het zoeken te maken */
function createRequestObject() {
  try {
	  var ro = new XMLHttpRequest();
	}
	catch (error) {
		try {
			var ro = new ActiveXObject("Microsoft.XMLHTTP");
		}
    catch (error) {
			return false;
		}
	}
	return ro;
}

var http = createRequestObject();

function buildProductDropdown(designer) {
	http.open('get', '/inc/ajax.inc.php?designer='+designer);
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function handleResponse() {
	if(http.readyState == 4){
		var response = http.responseText;
		document.getElementById("productdropdown").innerHTML = response;
  }
}

function checkbuildProductDropdown() {
	if(document.search) {
		buildProductDropdown(document.search.designer.options[document.search.designer.selectedIndex].value);
	}
	else {
	}
}