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

function roll_over(img_name, src) {
   document[img_name].src = src;
}

function change_title(title) {
	document.getElementById('tag_line').innerHTML = "<span>" + title + "</span>"
}

function change_title_back() {
	document.getElementById('tag_line').innerHTML = "SEVEN THINGS YOU CAN DO TO LEAD A GREENER LIFE"
}

function hide_everything() {
	$('intro-text').hide();
	$('walk-the-walk-circle').hide(); 
	$('walk-the-walk-text').hide();
	$('stick-with-what-you-got-circle').hide(); 
	$('stick-with-what-you-got-text').hide();
	$('easy-on-the-meat-circle').hide(); 
	$('easy-on-the-meat-text').hide();
	$('plug-out-circle').hide(); 
	$('plug-out-text').hide();
	$('stay-grounded-circle').hide(); 
	$('stay-grounded-text').hide();
	$('all-consuming-circle').hide(); 
	$('all-consuming-text').hide();
	$('human-heat-circle').hide(); 
	$('human-heat-text').hide()
}

function sort_sliders_out(show) {
	$$('.sub_slider').each(function(item) {
	  item.hide();
	});
	$("sub_action_sliders_" + show).show();
	$$("#header_" + show).each(function(item) {
	  item.scrollTo();
	});
}

function mobile() {
	window.location="http://www.dothegreenthing.mobi"
}

// New story page

function show_class(id_name, link) {
	//["media", "title", "tags"].each(function(c) {
	//	$(c).hide();
	//});
	$('media').hide();
	$('titles').hide();
	$('tags').hide();
	$('titles_link').innerHTML = "<img src='/images/new_story_icons/titles-off.gif' class='off'>";
	$('media_link').innerHTML = "<img src='/images/new_story_icons/media-off.gif' class='off'>";
	$('tags_link').innerHTML = "<img src='/images/new_story_icons/tags-off.gif' class='off'>";
	
	$(link).innerHTML = "<img src='/images/new_story_icons/" + id_name + "-on.gif' class='on'>";
	$(id_name).toggle();
}

// Used in the drop down to send the user to the adress
// that is specified in the drop down

function redirect_user() {
	var options_index = document.getElementById('useful_links_dropdown').selectedIndex; 
	if (options_index > 0) {
		var link_name = document.getElementById('useful_links_dropdown').options[options_index].innerHTML
		
		if (link_name == "New Blog Post") {
			document.location = document.getElementById('useful_links_dropdown').options[options_index].value; 
		} else {
			window.open(document.getElementById('useful_links_dropdown').options[options_index].value);
		}
	} 
}

// For /spotify/kate
// If theres an error we want to move the user down the page to the actual
// form

function show_user_the_form() {
  var error_message = document.getElementById('errorExplanation')
  if (error_message) {
    window.location.hash = "signup"; 
  }
}

// shop/glove_lover

function check_glove_love_form(form) {
  if (form.name.value.blank()) {
    alert('We need your name');
    return false;
  } else if (form.story_file.value.blank()) {
    alert('You need to give us an image.');
    return false;
  }
  return true;
}