var base = document.getElementsByTagName("base");

$(function() {
	
	$(".buttons").click(function () {
		var divname= this.value;
		$("#"+divname).show("slow").siblings().hide("slow");
	});	
	
	$(".sub_menu").mouseover(function() {
		var src = $(this).attr('src').replace('_off','_on');
		$(this).attr('src',src);
	}); 
	$(".sub_menu").mouseleave(function() {
		var src = $(this).attr('src').replace('_on','_off');
		$(this).attr('src',src);
	}); 
	
	$(".nav").mouseover(function() {
		var src = $(this).attr('src').replace('.png','_over.png');
		src = src.replace('.jpg','_over.jpg');
		$(this).attr('src',src);
	}); 
	$(".nav").mouseleave(function() {
		var src = $(this).attr('src').replace('_over.png','.png');
		src = src.replace('_over.jpg','.jpg');
		$(this).attr('src',src);
	}); 
	
	/* Do not allow continuing without selecting an apron */
	$("#submitItem").click(function() {
		var apron1 = $("#apron1").val();
		var apron2 = $("#apron2").val();
		
		if(apron1=="")
		{
			$("#apron1").focus();
			alert('Please select your matching apron and cap');
			return false;
		}
		
		if(apron2!=null && apron2=="")
		{
			$("#apron2").focus();
			alert('Please select your second matching apron and cap');
			return false;
		}
	});
	
	
	/* Hide all articles... unobtrusively */
	$(".toggledArticle").hide();
	
	/* Toggle article visibility */
	$(".toggleArticle").click(function() {
		var id = $(this).attr('id').substring(7);
		$("#article_"+id).toggle();
	});	
	
});


function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
		'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(mypage,myname,settings);
	win.focus();
}

function Toggle_SetVisibility(linkId, imageId, panelId, visibility, openText, closeText, openImageUrl, closeImageUrl) {
  var lnk = document.getElementById(linkId);
  var img = document.getElementById(imageId);
  var pnl = document.getElementById(panelId);
  if (img != null){
    if (pnl.style.display == 'none'){
      img.src = closeImageUrl ;
      img.alt = closeText;
      pnl.style.display = visibility;
    }
    else {
      pnl.style.display = 'none';
      img.src = openImageUrl ;
      img.alt = openText;
    }
  }
  else {
    if (pnl.style.display == 'none'){
      pnl.style.display = visibility;
      var txt = document.createTextNode(closeText);
      lnk.childNodes[0].nodeValue = closeText;
    }
    else {
      pnl.style.display = 'none';
      var txt = document.createTextNode(openText);
      lnk.childNodes[0].nodeValue = openText;
    }
  }
}