
jQuery(document).ready(function(){
	domColorAllLinks();
	domColorAllHeadlines();
	domColorAllButtons();
	domColorAllContainers();
	domColorAllBackgroundElements();
	
	
	/*
	 * **********************************************************************************************
	 * Special hack for "projektrum" settings
	 * **********************************************************************************************
	 * If the "projektrum" is being edited, manually force the template to get rid of the sidebar
	 * and expand the content area to its widest setting, regardless of which template is being
	 * used. One day this might swim up and bite us on the ass (that was from "Jaws") (and THAT was
	 * from "Clerks"), but for now it works.
	 * **********************************************************************************************
	 */
	
	var locSrc = window.location.search;
	if (locSrc.indexOf("tx_ktcprojectroom_pi1%5Bmode%5D=edit") > -1 || locSrc.indexOf("tx_ktcprojectroom_pi1[mode]=edit") > -1) {
		jQuery("#farright").hide();
		jQuery("#contentmain").css("width", "690px");
	};
	
	/*
	 * **********************************************************************************************
	 * That's it for now. No more hacks, I swear!
	 * **********************************************************************************************
	 */
	
});

function domColorAllLinks() {

	jQuery("a.markedLink, .csc-sitemap a").each(function(){
		var hlink = jQuery(this).attr("href").toLowerCase();
		if (hlink[0] == "/") hlink = hlink.substr(1);

		jQuery(this).removeClass("sectionYellow sectionGreen sectionBlue sectionExternalLink");

		if (hlink.substr(0, 5) == "viden" || hlink.substr(0, 13) == "kompetencenet" || hlink.substr(0, 9) == "offentlig")
			jQuery(this).addClass("sectionYellow");
		if (hlink.substr(0, 10) == "foreningen")
			jQuery(this).addClass("sectionGreen");
		if (hlink.substr(0, 13) == "teknik-miljoe")
			jQuery(this).addClass("sectionBlue");

		if (
			(hlink.substr(0, 7) == "http://") ||
			(hlink.substr(0, 8) == "https://") ||
			(hlink.substr(0, 6) == "ftp://")
		)
			jQuery(this).addClass("sectionExternalLink");
	});
}

function domColorAllButtons() {
	var setColor = getSectionColor();
	if (setColor) {
		setColor = "markSectionButton" + setColor;
		jQuery("button.jQueryColorButton, input.jQueryColorButton[type='submit']").each(function() {
			jQuery(this).addClass(setColor);
		});
	}
}

function domColorAllHeadlines() {
	var setColor = getSectionColor();
	if (setColor) {
		var textColor = "markSectionText" + setColor;
		jQuery(".jQueryColorText").each(function() {
			jQuery(this).addClass(textColor);
		});
	}

	// *************************
	//  Special cases for forum
	// *************************
	var fCont = jQuery("#tx_chcforum-pi1");
	var hasForum = fCont.length;
	if (hasForum) {
		var setCls = "jQueryColorText";
		if (setColor) setCls += " markSectionText" + setColor;
		var thCls = "markSectionBackground" + ((setColor) ? setColor : "General");
		fCont.find("tbody th, h1, h2, h3, h4, h5, h6").addClass(setCls);
		fCont.find("thead th, #formWhere").addClass(thCls);
	}
}

function domColorAllContainers() {
	var setColor = getSectionColor();
	if (!setColor) setColor = "General";

	jQuery(".tabholder").each(function() {
		jQuery(this).addClass("markSectionTabholder" + setColor);
	});

	jQuery(".formholder").each(function() {
		jQuery(this).addClass("markSectionFormholder" + setColor);
	});
}

function domColorAllBackgroundElements() {
	var setColor = getSectionColor();
	if (!setColor) setColor = 'General';

	jQuery(".jQueryColorBackground").each(function() {
		jQuery(this).addClass("markSectionBackground" + setColor);
	});
}

function getSectionColor() {
	var navStr = window.location.pathname;
	var sections = {
		"viden" : "Yellow",
		"offentlig" : "Yellow",
		"foreningen" : "Green",
		"teknik-miljoe" : "Blue"
	}
	for (sectionName in sections) {
		if (navStr.substr(1, sectionName.length) == sectionName)
			return sections[sectionName];
	}
	return false;
}
