// generic JS fixes

// various JavaScript object.
var Blueprint = {};

// jump to the value in a select drop down
Blueprint.go = function(e) {
  var destination = e.options[e.selectedIndex].value;
  if (destination && destination != 0) location.href = destination;
};

// prevent users from clicking a submit button twice
Blueprint.formCheck = function() {
  // only apply this to node and comment and new user registration forms
  var forms = $("#node-form>div>div>#edit-submit,#comment-form>div>#edit-submit,#user-register>div>#edit-submit");

  // insert the saving div now to cache it for better performance and to show the loading image
  $('<div id="saving"><p class="saving">Saving&hellip;</p></div>').insertAfter(forms);

  forms.click(function() {
    $(this).siblings("input[@type=submit]").hide();
    $(this).hide();
    $("#saving").show();

    var notice = function() {
      $('<p id="saving-notice">Not saving? Wait a few seconds, reload this page, and try again. Every now and then the internet hiccups too :-)</p>').appendTo("#saving").fadeIn();
    };

    // append notice if form saving isn't work, perhaps a timeout issue
    setTimeout(notice, 24000);
  });
};

// Global Killswitch.
if (Drupal.jsEnabled) {
  $(document).ready(Blueprint.formCheck);
}

$("html.anon #header .block-menu ul li").removeClass("leaf");
$("html.anon #header .block-menu ul li a").text("");
$("html.anon #header .block-menu ul li.first").after("<li class='sep'></li>");
$("html.anon #header .block-menu ul li.first").next().next().addClass("mid");
$("html.anon #header .block-menu ul li.mid").after("<li class='sep'></li>");
$("html.anon #header .block-menu ul li.last a").attr("target", "_blank");

var register_button = $("#user-login a.register");
$("html.anon #edit-submit").next("p").before(register_button);

$("div.slider").find("a").each(function(i, item){
		var href = $(item).attr("href");
		var el = $(item).children();
		var element = $(el).attr("link", href);
		$("div.auxslider").hide();
		$("div.auxslider").append(element);
});

$("div.slider").html("");
$("div.slider").append("<div class=sliderContent></div>");
$("div.sliderContent").html($("div.auxslider").html());
//$("div.sliderContent").append($("div.auxslider").html()); //repe

$("html.anon div.editorpick").appendTo("div.slider");

$("div.sliderContent img").click(function(){
	var href = $(this).attr("link");
	document.location = href;
	
});

$("<div id=slidecontrol></div>").insertAfter("div.slider");

var numItems = $("div.sliderContent img");

$("div.sliderContent").css("width", numItems.length * parseInt(numItems.css("width")));  

$("#slidecontrol").slider({
    animate: true,
	max: (numItems.length * parseInt(numItems.css("width"))) - parseInt($("div.slider").css("width")), 
	slide: function(e, ui){
		var ui_v =  ui.value * -1;
		$("div.sliderContent").css("left", ui_v + "px");
	}
});