var contents=[];
var popupProperty = new Object();
popupProperty.background = '#000000';
popupProperty.id='webguru_popup';
popupProperty.shadow = "2px 2px 10px #000000";
var authentic = "<div style='font-family:Arial; padding-top:10px; color:#333333; font-size:8px; width:100%;'></div>";
var closeButton="<div id='close_bt' style='position:absolute; text-align:center; bottom:0px; right:0px; padding:5px; font-family:Arial; color:#FFFFFF; background:#000000; width:50px; height:15px; cursor:pointer; opacity:0.6;'>close</div>"
function loadComplete()
{
	var c=0;
   	$('area').each(function(n){
						 
						    if($(this).attr('href').indexOf('webguru_popup@')!=-1)
							{						    
						       $(this).attr('rel',c)
							   contents[c] = ($(this).attr('href').split('webguru_popup@')[1]);
							   $(contents[c]).hide(1000);
							   $(this).bind('click',openPopup);
							   c++;
							}
						    
							
							});
	
	$(window).resize(popupResizing)
}



function applyStyle()
{
	dwx = $(window).width();
	dhx = $(document).height();
	
	
	
	$('#'+popupProperty.id).css('position','fixed');
	$('#'+popupProperty.id).css('top','0px');
	$('#'+popupProperty.id+' #shadowbox').css('position','absolute');
	$('#'+popupProperty.id+' #shadowbox').css('background',popupProperty.background);
	$('#'+popupProperty.id+' #shadowbox').css('width',dwx);
	$('#'+popupProperty.id+' #shadowbox').css('height',dhx);
	$('#'+popupProperty.id+' #shadowbox').css('opacity',0.7);
	$('#'+popupProperty.id+' #shadowbox').css('top',0);
	$('#'+popupProperty.id+' #shadowbox').css('left',0);
	
	$('#'+popupProperty.id+' #popup_content').css('position','absolute');
	$('#'+popupProperty.id+' #popup_content').css('background','#FFFFFF')
	$('#'+popupProperty.id+' #popup_content').css('border','15px #FFFFFF solid');
	$('#'+popupProperty.id+' #popup_content').css('overflow','hidden');
	$('#'+popupProperty.id+' #popup_content').css('top',0);
	$('#'+popupProperty.id+' #popup_content').css('left',0);
	$('#'+popupProperty.id+' #popup_content').css('-moz-box-shadow',popupProperty.shadow);
	$('#'+popupProperty.id+' #popup_content').css('-webkit-box-shadow',popupProperty.shadow);
	$('#'+popupProperty.id+' #popup_content').html("Loading...");
	
	
}

function createPopup()
{
   if($('#'+popupProperty.id).length)
   {$('#'+popupProperty.id).remove();}
   
   $('body').append('<div style="display:none;" id="'+popupProperty.id+'"><div id="shadowbox"></div><div id="popup_content"></div></div>');
   applyStyle();
	
	
}

function openPopup(e)
{
   //alert(contents[$(this).attr('rel')]);
   e.preventDefault();	
   createPopup();
   W = $(window).width();
   H = $(window).height();
   content = $(contents[$(this).attr('rel')]).html();
   wx = $(contents[$(this).attr('rel')]).width();
   hx = $(contents[$(this).attr('rel')]).height();
   
   content = closeButton+"<div id='"+contents[$(this).attr('rel')]+"'>"+content+"\n\n"+authentic+"</div>"
   //$('#'+popupProperty.id+' #popup_content').html(content)
  
  
 
  var initialProp = {
	  				 width:"10px",
					 height:"10px",
					 left:Math.ceil((W-10)/2)+'px',
					 top: Math.ceil((H-10)/2)+'px'
	  
  					};
  
  
  $('#'+popupProperty.id+' #popup_content').css('width',initialProp.width);
  $('#'+popupProperty.id+' #popup_content').css('height',initialProp.height);
  $('#'+popupProperty.id+' #popup_content').css('left',initialProp.left);
  $('#'+popupProperty.id+' #popup_content').css('top',initialProp.top);
 
 
   $('#'+popupProperty.id+' #popup_content').animate(initialProp,1);
  
   var targetProp = {
	                  width:wx,
					  height:Number(hx+30),
					  left:Number((W-wx)/2),
					  top:Number((H-hx)/2)
   					};
   

   $('#'+popupProperty.id+' #popup_content').animate(targetProp,1000,"easeOutQuad",function(){
																			 	$('#'+popupProperty.id+' #popup_content').html(content)
																				
																				$('#close_bt').bind('click',function(){
									   
									   													$('#'+popupProperty.id).hide();
									   
									   
									   											 })
																				
																				$('#shadowbox').css('height',$(document).height());
																				
																				});
   
   if((hx+30)>H)
   {
	   dhx = (hx+150);
	  $('#'+popupProperty.id).css('position','absolute'); 
	  $('#'+popupProperty.id+' #shadowbox').css('height',dhx);
   }
   
   
   $('#'+popupProperty.id).fadeIn(700);
}


function popupResizing()
{
  	if($('#'+popupProperty.id).length)
	{
	   W = $(window).width();
	   
	   dhx = $(document).height();
	   wx =  $('#'+popupProperty.id+' #popup_content').width();
	   $('#'+popupProperty.id+' #popup_content').css('left',(W-wx)/2);
	   $('#'+popupProperty.id+' #shadowbox').css('width',W);
	   $('#'+popupProperty.id+' #shadowbox').css('height',dhx);
	   
		
	}
}

function scrollPos()
{
   var topx = 20+$(window).scrollTop();
   $('#'+popupProperty.id+' #popup_content').css('top',topx);
}

$(document).ready(loadComplete);
