
/*
 * NOTICE OF LICENSE
 *
 * This source file is subject to the the MIT License
 * http://www.opensource.org/licenses/mit-license.php
 *
 * @title: gui Class
 * @author: brent
 * @description: rotate some images standards style!
 * 
 */

function base(){
  this.currentImage = 1;
  this.maxImage = 4;
  this.query_hash = new Hash();
};

//add query string entry
base.prototype.add_query = function(hash){ 
  this.query_hash = this.query_hash.merge(hash);
},

//remove a query string entry, Returns: removed value
base.prototype.remove_query = function(name){ 
  return (this.query_hash.unset(name));
},

//clear the current query string
base.prototype.clear_query = function(){
  this.query_hash = new Hash();
},

base.prototype.query_string = function(){
  return(this.query_hash.toQueryString());
},

base.prototype.fadeInImage = function(){

  Effect.Appear("home-header-image",{to: 1.0, from: 0.001, afterFinish: function(){
      setTimeout(site.fadeOutImage,10000);
    }});

};

base.prototype.fadeOutImage = function(){

  Effect.Fade("home-header-image",{from: 1.0, to: 0.001, afterFinish: function(){
      if (site.currentImage >= site.maxImage){
        site.currentImage = 1;
      }else{
        site.currentImage += 1;
      } 
      document.getElementById("home-header-image").attributes["src"].nodeValue = "app/layout/images/header-image"+site.currentImage+".jpg";
      setTimeout(site.fadeInImage,1000);
    }});

};

base.prototype.filter = function(obj){
  document.getElementById("events-form").submit();
};

base.prototype.manage = function(obj,theid,method){

  var bool = false;
  if (method == "destroy"){
    if (confirm("Are You Sure?"))
    {
      bool = true;
    }
  }else{
    bool = true;
  }

  if (bool)
  {
    var f = document.createElement('form');
    f.style.display = 'none';
    obj.appendChild(f);
    f.method = 'POST';
    f.action = obj.href;
    
    var m = document.createElement('input');
    m.setAttribute('type', 'hidden');
    m.setAttribute('name', 'type');
    m.setAttribute('value', method);
    f.appendChild(m);
    
    var v = document.createElement('input');
    v.setAttribute('type', 'hidden');
    v.setAttribute('name', 'id');
    v.setAttribute('value', theid);
    f.appendChild(v);
    f.submit();
  }
  

};


//get pop up calendar
base.prototype.showPop = function(dateId, div){

    this.add_query({
        'function': 'generatePopCalendar(0,0,"' + dateId + '");'
    });
    
    div.id = dateId + 'pop';
    div.attributes['onclick'].nodeValue = '';
    
    new Ajax.Request('app/views/admin/ajax.html.php', {
        method: 'post',
        parameters: this.query_string(),
        onSuccess: function(transport){
            document.getElementById(dateId + 'pop').innerHTML = transport.responseText;
            site.clear_query();
        },
        onFailure: function(){
            alert('something... unknown happened!');
        }
    });
    
};

//update pop up calendar
base.prototype.updatePop = function(mOff, yOff, dateId){

    this.add_query({
        'function': 'generatePopCalendar(' + mOff + ',' + yOff + ',' + dateId + ');'
    });
    
    new Ajax.Request('app/views/admin/ajax.html.php', {
        method: 'post',
        parameters: this.query_string(),
        onSuccess: function(transport){
            document.getElementById(dateId + 'pop').innerHTML = transport.responseText;
            site.clear_query();
        },
        onFailure: function(){
            alert('something... unknown happened!');
        }
    });
    
};

//add picked date to date text box (from pop up calendar)
base.prototype.addPopDate = function(dateStr, dateType){
    var div = document.getElementById(dateType + 'pop');
    
    setTimeout(function(){
        div.attributes["onclick"].nodeValue = "site.showPop('" + dateType + "',this);";
    }, 200);
    div.innerHTML = 'Select Date';
    $(dateType).value = dateStr;
    div.id = '';
};

base.prototype.toggleAllDay = function(box){
  if (box.checked)
  {
    document.getElementById("thedayspan").attributes["class"].nodeValue = "irrelevant";
  }else{
    document.getElementById("thedayspan").attributes["class"].nodeValue = "";
  }
  
};

base.prototype.moreEvents = function(obj,id){

  var f = document.createElement('form');
  f.style.display = 'none';
  obj.appendChild(f);
  f.method = 'POST';
  f.action = obj.href;

  var v = document.createElement('input');
  v.setAttribute('type', 'hidden');
  v.setAttribute('name', 'events');
  v.setAttribute('value', id);
  f.appendChild(v);
  f.submit();

};


var site = new base();

document.observe("dom:loaded",function(){setTimeout(site.fadeOutImage,5000);});