//Rollovers
function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//Form Functions
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt (0) == "s")) {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}



function HighlightAll(theField) {
var copytoclip=1
var tempval=eval("document."+theField);
tempval.focus();
tempval.select();
if (document.all&&copytoclip==1&&tempval.createTextRange){
	therange=tempval.createTextRange()
if(therange.execCommand)
	therange.execCommand("Copy")
else
	return;
window.status="Code is highlighted and copied to clipboard."
setTimeout("window.status=''",1800)
}
}


//onLoad events
/*window.onload=function() {
	preload('/images/origami/nav/myname_over.gif','/images/origami/nav/blog_over.gif','/images/origami/nav/about_over.gif','/images/origami/nav/work_over.gif','/images/origami/nav/contact_over.gif');
}

window.onload = function() {
	placeFocus();
}*/

//Social Bookmarks
//HTML <div id="social"></div>
function $(v) { return(document.getElementById(v)); }
function social(title,url) {
	var r={'google_reader.png':'www.keithparent.com/rss.xml',
	'blinklist.png':'blinklist.com/index.php?Action=Blink/addblink.php&Url='+url+'&Title='+title,
	'delicious.png':'del.icio.us/post?v=4&noui&jump=close&url='+url+'&title='+title,
	'digg.png':'digg.com/submit?phase=2&url='+url+'&title='+title,
	'furl.gif':'furl.net/storeIt.jsp?t='+title+'&u='+url,
	'google.png':'google.com/bookmarks/mark?op=edit&output=popup&bkmk='+url+'&title='+title,
	/*'stumble.png':'stumbleupon.com/submit?url='+url+'&title='+title,*/
	'technorati.png':'technorati.com/faves?add='+url,
	'yahoo-myweb.png':'myweb.yahoo.com/myresults/bookmarklet?t='+title+'&u='+url+'&ei=UTF'},z='';
	
	for(var i in r) { z+='<a href="http://'+r[i]+'"><img src="/images/minicons/webservices/'+i+'" border="0" width="16" height="16" /></a>'; }
	return(z);//return(z.substr(2));
}
function socialBookmarks(){ 
	var thisURL = String(document.location);
	$('social').innerHTML=social('Blog [ Keith Parent',thisURL);
}

//Drag 'N' Drop
// style="position: relative; top: 0; left: 0" onmousedown="dragOBJ(this,event); return false;"
function $(v) { return(document.getElementById(v)); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }

function dragOBJ(d,e) {

function drag(e) { if(!stop) { d.style.top=(tX=xy(e,1)+oY-eY+'px'); d.style.left=(tY=xy(e)+oX-eX+'px'); } }

var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop;

document.onmousemove=drag; document.onmouseup=function(){ stop=1; document.onmousemove=''; document.onmouseup=''; };

}
//End D 'N' D

//Flickr Functions
zg_insert_badge = function() {
	var zg_bg_color = 'f3f1e9';
	var zgi_url = 'http://www.flickr.com/apps/badge/badge_iframe.gne?zg_bg_color='+zg_bg_color+'&amp;zg_person_id=56484646%40N00';
	document.write('<iframe style="background-color:#'+zg_bg_color+'; border-color:#'+zg_bg_color+'; border:none;" width="113" height="151" frameborder="0" scrolling="no" src="'+zgi_url+'" title="Flickr Badge"><\/iframe>');
	if (document.getElementById) {
		document.write('<div id="zg_whatlink"><a href="http://www.flickr.com/badge.gne" onclick="zg_toggleWhat(); return false;" title="Expand for more">[ + ] <em>Badges!?<\/em><\/a><\/div>');
	}
}

zg_toggleWhat = function() {
	document.getElementById('zg_whatdiv').style.display = (document.getElementById('zg_whatdiv').style.display != 'none') ? 'none' : 'block';
	document.getElementById('zg_whatlink').style.display = (document.getElementById('zg_whatdiv').style.display != 'none') ? 'none' : 'block';
	return false;
}

//Drag Element
//HTML: <div style="position: relative; top: 0; left: 0" onmousedown="dragOBJ(this,event); return false;">test</div>
function $(v) { return(document.getElementById(v)); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }

function dragOBJ(d,e) {

function drag(e) { if(!stop) { d.style.top=(tX=xy(e,1)+oY-eY+'px'); d.style.left=(tY=xy(e)+oX-eX+'px'); } }

var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop;

document.onmousemove=drag; document.onmouseup=function(){ stop=1; document.onmousemove=''; document.onmouseup=''; };

}