// shuffle
// this function returns an array with the same values as the passed array, but shuffled into a new, random order
function shuffle(o) {
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
}

// pullParts
// this function sets the global variables label and subLabel according to the content of the parts variable after parsing
function pullParts() {

	label = parts.split("|")[0];
	if (parts.split("|").length > 1) subLabel = parts.split("|")[1];
	
	// ie fix (ie uses a fully-qualified path rather than a relative path)
	if (label.indexOf("/") > -1) label = label.substring(label.lastIndexOf("/")+1,label.length);
	
	// ie fix (ie uses a fully-qualified path rather than a relative path)
	if (subLabel.indexOf("/") > -1) subLabel = subLabel.substring(subLabel.lastIndexOf("/")+1,subLabel.length);
	
}

// arrayPos
// this function returns the position a given value occupies in an array, or -1 if it is not found
function arrayPos(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return i;
    }
    return -1;
}

// makeColorBullets
// function to make bullets one color and text another with spans
$.fn.makeColorBullets = function(bulletClass,textClass) {

	// loop through elements 
	for (var i=0; i<this.length; i++) {
		
		// add the class for the bullet color
		$(this[i]).addClass(bulletClass);
		
		// add a span around content and set to class for text color
		$(this[i]).find("li").wrapInner("<span class=" + textClass + " />");
	
	}

}

// toggleHighlight
// this function is run with an "each" jQuery command on a's to set the on-state (persistent) of an image to the same image name with -on appended
function toggleHighlight(i,e) {
	
	var myURL = $(e).find("img").attr("originalSRC");

	if (!$(e).hasClass("selected")) {
		var newURL = myURL.substr(0,myURL.lastIndexOf(".")) + "-on" + myURL.substr(myURL.lastIndexOf("."),myURL.length);
		$(e).addClass("selected");
	} else { 
		var newURL = myURL;
		$(e).removeClass("selected");
	}
	
	$(e).find("img").attr("src",newURL);
	
}

// makeHover
// this function is run with an "each" jQuery command on a's to set the over-state (mouse over) of an image to the same image name with -on appended
function makeHover(i,e) {
	
	var myURL = $(e).find("img").attr("src");
	$(e).find("img").attr("originalSRC",myURL);
	
	if (myURL.indexOf("-on.") == -1) {
		
		var myOnURL = myURL.substr(0,myURL.lastIndexOf(".")) + "-on" + myURL.substr(myURL.lastIndexOf("."),myURL.length);
	
		$(e).hover(function() {
			if (!$(e).hasClass("selected")) $(e).find("img").attr("src",myOnURL);
		},function(){
			if (!$(e).hasClass("selected")) $(e).find("img").attr("src",myURL);
		});
		
	}
	
}

// randRange
// return random number between min and max passed
function randRange(min,max) {
	return Math.floor(Math.random()*(max-min+1)) + min;	
}
