/**
 * 
 * @author frbk
 * @reference http://alistapart.com/stories/alternate/
 *
 */

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
  			a.disabled = true;
  			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	
	swapImages(title, 'logo');
	swapImages(title, 'logo_full_img');
}

/**
* By: frbk
* Changing selected background chooser button
*/
	
function changeChooser(title) {
	red_obj = $('red_chooser');
	black_obj = $('black_chooser');
	
	if(title == 'red') {
		red_obj.style.className = 'red_selected';
		red_obj.className = 'red_selected';
		black_obj.style.className = 'black';
		black_obj.className = 'black';
	} else if(title == 'black') {
		red_obj.style.className = 'red';
		red_obj.className = 'red';
		black_obj.style.className = 'black_selected';
		black_obj.className = 'black_selected';
	}
}

/**
* By: frbk
* Changing images to comply with selected background
*/

function swapImages(title, classname) {
	tgt_objs = getElementsByClassName(document, '*', classname);

	for(i=0; (a = getElementsByClassName(document, '*', classname)[i]); i++) {
		old_src = a.src.substr(a.src.lastIndexOf('\/', a.src), a.src.length);
		new_src = "img/" + title + old_src;
		
		a.src = new_src;
	}
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) return a.getAttribute("title");
	}
	return null;
}