var active_color = '#444'; // Color of user provided text
var inactive_color = '#aaa'; // Color of default text

$(document).ready(function() {
						   
  $("input.default-value").css("color", inactive_color);
  var default_values = new Array();
  $("input.default-value").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    $(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
    });
  });
  
	// Tabs navigation
	//$('#tabs-container').tabs({ fxFade: true, fxSpeed: 'fast' });
	$('#tabs-container > ul').tabs();
	// $('#footer-sitemap #tabs-container > ul').tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 5000);
	$('#footer-sitemap #tabs-container-footer > ul').tabs();
	
	$("ul.toc a").click(function(){ 
		$.scrollTo( this.hash, "fast", { easing:'easeOutCubic' });
		return false;
	});
	$("span.top-link a").click(function(){ 
		$.scrollTo( this.hash, "fast", { easing:'easeOutCubic' });
		return false;
	});
	
	$('#slideshow').before('<ul id="nav-slideshow">').cycle({ 
		fx:     'fade', 
		speed:  50, 
		timeout: 0, 
		pager:  '#nav-slideshow', 
		 
		// callback fn that creates a thumbnail to use as pager anchor 
		pagerAnchorBuilder: function(idx, slide) { 
			slide = "" + slide;
			splitted = slide.split(".");
			if (splitted.length<2)
				return '<!-- slide defective -->';
			recombined = "";
			for (i=0; i<splitted.length-2; i++)
				recombined += splitted[i]+".";
			recombined += splitted[splitted.length-2] + "t." + splitted[splitted.length-1];

			return '<li><a href="#"><img src="' + recombined + '" width="25" height="25" /></a></li>'; 
		} 
	});
	
	$('ol#quicklist li').quicksearch({
		position: 'before',
		attached: 'ol#quicklist',
		loaderImg: '/images/site/zoomloader.gif',
		delay: 500,
		inputText: "Search in this page",
		labelText: ''
	});
	$('div#quicklist p').quicksearch({
		position: 'before',
		attached: 'div#quicklist',
		loaderImg: '/images/site/zoomloader.gif',
		delay: 500,
		inputText: "Search in this page",
		labelText: ''
	});
	
	$('a[href$=pdf].hovertip').bt({
		fill: "rgb(242, 242, 242)",
		padding: "15px",
		strokeStyle: "#c7c7c7",
		cornerRadius: 4,
		spikeLength: 30,
		spikeGirth: 15,
		cssStyles: {fontSize: '11px', lineHeight: '15px'}
	});
	
	$('a.zoomable').bt({
		postShow: function() {
			$(this).attr('bt-xtitle', $(this).attr(''));
		},
		closeWhenOthersOpen: true,
  		trigger: 'hoverIntent',
		contentSelector: "$(this).attr('bt-xtitle')",
		fill: "rgb(242, 242, 242)",
		padding: "15px",
		strokeStyle: "#c7c7c7",
		cornerRadius: 4,
		spikeLength: 30,
		spikeGirth: 15,
		cssStyles: {fontSize: '11px', lineHeight: '15px'},
		positions: ['bottom'],
		hoverIntentOpts:  {
			interval: 300 // http://cherne.net/brian/resources/jquery.hoverIntent.html
			//timeout: 5000
		}
	});
	
	$('a.ajaxtip').bt({
		closeWhenOthersOpen: true,
		ajaxCache: false,
  		trigger: ['hoverIntent', 'unload'],
		ajaxPath: ["$(this).attr('bt-xtitle')", 'div#inner-wrapper'],
		fill: "rgb(229, 229, 229)",
		padding: "15px",
		strokeStyle: "#c7c7c7",
		width: 300,
		cornerRadius: 4,
		spikeLength: 30,
		spikeGirth: 15,
		cssStyles: {fontSize: '90%'},
		positions: ['left','right'],
		hoverIntentOpts:  {
			interval: 300, // http://cherne.net/brian/resources/jquery.hoverIntent.html
			timeout: 5000
		}
	});
	
	$('a.glossary').bt({
		closeWhenOthersOpen: true,
		ajaxCache: false,
  		trigger: ['hoverIntent', 'unload'],
		ajaxPath: ["$(this).attr('bt-xtitle')", 'div#content-glossary'],
		fill: "rgb(229, 229, 229)",
		padding: "15px",
		strokeStyle: "#c7c7c7",
		width: 200,
		cornerRadius: 4,
		spikeLength: 30,
		spikeGirth: 15,
		cssStyles: {fontSize: '90%'},
		positions: ['left','right'],
		hoverIntentOpts:  {
			interval: 300, // http://cherne.net/brian/resources/jquery.hoverIntent.html
			timeout: 500
		}
	});
	
	$('.hoverimage a[href$=jpg]').bt(
		{ 
		contentSelector: "'<img src=\"'+ $(this).attr('href') + '\" width=\"500\">'",
		width: 500,
		fill: "rgb(242, 242, 242)",
		padding: "15px",
		strokeStyle: "#c7c7c7",
		cornerRadius: 4,
		spikeLength: 30,
		spikeGirth: 15,
		cssStyles: {fontSize: '11px', lineHeight: '15px'}
	});
	
	$('a#toggle-link').click(function() {
		$('#toggle-box').slideToggle(400);
		return false;
	});
	
	// Textpattern outputs a br after every li in an ol (sibling ~ selector)
	$('li.file-name ~ br').css("display", "none");
	// Textpattern outputs a br after every li in an ul (sibling ~ selector)
	$('li.file-description ~ br').css("display", "none");
	//$('a[href$=".pdf"] > img').css("background" , "none");
	
	// Fade in note
	$(".note").fadeIn(3000);
	
});
	
function initJumpMenus() {
	// Turns all <select> elements with the 'jumpmenu' class into jump menus
	var selectElements = document.getElementsByTagName("select");
	// Set jumpmenu value to first on load (used for back button)
	document.getElementById("jm1").value = "";
	for( i = 0; i < selectElements.length; i++ ) {
		// Check for the class and make sure the element has an ID
		if( selectElements[i].className == "jumpmenu" && document.getElementById(selectElements[i].id) != "" ) {
			jumpmenu = document.getElementById(selectElements[i].id);
			jumpmenu.onchange = function() {
				if( this.options[this.selectedIndex].value != '' ) {
					// Redirect
					location.href=this.options[this.selectedIndex].value;
				}
			}
		}
	}
}

window.onload = function() {
	if(document.getElementById('jm1')) {
		initJumpMenus();
	}
}