function debug(msg, obj) {
  if (true) {
    var dbg = document.getElementById("myDebugArea");
    
    //create the debug container if needed
    if (!dbg) { //create the debug container if needed
      dbg = document.createElement("div");
      dbg.id = "myDebugArea";
      document.body.appendChild(dbg);
      t = document.createElement("h2");
      t.appendChild(document.createTextNode("DEBUG"));
      dbg.appendChild(t);
    }
                
    //add the message to the debug container
    dbg.appendChild(document.createTextNode(msg));
    dbg.appendChild(document.createElement("br"));
                
    if (obj) {
      var txt = "***** Object Dump *****";
      dbg.appendChild(document.createTextNode(txt));
      dbg.appendChild(document.createElement("br"));
                
      for (prop in obj) {
        var txt = prop + ": " + obj[prop];
        dbg.appendChild(document.createTextNode(txt));
        dbg.appendChild(document.createElement("br"));
      }

      var txt = "***********************";
      dbg.appendChild(document.createTextNode(txt));
      dbg.appendChild(document.createElement("br"));
    }
  }
}//*/
swap_val = [];
$(document).ready(function(){
	//projectSlideStart();
	for(var i=1; i<6; i++){
		$('#menu'+i).removeClass("item");
	}
	$(".swap").each(function(i){
		swap_val[i] = $(this).val();
		$(this).focusin(function(){
			if ($(this).val() == swap_val[i]) {
				$(this).val("");
			}
		}).focusout(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(swap_val[i]);
			}
		});
	});
	HideAll();
	CheckUrlHash();
});

function CheckUrlHash(){
	var url = unescape(self.document.location.hash.substring(1));
	var num = url.lastIndexOf('/')+1;
	if(1<num){
		url = url.substring(num);
		ShowContent(url);
	}
}

function Sendmail(){
	var oldhtml = $("#sendmail").html();
	$("#sendmail").html('<div style="margin-top:5px;"><img src="img/ajaxloadb.gif"/> <i>Loading</i></div>');

	//console.log('DADA');
	var Email = $('input[name="email"]').val();
	var Msg = $('textarea[name="msg"]').val();

	//Send the mail
	$.post("sendmail.php", { "email":Email, "msg":Msg},
	 function(){},"json").success(function(data){//Success!
		//console.log('STATUS: '+data.status);
		if(data.status==1){
			$("#sendmail").html('<div style="margin-top:5px;"><i>Success!</i></div>');
		}else{
			Sendmail_msg(oldhtml,'Wrong Email!');
		}
	}).error(function(){//failed generic error
		Sendmail_msg(oldhtml,'Error!');
	});
}
function Sendmail_msg(oldhtml,msg){
	$("#sendmail").html('<div style="margin-top:5px;"><i>'+msg+'</i></div>');
	//reset button
	setTimeout(function(){$("#sendmail").html(oldhtml);},1500);
}

function Login(){
		var oldhtml = $("#login").html();
		$("#login").html('<div style="margin-top:5px;"><img src="img/ajaxloadw.gif"/> <i>Loading</i></div>');
		setTimeout(function(){
			var status = 2;
			
			switch(status){
			case 1://success!
				//send to proper website here
				$("#login").html('<div style="margin-top:5px;"><i>Success!</i></div>');
				break;
			case 2://failed generic error
				$("#login").html('<div style="margin-top:5px;"><i>Failed!</i></div>');
				break;
			case 3://failed invalid username or password
				$("#login").html('<div style="margin-top:5px;"><i>User/pw wrong!</i></div>');
				break;
			case 4://failed account lockout
				$("#login").html('<div style="margin-top:5px;"><i>Lockout!</i></div>');
				break;
			};
			if(status!=1){
				setTimeout(function(){
					$("#login").html(oldhtml);
				},1500);
			}
		},1500);
}
/*
var projectSlideID;
var pSlideSpeedRight = 8;
var pSlideSpeedLeft = 1;
function projectSlideStart(){
	projectSlideID = setInterval(projectSlide, (pSlideSpeedRight + pSlideSpeedLeft) * $("#projects").attr("scrollWidth"));
	projectSlide();
}
function projectSlideStop(){
	clearInterval(projectSlideID);
}
function projectSlide(){
	var myDiv = $("#projects");
	myDiv.animate({ scrollLeft: myDiv.attr("scrollWidth") - myDiv.width() }, pSlideSpeedRight * myDiv.attr("scrollWidth")).animate({ scrollLeft: 0 }, pSlideSpeedLeft * myDiv.attr("scrollWidth"));
	//clearInterval(projectSlideID);
}*/
function HideAll(){
	for(var i=1; i<6; i++){
		$("#menu"+i+" .mcontent").hide();
	}
}
var lastid = null;
function ShowContent(numid){
	var id = $('#menu'+numid);
	var name = $(id).find('h2').find('i').html();
	window.location.hash ="#"+name.replace(' ','_').replace('/','_')+"/"+numid;

	if($(id).find(".mcontent").is(":hidden")){
		//HideAll();
		if(lastid!=null){$(lastid).find(".mcontent").slideUp();}
		$(id).find(".mcontent").slideDown();
		lastid = id;
	}else{
		$(id).find(".mcontent").slideUp();
	}
}
