SchedulePopup = function(browserSpecificSettings) {
	this.id = null;
	this.isInHideProcess = false;
	this.browserSpecificSettings = browserSpecificSettings;	
}

SchedulePopup.prototype.display = function(xpos, ypos, direction, listingId, browserSpecificSettings) {
	
    offset = $('schedule_entry_' + listingId).cumulativeOffset();
    endOfScheduleX = $$('.schedule')[0].getWidth() + $$('.schedule')[0].cumulativeOffset()[0];
    if (xpos > (endOfScheduleX - 300)) {
        $('episode_popup_box').style.left = (offset[0] ) + 'px';
    }
    else 
        $('episode_popup_box').style.left = (xpos + 10) + 'px';
    
    if (direction == "up") 
        $('episode_popup_box').style.top = (offset[1] - $('episode_popup_box').getHeight() + this.browserSpecificSettings.up_facing_popup_offset) + 'px';
    else 
        $('episode_popup_box').style.top = (offset[1] + this.browserSpecificSettings.down_facing_popup_offset) + 'px';
	//transitionPopup();
    window.setTimeout('schedule.runtime.popup.transition()', 50);
	return listingId;
}

SchedulePopup.prototype.transition = function() {
    if (this.browserSpecificSettings.shouldDoTransitionEffect) {
        new Effect.Appear($('episode_popup_box'), {
            duration: 0.1,
            start: 0,
            end: 1.0
        });
    }
    $('episode_popup_box').style.visibility = 'visible';
}

SchedulePopup.prototype.updateContent = function(view, listingId, direction, path) {
	
	params = 'view='+view +
			  '&id=' + listingId + 
			 '&direction=' + direction;
    new Ajax.Updater('episode_popup_box', 
					 path+'/?controller=Episode', 
					 {
					 	method: 'post',
						parameters: params,
					 	evalScripts:true
					 }	
	);
}

SchedulePopup.prototype.displayForListing = function(view, event, listingId, path) {
	
    if (this.browserSpecificSettings.shouldHidePopupDuringTransition) 
        $('episode_popup_box').hide();
    direction = (event.clientY > ((screen.availHeight / 2) - 30)) ? "up" : "down";
    oldContent = $('episode_popup_box').innerHTML;
	this.updateContent(view, listingId, direction, path);
    // delay until the content is ACTUALLY changed (in all browsers except ie < v6)
    // using the onComplete parameter with Ajax.Updater didn't work-- it was called
    // before the ajax response content was put in 'episode_popup_box' div
    if (this.browserSpecificSettings.shouldDelayPopupTransition) {
        while ($('episode_popup_box').innerHTML != oldContent) 
            x = 1;
    }
    window.setTimeout('schedule.runtime.popup.display(' + event.clientX + ',' + event.clientY + ', \'' + direction + '\',\'' + listingId + '\')', 800);  
}

SchedulePopup.prototype._hide = function(){
    if (schedule.runtime.mouse.isInPopup) 
        return;
    $('episode_popup_box').style.visibility = 'hidden';
    schedule.runtime.popup.id = null;
}

SchedulePopup.prototype.hide = function()
{
    this.runtime.popup.isInHideProcess = true;
}


        
