/*
OBLONGTECH JAVASCRIPT POPUP CODE VERSION3 UPDATED AUG2010
REQUIRES =>JQUERY 1.4.2 + OBLONGTECH-CORE-3
JQUERYUI REQUIRED FOR POPUP2
Edited By Dustin 201008261664
*/

function totalWidth(j){ return j.width()+parseInt(j.css('padding-left'),10)+parseInt(j.css('padding-right'),10); }
function totalHeight(j){ return j.height()+parseInt(j.css('padding-top'),10)+parseInt(j.css('padding-bottom'),10); }

/*######################################################################*/
/*CREATE ELEMENT HIGHLIGHTER*/
function targeter(e){
 jQuery('#target-label,#target-top,#target-left,#target-bottom,#target-right').remove();
 d = 2;
 
 j = jQuery(e);
 w = j.width()+parseInt(j.css('padding-left'),10)+parseInt(j.css('padding-right'),10);
 h = j.height()+parseInt(j.css('padding-top'),10)+parseInt(j.css('padding-bottom'),10);
 offset = j.offset(); x = offset.left; y = offset.top;
 
 jQuery('body').append('<div id="target-label">&nbsp;EDIT&nbsp;</div><div id="target-top"></div><div id="target-right"></div><div id="target-bottom"></div><div id="target-left"></div>');
 
 jQuery('#target-top,#target-bottom').css({'width':w+2*d+'px','height':d+'px','top':y-d+'px','left':x-d+'px'});
 jQuery('#target-right,#target-left').css({'width':d+'px','height':h+2*d+'px','top':y-d+'px','left':x-d+'px'});
 jQuery('#target-right').css({'left':x+w+'px'});
 jQuery('#target-bottom').css({'top':y+h+'px'});
 jQuery('#target-label').css({'top':y+'px','left':(x+w-totalWidth(jQuery('#target-label')))+'px'}).bind('click',function(){
		data = jQuery(jQuery(this).data('linked_elem')).data();
		jQuery.get(data['cms_url'],data['send_data'],function(data){
			remove_targeter();
			popup1(
			'<a id=\'popup-close\' onclick=\'popup1_close();\' title=\'Click here to cancel changes and close this popup.\'></a>'
			+data);
  });
  
  }).data('linked_elem',e);
  
jQuery(document).bind('mouseover',{
 j:jQuery('.spotlight')//JQUERY ELEMS
,x:jQuery('#target-label').get()//EXCLUDE ARRAY
,a:function(event,elem){//ACTION

 var link = jQuery('#target-label').data('linked_elem');
 if(link==elem){ remove_targeter(); }

 }},mass_level_event);

 }
 
function remove_targeter(){
 jQuery(document).unbind('mouseover',mass_level_event);
 jQuery('#target-label,#target-top,#target-left,#target-bottom,#target-right').remove();
 }
function mass_level_event(event){
 event.data.j.each(function(i){
  for(var i=0;i<event.data.x.length;i++){ if(jQuery.contains(event.data.x[i],event.target)||event.data.x[i]==event.target){ cancel = true; } }
  if(!jQuery.contains(this,event.target)&&this!=event.target){ event.data.a(event,this); }
  //else{ event.stopPropagation(); }
  });
 }

/*######################################################################*/
/*POPUP - FIXED CENTER*/
function popup_ajax(file,width,onComplete){
 popup_html('<div style="text-align:center;padding:50px 0px 80px;"><img src="gfx/loading.gif" /></div>',width);
 jQuery('#popup-inner').load(file,'',onComplete);
 }

function popup_html(content,width){
 var width = (typeof(width)=='undefined' ? 605 : width ); 
 if(typeof(content)=='string'){innerhtml=content;}else if(isElement(content)){innerhtml=content.innerHTML;}
 
 if(jQuery('#popup').size()>0)jQuery('#popup').remove();//ALLOW ONLY ONE POPUP AT A TIME
 
 html = ''
 +'<div id="popup" class="popup"><div class="popup-bgnd"></div><table class="popup-table"><tr><td>'
 +'<div id="popup-inner" style="width:'+width+'px;">'
 +innerhtml
 +'</div></td></tr></table></div>';
 jQuery(document.body).prepend(html);
 
 if(jQuery.browser.msie&&jQuery.browser.version.substr(0,1)<7)jQuery(window).bind('scroll',ie6_popup_onscroll);
 }

function popup_close(){ jQuery('#popup').remove(); }

function ie6_popup_onscroll(event){
 if(jQuery('#popup').size()<1){jQuery(window).unbind('scroll',ie6_popup_onscroll);}
 else{document.getElementById('popup').style.top = document.body.parentElement.scrollTop;}
 }

