//FramedContent.prototype=StandardContent.prototype;
function FramedContent(url) {
    this.elementReference;
    this.url=url;
    this.standardContent = new StandardContent();
    this._height=0;
    this._width=0;
    this.verticalScrollbar=null;
    this.standardContentContainer;
    this.createBody();
}

FramedContent.prototype.createBody = function () {
    var object=this;

    this.elementReference=$('<div class="framedContent"></div>');
    //this.verticalScrollbar=$('<div style="background:#181818; width:6px; display:inline-block; margin-left:20px"></div>');
    //this.verticalSlider=$('<div style="background:#FE8A00; height:50px; width:100%"></div>');
    //this.verticalScrollbar.append(this.verticalSlider);
    
    this.standardContentContainer=$('<div style="display:inline-block; overflow:hidden; vertical-align:top"></div>');
    this.elementReference
            .html(this.standardContentContainer.html(this.standardContent.getBodyReference()));

    this.standardContent.getBodyReference().bind('contentChanged',function(event){
        //object.standardContent.getBodyReference().unbind('contentChanged');
        object.standardContent.getBodyReference().css('margin-top','0');
        object.toggleScrollbar();
    });
    
    
    //disableSelection(this.elementReference.html());  
};

FramedContent.prototype.toggleScrollbar=function(){
    if(this.standardContentContainer.height()<this.standardContent.height()){
        this.showScrollbar();
    }
    else
        this.hideScrollbar();
};

FramedContent.prototype.getBodyReference = function () {
    return this.elementReference;
};

FramedContent.prototype.height = function (newValue) {
    if(newValue){
        this._height=newValue;
        this.standardContent.defaultBody.height(newValue/1.4);
    }else
        return this._height;//css stuff added :[
};

FramedContent.prototype.width=function(newValue){
    if(newValue)
        this._width=newValue;
    else
        return this._width;//css stuff added :[
};

FramedContent.prototype.defaultAction=function(){
    this.standardContent.defaultAction();
    //this.hideScrollbar();
};

FramedContent.prototype.load=function(){
    this.standardContent.load(this.url);
};

FramedContent.prototype.showScrollbar=function(){
    if(this.verticalScrollbar==null){
        var object=this;
        this.verticalScrollbar=new SimpleScrollbar();
        this.verticalScrollbar.width(16);
        //this.verticalScrollbar.getBodyReference().hide();
        this.verticalScrollbar.getBodyReference().css('opacity',0);
        //this.verticalScrollbar.getBodyReference().fadeIn();
        this.verticalScrollbar.getBodyReference().animate({opacity:1});
        this.verticalScrollbar.getBodyReference().bind('sliderDrag',function(event){object.scroll(event.fraction);});
        this.refreshBody();
        this.getBodyReference().append(this.verticalScrollbar.getBodyReference());
   }
};

FramedContent.prototype.scroll=function(fraction){
this.standardContent.getBodyReference().stop(true);
    var newPositionY=-(this.standardContent.height()-(this._height-60))*fraction;
    this.standardContent.getBodyReference().css("margin-top",newPositionY);
};

FramedContent.prototype.hideScrollbar=function(){
    if(this.verticalScrollbar!=null){
        this.verticalScrollbar.unload();
        this.verticalScrollbar=null;
        this.refreshBody();
    }
};

FramedContent.prototype.refreshScrollbar=function(){
    this.verticalScrollbar.height(this._height-60);
    this.verticalScrollbar.sliderCover(this.standardContentContainer.height()/this.standardContent.height());
    this.verticalScrollbar.refreshBody();
};

FramedContent.prototype.refreshBody=function(){
    this.getBodyReference().height(this._height);
    this.standardContentContainer.height(this._height-60);
    //this.verticalScrollbar.height(this._height-60);//style stuff here :[

    if(this.verticalScrollbar!=null){
        this.standardContent.width(this._width-this.verticalScrollbar.width()-1-3-20-20);
        this.refreshScrollbar();
    }else
        this.standardContent.width(this._width-1-3-20-20);
       
    this.standardContent.refreshBody();
};

FramedContent.prototype.unload=function(){
    this.standardContent.unload();
    if(this.verticalScrollbar!=null){
        this.verticalScrollbar.getBodyReference().unbind('sliderDrag');
        this.verticalScrollbar.unload();
    }
    this.getBodyReference().remove();
};
