function addLabel(el,el_label){
  if(el.value==''){
    el.value=el_label;
    el.style.color="#777777";
  }
}
function removeLabel(el,el_label){
  if(el.value==el_label){
    el.value='';
    el.style.color="#000000";
  }
}

function show_hide(x,y){
	$("#"+x).hide();
	$("#"+y).show();
}

jQuery.preloadImages = function(){
  for(var i = 0; i<arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }
}

function prepareGallery(){
	var gallery = document.getElementById("menu");
	var links = gallery.getElementsByTagName("a");
	for( i=0; i<links.length; i++){
		links[i].onclick = function() {
			nav(this.id);
			return false;
		}
	}
}

function nav(id){
	var navigation = document.getElementById("menu");
	var newID = $("span.nonlink").attr("id");
	var name = $("span.nonlink").attr("title");
	$("span.nonlink").replaceWith("<a id='"+newID+"' href='#'>"+name+"</a>");
	//$("a").remove("#"+id);
	$("a#"+id).replaceWith("<span class='nonlink' id='"+id+"''>"+id+"</span>");
	prepareGallery();
}

function showpic(url,id) {
	var source = url;
	var size = getImgSize(source);
	var placeholder = document.getElementById("placeholder");
	var old = placeholder.getAttribute("src",source);
	if(size == 'width'){
		placeholder.setAttribute("width","466");
	}else if(size == 'height'){
		placeholder.setAttribute("height","448");
	} else {
		placeholder.setAttribute("height"," ");
		placeholder.setAttribute("width"," ");
	}
	placeholder.setAttribute("src",source);
	//var text = whichPic.getAttribute("title");
	//var description = document.getElementById("description");
	//description.firstChild.nodeValue = text;
	//photo_nav(id,old); // call the new nav function
}



function getImgSize(imgSrc){
	var newImg = new Image();
	newImg.src = imgSrc;
	var height = newImg.height;
	var width = newImg.width;
	if(height > 448)
	{
		return 'height';
	}
	if(width > 466)
	{
		return 'width';
	}
}

function show_edit(val){
	$("#"+val).addClass("on");
	$("#"+val).removeClass("off");
}
function hide_edit(val){
	$("#"+val).addClass("off");
	$("#"+val).removeClass("on");
}
//Confirmation
function areYouSure(page) {
  var warning='This action cannot be undone.\nClick cancel if you are unsure, or click OK to delete.';
  if ( confirm(warning) == true ) window.location=page;
  else return false();
}

function tooltip(id,newLayout) {
	var oldLayout = $("#tooltip").html();
	$("#tooltip").html(newLayout);
	$("#"+id).mouseout(function(){
		$("#tooltip").html(oldLayout);
	});
}

function close_flash(id) {
	$.ajax({
		type:"POST",
		url: '/users/hide_notice',
		data: 'user_id='+id,
		dataType: "html",
		success: function(responseText){
			$(".first-time").toggle();
		}
	});	
}

function update_status(status,id) {
	$.ajax({
		type:"POST",
		url: '/articles/update_status',
		data: 'id='+id+'&status='+status,
		dataType: "html",
		success: function(responseText){
			$("#flash").html('<span id="notice" style="background:#ffffcc;padding:3px;">Status Updated!!</span>');

			setTimeout('$(\'#notice\').fadeOut(\'slow\')',5000);
		}
	});
}