/*######################################################################*/
/*NEW! POPUP1 - FIT VERT/HORIZ CENTER*/
function popup1(content,width){
 var width = (typeof(width)=='undefined' ? 590 : width ); 
 if(typeof(content)=='string'){innerhtml=content;}else if(isElement(content)){innerhtml=content.innerHTML;}
 
 if(jQuery('#popup1').size()>0)jQuery('#popup1').remove();//ALLOW ONLY ONE POPUP AT A TIME
 height = jQuery(document).height();
 
 html = ''
 +'<div id="popup1" class="popup1" style="height:'+height+'px;"><div class="popup-bgnd"></div>'
 +'<div id="popup1-inner" style="width:'+width+'px;visibility:hidden;top:'+jQuery(window).scrollTop()+'px;"><div class="popup2-bgnd"></div>'
 +innerhtml
 +'</div></div>';
 jQuery(document.body).append(html);
 jQuery('#popup1-inner').css({'visibility':'visible'});
 jQuery(window).bind('resize',popup1_resize);
 jQuery(window).bind('scroll',popup1_scroll);
 //FOLLOWING TOP CALC FAILS IN IE (NOT IMPLEMENTED)
 var top = ( totalHeight(jQuery('#popup1-inner')) < jQuery(window).height() ? jQuery(window).scrollTop()+jQuery(window).height()/2-totalHeight(jQuery('#popup1-inner'))/2 : jQuery(window).scrollTop() );
 jQuery('#popup1-inner').css({'top':top+'px'});
 }
function popup1_close(){ jQuery('#popup1').remove(); }
function popup1_resize(event){ jQuery('#popup1').css({'height':100+'%'}).css({'height':jQuery(document).height()+'px'}); }
function popup1_scroll(event){ jQuery('#popup1').css({'height':100+'%'}).css({'height':jQuery(document).height()+'px'}); }

/*######################################################################*/
/*POPUP2 - MULTIPLE DRAGGABLE RESIZABLE - REQUIRES JQUERYUI*/
function open_popup2(html,id){
 if(jQuery('#popup2').size()<1){
  jQuery('body').prepend('<div id="popup2"><div class="popup-bgnd"></div><div href="javscript:;" title="Click to close all popups" id="popup2-close" onclick="jQuery(\'#popup2\').css({\'display\':\'none\'})"></div></div>');
  if(jQuery.browser.msie && jQuery.browser.version.substr(0,1)<7){ jQuery(window).unbind('scroll',ie6_popup2_onscroll);}
  }
 if(jQuery('#popup2>#'+id).size()>0){
  jQuery('#'+id+'>*:not(.popup-close,.popup2-drag-handle,.popup2-bgnd,.ui-resizable-handle)').remove();
  jQuery('#'+id).append(html).trigger('mousedown',[jQuery('#'+id).get(0)]);
  }
 else{
 jQuery('#popup2').append(
 '<div id="'+id+'" class="popup2">'
 +'<div class="popup2-bgnd"></div>'
 +'<a href="javascript:;" title="Click here and drag mouse to move this popup, release click to drop." class="popup2-drag-handle"></a>'
 +'<a href="javascript:;" onclick="close_popup2(\''+id+'\');" title="Click here to close this popup." class="popup-close"></a>'
 +'</div>'
 );
 jQuery('#'+id).eq(0)//.load('admin/images.php')
 .draggable({ scroll:false, snap:false, snapMode:'outer', snapTolerance:40, containment:'document', handle:'.popup2-drag-handle',
  start:function(event,ui){ jQuery('.popup2-bgnd',ui.helper).css({'z-index':10}); },
  stop:function(event,ui){ jQuery('.popup2-bgnd',ui.helper).css({'z-index':-1}); },
  drag:function(event,ui){
   if(ui.position.left>=jQuery(window).width()-ui.helper.width()-12){
    ui.position.left = jQuery(window).width()-ui.helper.width()-12;
    };
   if(ui.position.left<=12){
    ui.position.left = 12;
    if(ui.position.left+ui.helper.width()>=jQuery(window).width()-12){
     ui.helper.width(jQuery(window).width()-ui.position.left-12);
     };    
    }
   if(ui.position.top>=jQuery(window).height()-totalHeight(ui.helper)-12){
    ui.position.top = jQuery(window).height()-ui.helper.height()-totalHeight(ui.helper)+ui.helper.height()-12;
    };
   if(ui.position.top<=12){
    ui.position.top = 12;
    if(ui.position.top+totalHeight(ui.helper)>=jQuery(window).height()-12){
     ui.helper.height(jQuery(window).height()-ui.position.top-totalHeight(ui.helper)+ui.helper.height()-12);
     //RESIZE RTE
     jQuery('.mceIframeContainer iframe',ui.helper).css({'height':0});
     jQuery('.mceIframeContainer iframe',ui.helper).css({'height':parseInt(ui.helper.height())-parseInt(jQuery('form.item',ui.helper).height())});
     };
    }
   }
  })
  .resizable({ containment:'document', minWidth:300, minHeight:200,
   start:function(event,ui){ jQuery('.draggable-bgnd',ui.helper).css({'z-index':10}); },
   stop:function(event,ui){ jQuery('.draggable-bgnd',ui.helper).css({'z-index':-1}); },
   resize:function(event,ui){
    if(ui.position.left+ui.helper.width()>=jQuery(window).width()-12){
     ui.helper.width(jQuery(window).width()-ui.position.left-12);
     };
    if(ui.position.top+totalHeight(ui.helper)>=jQuery(window).height()-12){
     ui.helper.height(jQuery(window).height()-ui.position.top-totalHeight(ui.helper)+ui.helper.height()-12);
     };
    //RESIZE RTE
    jQuery('.mceIframeContainer iframe',ui.helper).css({'height':0});
    jQuery('.mceIframeContainer iframe',ui.helper).css({'height':parseInt(ui.helper.height())-parseInt(jQuery('form.item',ui.helper).height())});
    }
   })
  .append(html)
  .bind('mousedown',function(event,t){
   event = ( window.event || event );
   var target = ( t || event.target || event.srcElement );
			jQuery('.popup2').each(function(i){
			 if(this==target||jQuery.contains(this,target)){
     jQuery('.popup2-bgnd',this).css({'z-index':-1});
     jQuery(this).removeClass('popup2-unselected');
     if(jQuery('.popup2').index(jQuery(this))<jQuery('.popup2').size()-1)jQuery('#popup2').append(jQuery(this));
     }
    else{
     jQuery('.popup2-bgnd',this).css({'z-index':10});
     jQuery(this).addClass('popup2-unselected');
     }
				});
   }).trigger('mousedown',[jQuery('#'+id).get(0)])
  ;
  }
 }

