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; line-height:15px; top:0px; right:0px; font-family:Arial; color:#FFFFFF; background:#ed2224; width:50px; height:15px; cursor:pointer; padding:5px 0px; font-size:12px;'>close</div>"
function loadComplete()
{
	var c=0;
   	$('a').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.9);
	$('#'+popupProperty.id+' #shadowbox').css('top',0);
	$('#'+popupProperty.id+' #shadowbox').css('left',0);
	
	$('#'+popupProperty.id+' #popup_content').css({
												  'position':'absolute',
												  'background':'#FFFFFF',
												  'border':'5px #ed2224 solid',
												  'padding':'100px 50px',
												  'font-family':'Arial, Helvetica, sans-serif',
												  'font-size':'20px',
												  'line-height':'30px',												  
												  'overflow':'hidden',
												  'top':0,
												  'left':0,
												  '-moz-box-shadow':popupProperty.shadow,
												  '-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')]);
   
   $('#pageid').val($(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.height-H)/2);
 
 
   $('#'+popupProperty.id+' #popup_content').animate(initialProp,1);
  
  var popTop = (H-550)/2
  
   var targetProp = {
	                  width:wx,
					  height:Number(hx+30),
					  left:Number((W-wx)/2),
					  top:popTop
   					};
   

   $('#'+popupProperty.id+' #popup_content').animate(targetProp,1000,"easeOutExpo",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);
}


function openPopupOutside(tgtDiv)
{
   createPopup();
   W = $(window).width();
   H = $(window).height();
   content = $(tgtDiv).html();
   wx = $(tgtDiv).width();
   hx = $(tgtDiv).height();
   
   content = closeButton+"<div id='"+tgtDiv.split('#')[1]+"'>"+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.height-H)/2);
 
 
   $('#'+popupProperty.id+' #popup_content').animate(initialProp,1);
  
   var targetProp = {
	                  width:wx,
					  height:Number(hx+30),
					  left:Number((W-wx)/2),
					  top:20+$(window).scrollTop()
   					};
   

   $('#'+popupProperty.id+' #popup_content').animate(targetProp,1000,"easeOutBounce",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);
}

$(document).ready(loadComplete);
