﻿var ClassItems  = new Array();
var ClubClasses = new Array();
var CSS_POP     = "PopClassContainer";
var CSS_HIDE    = "Hide";

function DayItemOver(e, code, isOver){
    var classItem = ClassItems["ic"+code.toString()];
    var box      = FindElement("div", "PopClassContainer");
    if (isOver){              
       classItem.Binder = e;       
       classItem.Load(); 
       classItem.BoxShiftLeft   = 110;
       classItem.BoxShiftTop    = -10;
       classItem.Show(box);  
    }
    else
    {
        classItem.Hide(box);        
    }
}

function Body_OnLoad(){

}

function ClubClass(id, name, exp, imp){
    this.ClassId        = id;
    this.Name           = name;
    this.Experience     = exp;
    this.Impact         = imp;
    this.Description    = "";
} 

function ClassItem(itemId, day, start, end, duration, trainer){
this.Binder         = null;
this.ClubClass      = null;
this.ItemId         = itemId;
this.Day            = day;
this.StartTime      = start;
this.EndTime        = end;
this.Duration       = duration;
this.Instructor     = trainer;
this.BoxShiftTop    = 0;
this.BoxShiftLeft   = 0;
}

ClassItem.prototype.Load = function(){
          
    // required fields
    var eName       = FindElement("div",  "popClassName");
    var eDay        = FindElement("span", "popDay");
    var eTimeSpan   = FindElement("span", "popTimeSpan");
    var eDuration   = FindElement("span", "popDuration");
    var eDesc       = FindElement("div",  "popDescription");    

    eName.innerHTML     = this.ClubClass.Name;
    eDay.innerHTML      = this.Day;
    eTimeSpan.innerHTML = this.StartTime+"-"+this.EndTime;
    eDuration.innerHTML = this.Duration+" minutes";
    
    eDesc.innerHTML     = this.ClubClass.Description;

    // optional fields
    var eInst       = FindElement("span", "popInstructor");
    if (eInst)
        eInst.innerHTML = this.Instructor;  
        
    var eLevels     = FindElement("div",  "popLevels");      
        
    if (this.ClubClass.Experience!="NA"||this.ClubClass.Impact!="NA")
    {        
        var eExp        = FindElement("span", "popExperience");
        var eImp        = FindElement("span", "popImpact");
        if (eLevels)
        {
            eLevels.className = "popLevels";
            eExp.innerHTML = this.ClubClass.Experience;
            eImp.innerHTML = this.ClubClass.Impact;
        }        
    }
    else
    {
        if (eLevels)
        {
            eLevels.className = "Hide";
        }   
    }    
};
ClassItem.prototype.Show = function(displayBox){ 
    var container = FindElement("div","ScheduleContainer");
    var pos = 0;
    var width = 0;
    var height = 0;
    if (container!=null){
        pos     = findPos(container);
        width   = container.offsetWidth;
        height  = container.offsetHeight;
    }
    var farRight    = pos[0]+width;
    var farBottom   = pos[1]+height;
    
    var e = FindElement("div", "ScheduleContainer");
    this.BinderPosition    = findPos(this.Binder);
   
    displayBox.className   = CSS_POP;
    
    var leftPos     = this.BinderPosition[0]+this.BoxShiftLeft;
    var topPos      = this.BinderPosition[1]+this.BoxShiftTop-e.scrollTop;
    
    var boxRight    = displayBox.offsetWidth+this.BinderPosition[0]+this.BoxShiftLeft;
    var boxBottom   = displayBox.offsetHeight+this.BinderPosition[1]+this.BoxShiftTop-e.scrollTop;

    
    if (boxRight>=farRight)
        leftPos=this.BinderPosition[0]-displayBox.offsetWidth+25;
    
    if (boxBottom>=farBottom)
        topPos=farBottom-displayBox.offsetHeight;
    
    displayBox.style.left  = leftPos+"px";
    displayBox.style.top   = topPos+"px";
    //this.Binder.className  = this.Binder.className+" itemOver";
    
};
ClassItem.prototype.Hide = function(displayBox) {
    displayBox.className = CSS_HIDE;    
    //this.Binder.className  = this.Binder.className.replace(" itemOver", "");
};


