﻿Position.GetWindowSize = function(w) {
        w = w ? w : window;
        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        return [width, height]
}
Position.Center = function(element, parent) {
        var w, h, pw, ph, topPx, leftPx;
        
        var d = Element.getDimensions(element);
        w = 500;//d.width;
        h = d.height;
        Element.absolutize(element);
        jQuery(element).setStyle({width: w+'px', height: h+'px'});
        
        Position.prepare();
        
        var ws = Position.GetWindowSize();
        
        pw = ws[0];
        ph = ws[1];
        
        if (parent) {
                pw = parent.offsetWidth;
                //ph = parent.offsetHeight;
        }
        
        topPx = ((ph/2) - (h/2) + Position.deltaY) + "px";
        leftPx = ((pw/2) - (w/2) + Position.deltaX) + "px";
        
        jQuery(element).setStyle({top: topPx, left: leftPx});

}


/*  =DID_YOU_KNOW
    ---------------------------------------------------- */
   var DidYouKnowExtender = Class.create({
		 initialize: function() {
		    if(jQuery('Quotes') == null)
		    {
		        return;
		    }
			this.debug = true;
			
			this.FullQuote = jQuery('Quotes').down('div#full_quote');
			
			//this.totalElmt = this.arrControls.size();
			jQuery('Quotes').observe('click', function(event){
	            this.update();
	        }.bind(this));
			
		 },		 
		start: function() {
			    try{
			        this.FullQuote.hide();
			    }
			    catch(e)
			    {
			        if(this.debug)
	                {
	                    alert(e);
	                }
			    }
		},
		showQuote: function() {
		    try
		    {
		        if(!this.FullQuote.hasClassName('expanded'))
		        {
		            new Effect.Appear(this.FullQuote, { duration: 2.0,beforeStart:function(){
			            Position.Center(this.FullQuote, jQuery('stage'));
				        this.FullQuote.addClassName('expanded');     
			        }.bind(this)});    
                }
			}
			catch(e)
			{
			    if(this.debug)
	            {
	                alert(e);
	            }
			}
		},
		hideQuote: function() {
		    try
		    {
		        if(this.FullQuote.hasClassName('expanded'))
		        {
			        new Effect.Fade(this.FullQuote, { duration: 1.0,afterFinish:function(){
				        this.FullQuote.removeClassName('expanded');  
			        }.bind(this)});               
			    }
			}
			catch(e)
			{
			    if(this.debug)
	            {
	                alert(e);
	            }
			} 
			
		},
		toggle: function () {
		    try
		    {
		        if(this.FullQuote.hasClassName('expanded'))
		        {
		            this.hideQuote();
		        }
		        else
		        {
		            this.showQuote();
		        }
		    }
		    catch(e)
		    {
		        if(this.debug)
		        {
		            alert(e);
		        }
		    }
		},
		update: function() {
		    try
		    {   
		        this.toggle();
		    }
		    catch(e)
		    {
		        if(this.debug)
	            {
	                alert(e);
	            }
		    }
		}
	});
	
	
    // Extending all elements to support special interactive functionality.
    function createDidYouKnowExtender(e){  
        var didYouKnowExtender = new DidYouKnowExtender();
		didYouKnowExtender.start();
    };
    
    //Add this to the member listing page/control.
    //Event.observe(window, 'load', createDidYouKnowExtender);

