// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function fix_two() {
	var one = document.getElementById('one');
	var two = document.getElementById('two');
	one.width = 93;
	two.width = 93;
//	alert('Image width: ' + one.width);
}

function fix_one() {
	var one = document.getElementById('one');
	one.width = 186;
}

var item;
var current;
var sliding = false;
var height;

function doneSliding() {
	sliding = false;
	$('container').height = height;
	//alert('Final height: ' + $('container').height);
}

function slide(i) {
	height = $('container').offsetHeight;
	//alert('Current height: ' + height);
	if (sliding) return(false);

	if (i.id == 'tips_and_tools_link') {
		return(false);
	}
	
	if (i.parentNode.id == 'current2') {
		return(true);
//		if(current.childNodes[2].style.display != 'none')
//			return(false);
	}
	if(i.parentNode.id == 'current' && i.parentNode.childNodes[2] && i.parentNode.childNodes[2].style.display != 'none') {
		return(false);
	}
	

	sliding = true;		
	item = i
	current = $('current2');

	if (!current)
		current = $('current');


	if (current) {
		if (current.childNodes[2]) {
			new Effect.BlindUp(current.childNodes[2], {duration:0.34, afterFinish:slide2});
		} else {
			return(slide2(i));
		}
		return(false);
	} else {
		return (slide2(item));
	}
}

function slide2(obj) {
	if (current && current.id == 'current2') current.id = '';
	if (item.parentNode.id != 'current')
		item.parentNode.id = 'current2';
	Element.hide(item.parentNode.childNodes[2]);
	new Effect.BlindDown(item.parentNode.childNodes[2], {duration:0.34, afterFinish:doneSliding});
	return(false);
}

// Below is all of the javascript for the scrolling buttons in the footer

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Move Element Script

function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  if (!elem.style.marginLeft) {
    elem.style.marginLeft = "0px";
  }
  if (!elem.style.marginTop) {
    elem.style.marginTop = "0px";
  }
  var xpos = parseInt(elem.style.marginLeft);
  var ypos = parseInt(elem.style.marginTop);
  if (xpos == final_x && ypos == final_y) {
    return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.marginLeft = xpos + "px";
  elem.style.marginTop = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}

// Specific Javascript for the Sliding

function prepareSwitch() {
// Make sure the browser understands the DOM methods
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;

// Make sure the elements exist
  if (!document.getElementById("footerLinks")) return false;

// Create variable from footerLinks
  var list = document.getElementById("footerLinks");

// Get all the links in the ul
  var links = list.getElementsByTagName("a");


// Attach the animation behavior to the mouseover event

  links[0].onmouseover = function() {
    moveElement("linkA",0,-45,5);
  }
  

// Attach the animation behavior to mouseout events

	links[0].onmouseout = function() {
		moveElement("linkA",0,0,5);
	}

}

addLoadEvent(prepareSwitch);