Cufon.replace('h1, h2, h3, h4', {hover: true, hoverables: { h2: true, a: true }} );
Cufon.replace('.menu>ul>li>a, .pager a',{hover: true, hoverables: { a: true, li: true }});
Cufon.replace('#content .sitemap-wrapper>ul>li>a',{hover: true, hoverables: { a: true, li: true }});

function replaceText() {
	$("body *").each(function() { 
		if($(this).children().length===0) { 
			$(this).html($(this).html().replace('CO2', 'CO<sub>2</sub>')); 
		} 
	});
}        



$(document).ready(function() {

	$('input[title!=""]').hint();
	$("div.menu ul:first").ohMenu();
	$(document).ready(replaceText);
	//$("html").ajaxStop(replaceText);


	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});


	// rearrange site-map layout

	var oldMap = $("div.sitemap-wrapper ul");
	$firstCol = [];
	$secondCol = [];
	$thirdCol = [];
	$fourthCol = [];

	// remove extra header labels that are in the menu

	$("div.site-map").append("<div id='col-one' class='col'></div>");
	$("div.site-map").append("<div id='col-two' class='col'></div>");
	$("div.site-map").append("<div id='col-three' class='col'></div>");
	$("div.site-map").append("<div id='col-four' class='col'></div>");
	$("div.site-map:first ul > li a").each(function() {
		if($(this).text() == 'About ICO2N') {
			$firstCol.push($(this).parent());
		}

		if($(this).text() == 'What is CCS') {
			$secondCol.push($(this).parent());
		}

		if($(this).text() == 'CCS in Canada') {
			$thirdCol.push($(this).parent());
		}

		if($(this).text() == 'CCS International') {
			$fourthCol.push($(this).parent());
		}

		if($(this).text() == 'Library') {
			$fourthCol.push($(this).parent());
		}

		if($(this).text() == 'News') {
			$fourthCol.push($(this).parent());
		}
	});


	$.each($firstCol,function( intIndex, objValue ){
		var ul = document.createElement("ul");
		ul.setAttribute("class", intIndex);
		$("#col-one").append(ul);
		$("#col-one ul:first").append(objValue);
		ul.setAttribute("class", "menu");
	});

	$.each($secondCol,function( intIndex, objValue ){
		var ul = document.createElement("ul");
		ul.setAttribute("class", intIndex);
		$("#col-two").append(ul);
		$("#col-two ul:first").append(objValue);
		ul.setAttribute("class", "menu");
	});

	$.each($thirdCol,function( intIndex, objValue ){
		var ul = document.createElement("ul");
		ul.setAttribute("class", intIndex);
		$("#col-three").append(ul);
		$("#col-three ul:first").append(objValue);
		ul.setAttribute("class", "menu");
	});

	$.each($fourthCol,function( intIndex, objValue ){
		var ul = document.createElement("ul");
		ul.setAttribute("class", intIndex);
		$("#col-four").append(ul);
		$("#col-four ul:first").append(objValue);
		ul.setAttribute("class", "menu");
	});


	$("div.site-map ul:first").remove();
	$("#col-one > ul > li:eq(1)").remove();
	$("#col-one > ul > li:eq(1)").remove();
	$("#col-two > ul > li:eq(1)").remove();
	$("#col-three > ul > li:eq(1)").remove();
	$("#col-four > ul > li:eq(3)").remove();
	$("#col-four > ul > li:eq(3)").remove();
	$("#col-four > ul > li:eq(3)").remove();

	$("#col-one > ul >li:eq(0) a:first").html('About ICO<sub>2</sub>N');
	Cufon.replace('#col-one > ul >li:eq(0) a:first');	


	$('#print').click(function() {
		window.print();
		return false;
	});

	$('#textsize').cycleFontSize({increaseEle: "#content"});

	$(".colorbox").colorbox({
		opacity: 0.7
	});

	// qTip setup

	$('#content a.qtip').click(function(e) {
		e.preventDefault();
	});

	// By suppling no content attribute, the library uses each elements title attribute by default
	$('#content a.qtip').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		position: {
			corner: {
				target: 'bottomLeft'
			}
			// Automatically reposition the qtip if there is not enough room to display it
			// ,
			// 			adjust: {
			// 				screen: true
			// 			}
		},
		style: { // Give it some style
			tip: { // Now an object instead of a string
				corner: 'topLeft', // We declare our corner within the object using the corner sub-option
				color: '#ccdceb'
			},
			border: { width: 0 },
			background: '#ccdceb',
			color: '#333'
		} 
	});

	// Accordion
	//$(".accordion").accordion({ header: "h3", collapsible: true, activate: false });
	
	$('.accordion h3').click(function() {
		$(this).parent().toggleClass('active')
		$(this).next().toggle();
		return false;
	}).next().hide();
	
	$('.sub-accordion h3').click(function() {
		$(this).parent().toggleClass('active')
		$(this).next().toggle();
		return false;
	}).next().hide();
	
});
