/*
 * MonkCMS stuff
 */

function gotoSermon2() {
  var x=document.getElementById("sermonLists");
  var go=x.options[x.selectedIndex].value;

  window.location=go;
}

function gotoContent(x) {
  var go=x.options[x.selectedIndex].value;

  window.location=go;
}

function wimpyPopPlayer(theFile,id,stuff) {
  window.open(theFile,id,stuff);
}

/*
 * Wrote this wrapper to stay compatible / eT Oct 2008
 */
function waspPopup (filename, width, height){

  window.open('http://my.ekklesia360.com/Clients/waspPopup.php?theFile='+filename+'&w='+width+'&h='+height,'_mediaplayer','width='+width+',height='+height);

}

function doJSEvents() {
  if (!document.getElementsByTagName) return false;

  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("mcmsSearch")) {
      links[i].onclick = function() {
        document.getElementById('searchForm').submit();
        return false;
      }
    }
    if (links[i].className.match("mcmsSearch2")) {
      links[i].onclick = function() {
        document.getElementById('searchForm2').submit();
        return false;
      }
    }
    if (links[i].className.match("thickbox")) {
      links[i].onmouseover = function() {
        window.status='';
		return true;
      }
    }
  }
  var inputs = document.getElementsByTagName("input");
  for (var i=0; i < inputs.length; i++) {
    if (inputs[i].className.match("clearClick")) {
      inputs[i].onfocus = function() {
        if (document.getElementById('search_term')) document.getElementById('search_term').value='';
        if (document.getElementById('search_term2')) document.getElementById('search_term2').value='';
        if (document.getElementById('newsletter_text')) document.getElementById('newsletter_text').value='';
        return false;
      }
    }
  }
}
window.onload=doJSEvents;

function changeFieldValue(fieldName,fieldValue) {
  document.getElementById(fieldName).value=fieldValue;
}

function monkIsValidEmail(emailAddress) {
  atPos=emailAddress.indexOf("@");
  dotPos = emailAddress.indexOf(".", atPos);
  spacePos = emailAddress.indexOf(" ");
  if ((emailAddress.length > 0) && (atPos > 0) && (dotPos > atPos) && (spacePos == -1)) {
    return true;
  }
  alert("Please enter a valid email address.");
  return false;
}

/*
   Monk Media Popup v.1 - a script to open window with videoplayer
   (c) 2010 Adam Randlett : monkdevelopment.com
*/  

(function($){
 $.fn.monkmediapopup = function(settings){ 
 // "this" is the jQuery object $this.text('0'); / 
 var defaults = {
    file:"href",
    image:"",
    width:"400",
    height:"300",
    playlist:"false",
    template:"http://monkcms.bodeutsch.com/Clients/player/videoplayer.php",
    previewimage:"",
    autostart:"true",
    fullscreen:"true",
    controlbar:"bottom",
    stretching:"uniform",
    bufferlength:"1",
    smoothing:"true",
    volume:"90",
    type:"video",
    screencolor:"#000000", 
    backcolor:"#000000",
    frontcolor:"#ffffff",
    skin:"http://monkcms.bodeutsch.com/Clients/player/default.swf"
 }

 var options = $.extend(defaults, settings); 
 return this.each(function(){ 
     var $this = $(this); 
     var playeroptions ={
       file:$this.attr(options.file),
       image:"",
       width:options.width,
       height:options.height,
       playlist:options.playlist,
       autostart:options.autostart,
       fullscreen:options.fullscreen,
       controlbar:options.controlbar,
       stretching:options.stretching,
       type:options.type,
       volume:options.volume, 
       screencolor:options.screencolor,
       bufferlength:options.bufferlength,
       smoothing:options.smoothing,
       backcolor:options.backcolor,
       frontcolor:options.frontcolor,
       skin:options.skin

     } 

     if(options.image.indexOf('.') !=-1){
       playeroptions.image = options.image;
     }else{
       playeroptions.image = $this.attr(options.image); 
     }

     var globalwidth;
     var pheight =  Number(options.height) + 24;
     var globalheight = String(pheight);

     if(options.playlist =="true"){
       var pwidth = 240;
       var width = Number(options.width) + pwidth;
       globalwidth = String(width); 
     }else{
       globalwidth = options.width;
     }

     //if object is not anchor and has anchor as child disable anchor
     if($this.find("a").length > 0){
       $this.find("a").click(function(e){e.preventDefault(); return false; });
     }

     //$this.data({video: $this.attr(options.attribute)});
     $this.click(function(e){ 
         var attr = $.param(playeroptions);
         var url = options.template +"/?"+attr+"&target=MediaPlayer";
         window.open(url,"MediaPlayer","menubar=no,resizable=no,width="+globalwidth+",height="+globalheight+",scrollbars=no,status=no");
         if($this.is("a")){
         e.preventDefault();
         return false; 
         }
         });      
  });
 };

})(jQuery);

$(document).ready(function(){
  $("a.mcms_audioplayer").monkmediapopup({file:"href",width:"400",height:"300",playlist:"true",type:"sound",stretching:"fill"});
  $("a.mcms_videoplayer").monkmediapopup({file:"href",playlist:"true",type:"video",stretching:"fill"});
});
