/*
Show overview Foldout
param	id	numeric	Number of foldout to show (#overview[id]) 
*/
function showFoldout(id) {
	// Hide all elements with classname 'overviewFoldout'
    $(".overviewFoldout").each(function(i) {
        $(this).hide();
    });
	// Show requested element
	try{
	    var overview = $("#overview" + id);
	    if(overview.size() == 1) {
	        overview.show();
		    // Deactivate the active tab
            $(".active").removeClass("active");
        
	        // Activeate selected tab
            $("#tab" + id).addClass("active");
        } else {
            $("#overview6").show();
	        $("#selFilter").val(1);
	        $(".active").removeClass("active");
	        $("#tab6").addClass("active");
	        $("#inchOverview").css("display","block");
            $("#ageOverview").css("display","none");
        }
	}catch(e){ 
	    $("#overview6").show();
	    $("#selFilter").val(1);
	    $(".active").removeClass("active");
	    $("#tab6").addClass("active");
	    $("#inchOverview").css("display","block");
        $("#ageOverview").css("display","none");
	}
	
	
}

/*
Add a trim() function to the String object.
*/
/*
Add a trim() function to the String object.
*/
String.prototype.trim = function () {
	var	s = this.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = s.length;
	while (ws.test(s.charAt(--i)));
	return s.slice(0, i + 1);
}

function getObjectsByClassname(clsName) {
	var retVal = new Array();
	var elements = document.getElementsByTagName("*");
	
	for(var i = 0;i < elements.length;i++) {
		if(elements[i].className.indexOf(" ") >= 0) {
			classes = elements[i].className.split(" ");
			for(var j = 0;j < classes.length;j++){
				if(classes[j] == clsName) {
					retVal.push(elements[i]);
				}
			}
		}
		else if(elements[i].className == clsName) {
			retVal.push(elements[i]);
		}
	}
	return retVal;
}


function RemoveClassName(objElement, strClass) {
	// if there is a class
	if ( objElement.className ) {
	
	   // the classes are just a space separated list, so first get the list
	   var arrList = objElement.className.split(' ');
	
	   // get uppercase class for comparison purposes
	   var strClassUpper = strClass.toUpperCase();
	
	   // find all instances and remove them
	   for ( var i = 0; i < arrList.length; i++ )
	      {
	
	      // if class found
	      if ( arrList[i].toUpperCase() == strClassUpper )
	         {
	
	         // remove array item
	         arrList.splice(i, 1);
	
	         // decrement loop counter as we have adjusted the array's contents
	         i--;
	
	         }
	
	      }
	
	   // assign modified class name attribute
	   objElement.className = arrList.join(' ');
	
	   }
	// if there was no class
	// there is nothing to remove
}

function AddClassName(objElement, strClass, blnMayAlreadyExist) {
	
	// if there is a class
	if ( objElement.className )
	   {
	
	   // the classes are just a space separated list, so first get the list
	   var arrList = objElement.className.split(' ');
	
	   // if the new class name may already exist in list
	   if ( blnMayAlreadyExist )
	      {
	
	      // get uppercase class for comparison purposes
	      var strClassUpper = strClass.toUpperCase();
	
	      // find all instances and remove them
	      for ( var i = 0; i < arrList.length; i++ )
	         {
	
	         // if class found
	         if ( arrList[i].toUpperCase() == strClassUpper )
	            {
	
	            // remove array item
	            arrList.splice(i, 1);
	
	            // decrement loop counter as we have adjusted the array's contents
	            i--;
	
	            }
	
	         }
	
	      }
	
	   // add the new class to end of list
	   arrList[arrList.length] = strClass;
	
	   // add the new class to beginning of list
	   //arrList.splice(0, 0, strClass);
	   
	   // assign modified class name attribute
	   objElement.className = arrList.join(' ');
	
	   }
	// if there was no class
	else
	   {
	
	   // assign modified class name attribute      
	   objElement.className = strClass;
	
	   }
}

var currentImage = '';

function switchImage(imageName, clickedObject) {
	if (currentImage != imageName) {
		document.getElementById('productSwitch').src = imageName;
		currentImage = imageName;
	}
	
	var typeLinks = getObjectsByClassname('productType');
	
	for(var i = 0;i < typeLinks.length;i++) {
		RemoveClassName(typeLinks[i], 'selected');
	}
	// Show requested element
	AddClassName(clickedObject, 'selected');
}

function switchColor(colorName) {
   document.getElementById('productColor').innerHTML = 'Kleur: ' + colorName;
}

function initTabsNews() {
	$("#newshighlights > ul").tabs({ fx: 
		[
			{opacity:'toggle', duration:'slow'},   // hide option 
			{opacity:'toggle', duration:'slow'}	// show option
		]
	}).tabs('rotate', 5000, false);
	
	
	$("#newshighlights > ul").bind('tabsshow', function() {
		var idx = $(this).tabs('option', 'selected');
		if(!replaced[idx]) {
			sIFR.replace(homeworkNormal, {
				selector: 'div.deurmatKolom h5'
				,css: ['.sIFR-root { font-size: 30px; color: #FFFFFF; text-decoration: none; text-align: center;} a { color: #FFFFFF; text-decoration: none; } a:hover {color: #FFFFFF; text-decoration: none; }']
				,wmode: 'transparent'
				,selectable: false
			});
			replaced[idx] = true;
		}
	});
	
	$('div#newshighlights > ul').bind('mouseenter', function(ev) {
		$('#newshighlights > ul').tabs('rotate', 0, false);
	});
	
	$('div#newshighlights > ul').bind('mouseleave', function(ev) {
		$('#newshighlights > ul').tabs('rotate', 5000, false);
	});
	
	$('div#newshighlights').css('visibility', 'visible');
}