// dnr.js

Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');

Drupal.behaviors.dnr_theme = function(context) {
  dnrLoad();
}

$(window).load(function(){
	if($('#matrix tr.map-column-header').length > 0) {
	  make_sticky();
	}
});

// Flipper stuff flollows: 
var flipperIndex;
var slides;
var theTitle = new Image();
var dots = [];
var flipper_pause = 6000;  // 6000 miliseconds
var flipper_interval;

function dnrLoad(){
	if(document.getElementById("sm_flipper")) {
		init_sm_flipper();	
	}
}

function elem(elementId) {
	return document.getElementById(elementId);
}

/*
* The homepage no longer has a flipper.
*/


function swap() {
	if(flipperIndex == 3) {
		switch_slide(0);
		flipperIndex = 0;
	}
	else {
		switch_slide(++flipperIndex,false);
	}
}


function init_sm_flipper(){
	slides = parseInt(elem("sm_flipper_count").innerHTML);
	flipperIndex = 1;
	flipper_interval = setInterval("sm_swap()", flipper_pause);
}

function sm_swap() {
  if(flipperIndex == slides) {
		sm_switch_slide(1);
		flipperIndex = 1;
	}
	else {
		sm_switch_slide(++flipperIndex, false);
	}
}

function sm_flip_left() {
  clearInterval(flipper_interval);
	if(flipperIndex == 1) {
		sm_switch_slide(slides);
	}
	else {
		sm_switch_slide(flipperIndex - 1);
	}
}

function sm_flip_right() {
  clearInterval(flipper_interval);
	if(flipperIndex == slides) {
		sm_switch_slide(1);
	}
	else {
		sm_switch_slide(flipperIndex + 1);
	}
}

function sm_switch_slide(newSlide, stopInterval) {
  if(stopInterval) {
    clearInterval(flipper_interval);
  }
	for(var s=1; s <= slides; s++) {
		if(s == newSlide) {
			elem('slide'+s).style.display = "block";
			elem('dot'+s).className = "dot_on";
		}
		else {
			elem('dot'+s).className = "dot_off";
			elem('slide'+s).style.display = "none";
		}
	}
	flipperIndex = newSlide;
}

function park_go(dest) {
		if (dest) location.href = dest;
}

//sticky map matrix headers:
function make_sticky(){
  floater = $('<div id="floater"></div>');
  $(floater).css('top', $('#matrix').position().top);
  $(floater).css('left', $('#matrix').position().left);
  $(floater).css('height', $('#matrix tr.map-column-header').height());
  $(floater).css('width', $('#matrix table').width() + 1);
  $('#matrix table').clone().appendTo(floater);
  $('#content-area').append(floater);
}