function close_popup2(id){
 jQuery('#'+id).remove();
 jQuery('#popup2>.popup2').eq(jQuery('#popup2>.popup2').size()-1).removeClass('popup2-unselected');
 if(jQuery('#popup2>.popup2').size()<1) jQuery('#popup2').remove();
 }

function ie6_popup2_onscroll(event){
 if(jQuery('.popup2').size()<1){jQuery(window).unbind('scroll',ie6_popup2_onscroll);}
 else{document.getElementById('popup2').style.top = document.body.parentElement.scrollTop;}
 }


/*######################################################################*/
/*POPUP FLV PLAYER*/

function popupflv(src){
 
 var w = 600; var h = 400;
 
 popup1('<div id=\'popup-close\' onclick=\'popup1_close();\'></div><div id="popup-flv-player" style="width:'+w+'px;height:'+h+'px;"><a href="http://get.adobe.com/flashplayer/" style="background:transparent url(\'gfx/flash-required.gif\') no-repeat center center scroll;width:100%;height:100%;display:block;"></a></div>',w);
 jQuery('#popup1-inner').css({'background-color':'#000000','border':'1px solid #555555'});

 var flashvars = {};
 flashvars.videoPath = src;
 flashvars.imagePath = src+".jpg";
 flashvars.stageW = w;
 flashvars.stageH = h;
 
 flashvars.autoStart = "true";
 flashvars.autoHide = "true";
 flashvars.autoHideTime = "3";
 flashvars.hideLogo = "false";
 flashvars.volAudio = "100";
 flashvars.disableMiddleButton = "false";
 flashvars.playSounds = "false";
 
 flashvars.soundBarColor = "0x666666";
 flashvars.barColor = "0x666666";
 flashvars.barShadowColor = "0xaaaaaa";
 flashvars.subbarColor = "0xffffff";
 
 flashvars.extendVideo = "true";

 var params = {};
 params.bgcolor = "#000000";
 //params.wmode = "transparent";
 params.allowFullScreen = "true";
 //params.allowScriptAccess = "sameDomain";
 
 var attributes = {};

 swfobject.embedSWF("flvPlayer.swf", "popup-flv-player", w, h, "9.0.0", "", flashvars, params, attributes);
 }


