// JavaScript Document

var stopEvent = function(e){ 
		if (e.stopPropagation){ e.stopPropagation(); e.preventDefault(); } 
		else { e.returnValue = false; e.cancelBubble = true; } 
		return false; 
	}



function makeModal(){
	
	
	
}


function showModal(e,targ){
	//alert(e);
	//console.log(e);
	
	var modalwindow;
	
	if($('modalShell')){
		modalwindow = $('modalShell');
		//console.log(modalwindow);
	}else{
		modalwindow=new Element("div");
		modalwindow.injectInside($E('body'));
		modalwindow.setProperty('id','modalShell');
		modalwindow.addClass('modal');
		//console.log(modalwindow);
	}
	
	var modalConents = new Element('div').setProperty('id', 'mb_contents').injectInside(modalwindow);
	
	modalwindow.top = Window.getScrollTop() + (Window.getHeight() / 15);
	modalwindow.setStyles({top: modalwindow.top+'px'});
	modalwindow.setStyles({opacity:"0.9",left:e.clientX+"px",top:e.clientY-20+"px", marginLeft: '-150px'});
	
	
	/*
	var targ;
	if(window.event){
		targ=e.srcElement;
	}else{
		targ=e.target;
	}
	*/
	//alert(targ.getAttribute('rel'));
	modalConents.setHTML($(targ.rel).innerHTML);
	modalwindow.addEvent('click',function(e){$ES('#modalShell').remove();stopEvent(e);});
	stopEvent(e);

	}



function showModal2(targ){
	
	
}



function init(){
	//console.log($('bio').getElements('.mlink'));
	//alert($('bio').getElements('.mlink'));
	/*
	for(var i=0;i<$('bio').getElements('.mlink').length;i++){
		//console.log($ES('a')	[i]);
		//if($('bio').getElements('.mlink')[i].rel=="modal"){
			//.getElements('.mlink')[i]);
			$('bio').getElements('.mlink')[i].addEvent('click',showModal);
		//}
	}
	
	$('testlink').addEvent('click',showModal);
	*/
	var anchors = document.getElementsByTagName('a');

		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			//alert(anchor.attributes['class']);
			var relAttribute = String(anchor.getAttribute('class'));
			
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if ((relAttribute.toLowerCase().match('mlink'))){
				//anchor.onclick = function () {myLightbox.start(this); return false;}
				
				anchor.onclick=function(e){showModal(e,this)};
			}
		}
	
	//$('testlink').addEvent('click',showModal);
	
		
}


//window.addEvent('load',init);