var AddForm = Behavior.create({
  initialize: function() {
    $('add_form').hide();
  },
  onclick: function() {
    $('add_form').show();
    return false;
  }
});

var ModalPop = Behavior.create({
  initialize: function(options) {
    var window_close = new Element('div').addClassName('window_close');
    var w = new Control.Modal(this.element, Object.extend({  
      overlayOpacity: 0.75,  
      className: 'modal',  
      closeOnClick: window_close,
      fade: false
    }, options || {}));  
    w.container.insert(window_close);
    if(w.container.hasClassName("open_window")) w.open();
  }
});

var FlashMessage = Behavior.create({
  initialize: function(){
    new Effect.BlindUp(this.element.identify(), {delay: 3.5});
  }
});

var signup_submit = Behavior.create({
  onclick: function() {
    this.element.disable();
    this.element.value = "Processing...";
    this.element.addClassName("disabled");
    this.element.form.submit();
  }
});

var video_player = Behavior.create({
  initialize: function(){
    this.player = flowplayer(this.element, "/flowplayer/flowplayer-3.1.5.swf",
      {
        clip:  { 
           autoPlay: true, 
           autoBuffering: true
         },
         plugins: {
           controls: {
             url: '/flowplayer/flowplayer.controls-3.1.5.swf',
             playlist: false,
             backgroundColor: '#000', 
             height: 18,
             time: false,
             fullscreen: true,
             volume: false,
             bufferColor: '#666666',
             buttonColor: '#666666',
             tooltips: {
                 buttons: true, 
                 fullscreen: 'Fullscreen' 
             } 
           } 
         }
       }
     );
  }
});

var question_show_hide = Behavior.create({
  initialize: function(options) {
    this.switch_on_value = options["on"];
    this.show = [options["show"]].flatten();
    this.hide = [options["hide"]].flatten();
    this.click = [options["click"]].flatten();
    if(this.hide) this.hide.each(this.hide_element);
    if(this.show) this.show.each(this.hide_element);
    this.onclick();
  },
  onclick: function(e) {
    if(this.set_current_values()) {
      if(this.current_values.include(this.switch_on_value)) {
        if(this.click) this.click.each(this.click_element);
        if(this.hide) this.hide.each(this.hide_element);
        if(this.show) this.show.each(this.show_element);
      } else {
        if(this.show) this.show.each(this.hide_element);
        if(this.hide) this.hide.each(this.show_element);
        if(this.click) this.click.each(this.click_element);
      }
    }
  },
  set_current_values: function() {
    this.current_values = new Array;
    if(current_value = this.element.select('select').first()) {
      this.current_values = [current_value.options[current_value.selectedIndex].innerHTML];
    } else {
      selected_elements = this.element.select('input:checked');
      if(selected_elements.size() > 0) {
        this.current_values = selected_elements.pluck('value');
      }
    }
    return(this.current_values);
  },
  show_element: function(el_id) {
    if(el_id) { 
      var e = $(el_id);
      if (e.style.display == 'none') 
      {
        e.show();
      }
    }
  },
  hide_element: function(el_id) {
    if(el_id) {
      var e = $(el_id);
      if (e.style.display != 'none') e.hide();
    }
  },
  click_element: function(el_id, not_by_value) {
    if(el_id) {
      if(element = $(el_id).select('select').first()) {
         current_element = element.options[element.selectedIndex];
      } else {
        current_element = $(el_id).select('input:checked').first();
      }
      if(current_element) current_element.click();
    }
  }
});

var game_launch = Behavior.create({
  onclick: function() {
    this.open_fullscreen(this.element.href);
    return false
  },
  open_fullscreen: function(page) {
    var URLen = page;
    var windowNamen = "mainflashwindow";
    var browserName =  navigator.appName;
    var operatingSystem=navigator.platform;
    var version = parseFloat(navigator.appVersion);
    // Netscape check version 4.0+ on Win
    if (browserName.indexOf("Netscape")!=-1 && version>=4.0 && operatingSystem.indexOf("Mac")!=-1) { 
      window.open(URLen,windowNamen,'titlebar=no,top=0,left=0,width=' + window.screen.availWidth+',height='+window.screen.availWidth+',screenX=0,screenY=0,top=0,left=0') 
    }
    // MSIE Mac check
    else if (browserName.indexOf("Microsoft Internet Explorer")!=-1 && operatingSystem.indexOf("Mac")!=-1) {
      window.open(URLen,windowNamen,'titlebar=no,top=0,left=0,width=' + window.screen.availWidth+',height='+window.screen.availWidth+',screenX=0,screenY=0,top=0,left=0')
    }
    // Netscape Mac check
    else if (browserName.indexOf("Netscape")!=-1 && operatingSystem.indexOf("Mac")!=-1) {
      window.open(URLen,windowNamen,'width='+screen.width+',height='+screen.height+',top=0,left=0');
    }
    // MSIE Windows
    else if (browserName.indexOf("Microsoft Internet Explorer")!=-1 && operatingSystem.indexOf("Win")!=-1) {
      //window.open(URLen,windowNamen,'fullscreen=yes')
      var win = window.open(URLen,windowNamen,'titlebar=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,top=0,left=0,width=' + window.screen.availWidth+',height='+window.screen.availHeight+',screenX=0,screenY=0,top=0,left=0');
      win.resizeTo(screen.width, screen.height);
    }
    // Netscape Windows
    else if (browserName.indexOf("Netscape")!=-1 && operatingSystem.indexOf("Win")!=-1) {
      window.open(URLen,windowNamen,'width='+screen.width+',height='+screen.height+',top=0,left=0');
    }
    else {
      window.open(URLen,windowNamen);
    }
  }
});

var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 600,
      height: 500,
      name:"_blank",
      location:"no",
      menubar:"no",
      toolbar:"no",
      status:"yes",
      scrollbars:"yes",
      resizable:"yes",
      fullscreen:"no",
      left:"",
      top:"",
      normal:false
    }
    Object.extend(this.options, options || {});

    if (this.options.normal){
        this.options.menubar = "yes";
        this.options.status = "yes";
        this.options.toolbar = "yes";
        this.options.location = "yes";
    }

    this.options.width = this.options.width < screen.availWidth?this.options.width:screen.availWidth;
    this.options.height=this.options.height < screen.availHeight?this.options.height:screen.availHeight;
    var openoptions = 'width='+this.options.width+',height='+this.options.height+',location='+this.options.location+',menubar='+this.options.menubar+',toolbar='+this.options.toolbar+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',status='+this.options.status+',fullscreen='+this.options.fullscreen
    if (this.options.top!="")openoptions+=",top="+this.options.top;
    if (this.options.left!="")openoptions+=",left="+this.options.left;
    window.open(this.options.url, this.options.name,openoptions );
    // return false;
  }
};




// var header_login = Behavior.create({
//   initialize: function(d) {
//     this.default_text = d;
//     this.element.value = d;
//   },
//   onblur: function(e) {
//     if (this.element.value == '') {
//       this.element.value = this.default_text; this.element.style.color = 'grey';
//     }
//   },
//   onfocus: function(e) {
//     if (this.element.value == this.default_text) {
//       this.element.value = ''; this.element.style.color = '#000000'; 
//     }
//   }
// });

