
/*
 * FED - REOL
 * Copyright 2010. All rights reserved.
 *
 * Description: Global Variables [production]
 */
var Gv = {
  env: 'pro',          // Environment [dev = development, pro = production]
  page: null,          // Page instance, globally referrable.
  rpc: '',        // RPC Path
  ge: new Events(),    // Global event handler
  url:                 // Page Urls
  {
    ext: '/j/y/b/ext'
  },
  root: 'fed.reol.com'  // Root Domain
};
/*
 * FED - REOL
 * Copyright 2010. All rights reserved.
 *
 * Class: Core
 */
var Core = new Class();
Core.extend({
  idToPage: function(id){
    return 'Page.'+id.trim().capitalize();
  },
  addClear: function(el, loc){
    var location = $pick(loc, 'bottom');
    return new Element('div', { "class": "g_clear" }).inject(el, loc);
  },
  addIECache: function(){
    if (this.isIE())
      document.execCommand("BackgroundImageCache",false,true);
  },
  isIE: function(){
    return (Browser.ie);
  },
  isIE6: function(){
    return (this.isIE() && (Browser.Engine.version <= 4));
  },
  isIE7: function(){
    return (this.isIE() && (Browser.Engine.version == 5));
  },
  isIE8: function(){
    return (this.isIE() && (Browser.Engine.version == 6));
  },
  is_mobile_safari: function(){
    return (this.is_ipad() || this.is_iphone());
  },
  is_ipad: function(){
    return (navigator.userAgent.match(/iPad/i) != null);
  },
  is_iphone: function(){
    return (navigator.userAgent.match(/iPhone/i) != null);
  },
  getExtPath: function(){
    return gv_r+Gv.get('url').ext+'/{Klass}.js';
  },
  toUrl: function(url){
    window.location = url;
  },
  warn: function(e){
    if (Gv.get('env') == 'dev')
    {
      alert(e.fileName+'\nError: '+e.name+'\nLine: '+e.lineNumber+'\n'+e.message);
    }
  }
});
/*
---
name: DisplayObject
description: Standard object inheriting additional common element behavior.
authors:
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires:
- core/1.2.4: '*'
provides: [DisplayObject]
...
*/
var DisplayObject = new Class
({
  Implements: [Events],
  initialize: function()
  {
    this.build();
    return;
  },
  build: function()
  {
    this.is_visible = false;
    this._element;
    this.fx_element = new Fx.Morph($(this), {link: 'cancel'});
  },
  fade_in: function(e)
  {
    this.stop_event(e);
    
    this.fx_element.start(
    {
      opacity: 1
    }).chain(this.fireEvent.bind(this, 'onFadeIn'));
    
    return this;
  },
  fade_out: function(e)
  {
    this.stop_event(e);
    
    this.fx_element.start(
    {
      opacity: 0
    }).chain(this.fireEvent.bind(this, 'onFadeOut'));
    
    return this;
  },
  hide: function(e)
  {
    this.stop_event(e);
    $(this).setStyle('display', 'none');
    return this;
  },
  show: function(e)
  {
    this.stop_event(e);
    $(this).setStyle('display', 'block');
    return this;
  },
  stop_event: function(e)
  {
    if (e && e.stop)
    {
      e.stop(); 
    }
  },
  toElement: function()
  {
    return this._element;
  }
});
/*
--- 
description: LazyLoader
authors: 
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires: 
- core/1.3: '*'
- more/1.3.1: [Utilities.Assets]
- more/1.3.1: [Class.Refactor]
provides: [LazyLoader]
...
*/
var LazyLoader = new Class
({
  Implements: [Events, Options],
  options:
  {
  /*
    onLoad: $empty(thisElement, event),
    onProcessStart: $empty(thisElement, event),
    onProcessEnd: $empty(thisElement, event),
  */
    autoStart: true,
    path: '{Klass}.js'
  },
  initialize: function(klass, args, options)
  {
    this.setOptions(options);
    var opts = this.options;
    
    this.klass = klass;
    this.args = args;
    this.instance;
    
    this.load();
  },
  emulate: function()
  {
    var args = arguments;
  },
  instantiate: function()
  {
    var Klass = this.Klass;
    Class.refactor(Klass,
    {
      initialize: function()
      {
        this.previous.apply(this, arguments[0]);
      }
    });
    return new Klass(arguments);
  }.protect(),
  load: function()
  {
    var opts = this.options, script = opts.path.substitute({Klass: this.klass});
    new Asset.javascript(script,
    {
      'onload': this.loaded.bind(this)
    });
  },
  loaded: function()
  {
    this.fireEvent('load');
    if (this.options.autoStart)
    {
      this.process();
    }
  },
  process: function()
  {
    var klass = null;
    this.fireEvent('processStart');
    if (this.instance == undefined)
      eval('this.Klass = '+this.klass);
    this.instance = this.instantiate.apply(this, this.args);
    this.fireEvent('processEnd');
  },
  getInstance: function()
  {
    return this.instance;
  }
});

LazyLoader.Multiple = new Class (
{
  Implements: [Events, Options],
  Extends: LazyLoader,
  initialize: function(klasses, options)
  {
    this.setOptions(options);
    var opts = this.options;

    this.klasses = klasses;

    this.load(0);
  },
  load: function(i)
  {
    var opts = this.options, script;

    if (i > this.klasses.length-1)
    {
      this.fireEvent('load');
      return;
    }

    script = opts.path.substitute({Klass: this.klasses[i]});

    new Asset.javascript(script,
    {
      'onload': this.load.bind(this, i+1)
    });
  }
});
/*
 * FED - REOL
 * Copyright 2010. All rights reserved.
 *
 * Class: Page
 * Description: a generic page meant to be extended
 */
var Page = new Class();
/*
---
name: Remote
description: Provides default JSON rpc request functionality
authors:
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires:
- core/1.2.4: '*'
provides: [Remote]
...
*/
var Remote = new Class
({
  Implements: [Events, Options],
  options:
  {
    rpc_qs_token: '?',
    rpc_path: '',
    rpc: null,
    extra_query_string: null,
    autostart: true
  },
  initialize: function(options)
  {
    this.setOptions(options);
    this.build();
    return;
  },
  build: function()
  {
    this.data;
    this.has_data = false;
    this.rpc_count = 0;
    this.rpc_url;
    this.rqt;
    this.statement;
    
    this.prepare();
    if (this.options.autostart)
    {
      this.send();
    }
    return;
  }, 
  prepare: function(new_qs)
  {
    var opts = this.options,
        qs = (new_qs) ? new_qs : opts.extra_query_string,
        qs = (qs) ? qs+'&' : '',
        rq;

    this.qs = qs;
    this.statement = opts.rpc_path+opts.rpc+opts.rpc_qs_token+this.qs;
  },
  send: function()
  {
    if (this.rqt instanceof Request)
    {
      this.rqt.cancel();
    }
    this.rqt = new Request.JSON(
    {
      data: this.qs,
      url: this.statement,
      noCache: true,
      onSuccess: function(data)
      {
        this.has_data = true;
        this.set_data(data);
        this.fireEvent('onSuccess');
      }.bind(this)
      }).post();
      return;
  },
  get_data: function()
  {
    return (this.has_data) ? this.data : false;
  },
  get_rpc: function()
  {
    return this.rpc;
  },
  set_data: function(data)
  {
    if (data instanceof Object)
    {
      //console.log('Remote data is set: ');
      //console.log(data);
      this.data = data;
    }
    else
    {
      console.log('RPC: '+this.options.rpc+'. Invalid data');
    }
  }
});
/*
 * FED - REOL
 * Copyright 2010. All rights reserved.
 *
 * Class: Site
 * Description: Provides a clean init sequence.
 */
var Site = new Class({
  initialize: function(){
    this.pre();
      
    this.init_ga();
    
    if(Core.is_ipad()){
       $(document.body).addClass('ipad');
    }
    
    
    var bdy = $(document.body), id = bdy.get('id'), page;
    eval('page = new '+Core.idToPage(id)+'()');
    Gv.page = page;
    
    new IE6($('w_ie6'));
       
    this.post();
  },      
  init_ga: function(){   
    var src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var ga_script = new Asset.javascript(src, {onLoad: this.init_ga_code.bind(this)});   
  },     
  init_ga_code: function(){
     var pageTracker = _gat._getTracker("UA-11742147-1"); 
     pageTracker._initData();
     pageTracker._trackPageview(); 
     this.pageTracker = pageTracker;   
     this.init_ga_links();
  },
  init_ga_links: function(){
      $$('a').each(function(_a){    
         if(_a.get('data-ga')){
           _a.addEvent('click', this.handle_ga_external_track.bind(this) );
         }
      }.bind(this));
      $$('a').each(function(_a){
         if(_a.get('data-ga-external-demo')){      
           _a.addEvent('click', this.handle_ga_demo_track.bind(this) );
         }
      }.bind(this));    
  },
  handle_ga_external_track: function(e){      
    var _a = $(e.target);
    if(_a.get('tag') != 'a'){
      _a = _a.getParent('a');
    }  
    if(this.pageTracker){     
      this.pageTracker._trackPageview(_a.get('data-ga'));
    }else{
      alert('Analytics Tracking: ' + _a.get('data-ga'));    
    }
  },
  handle_ga_demo_track: function(e){  
    var _a = $(e.target);
    if(_a.get('tag') != 'a'){
      _a = _a.getParent('a');
    }  
    if(this.pageTracker){     
      _gat._getTrackerByName()._trackEvent('View Demo', _a.get('href') );
    }else{
      alert('Analytics Tracking: View Demo | '+_a.get('href'));       
    }
  },
  pre: function(){},
  post: function(){}
});
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Abt
 * Extends: Page
 * Description: About Us page
 */
Page.Abt = function(){};
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Cln
 * Extends: Page
 * Description: Client main page.
 */
Page.Cln = new Class(
{
  initialize: function()
  {   
    
    this._show_container = $('w_show_container') || new Element('div'); 
    
    $$('a[target="show"]').each(function(_anchor, i){
       _anchor.addEvent('click', this.handle_anchor_click.bind(this));
    }.bind(this));        
    
    var _anchors = $$('.w_infonav_anchor');
    
    var hash = window.location.hash;
    var display_idx = 0;
    if(hash){
      window.location.hash = null;          
      hash = hash.replace("#", '');   
      display_idx = _anchors.indexOf(document.id(hash));
      if(display_idx < 0){
        display_idx = 0;
      }  
    }     
    
    
    new Fx.Accordion(_anchors, $$('.w_infonav_content'),
    { 
      display: display_idx,
      onActive: function(toggler, element)
      {
        toggler.addClass('active'); 
        //element.addClass('active');      
        this.display_show_from_anchor(toggler);

        if(Core.isIE()){
           
           this.fix_ie_text.delay(1000, this, element);
      
           
        }

        
      }.bind(this),
      onBackground: function(toggler, element)
      {
        toggler.removeClass('active');    
        //element.removeClass('active');   
      }
    }); 
    
    
    
    
  },    
  fix_ie_text: function(e){
      e.set('style', e.get('style').toString().replace('FILTER: ;', ''));
  },
  handle_anchor_click: function(e){
    if(e && e.stop){
      e.stop();
    }  
  },   
  display_show_from_anchor: function(_anchor){
    if(!_anchor){
      return;
    } 
    var target_show_id = _anchor.get('data-show');
    if(target_show_id != null){
      var _show = this._show_container.getElement('#'+target_show_id);
      if(this._current_show){
        this._current_show.hide();
      }              
      this._current_show = _show.show();
    }else{
      var href = _anchor.get('href'); 
      this.remote = new Remote({  
                                  rpc: href,
                                  onSuccess: this.build_show_from_anchor.bind(this, _anchor)
                               });   
    }      
  },
  build_show_from_anchor: function(_anchor){
    var data = this.remote.get_data(),
        uid = String.uniqueID(),
        _el = new Element('div', {'class': 'w_show', 'id': uid}).inject(this._show_container);
    _anchor.set('data-show', uid); 
    
    this.current_show = new Show(_el);        
    this.current_show.defer_build(data);
    
    this.display_show_from_anchor(_anchor); 
  }
}); 
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Cnt
 * Extends: Page
 * Description: Contact Us main page.
 */
Page.Cnt = new Class(
{
  initialize: function()
  {
    new ContactForm(document.id('contact_form'));
  }
});
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Err
 * Extends: Page
 * Description: Error page
 */
Page.Err = function(){};
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Gen
 * Extends: Page
 * Description: None
 */
Page.Gen = function(){};
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Hom
 * Extends: Page
 * Description: None
 */
Page.Hom = new Class(
{
  initialize: function()
  {
    var scrollshow = new Scrollshow($('animated_banner'));
    
    new Fx.Accordion($$('.w_inform .w_juicy'), $$('.w_inform dd'),
    {
      display: -1, 
      alwaysHide: 1,
      onActive: function(toggler)
      {           
        
        toggler.addClass('active');
        var view_id = toggler.get('text').clean();
        scrollshow.set_view_by_id(view_id);
      },
      onBackground: function(toggler)
      {                 
        toggler.removeClass('active');
        var _active = $$('.w_inform .w_juicy.active');
        if(_active.length == 0){
           scrollshow.set_view_by_id('Default');
        }
      }
    });
  } 
});
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Prd
 * Extends: Page
 * Description: None
 */
Page.Prd = function(){};
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Pro
 * Extends: Page
 * Description: None
 */
Page.Pro = new Class(
{
  initialize: function()
  {
    this.quote_form = new RequestQuoteForm($('quote_form').getElement('.w_form'));    
    
    this.scrollshow = new Scrollshow($('animated_banner'));
    this.rotate = new Rotate(document.id('demo'));
    
    var launch_demo_btn = $('launch_demo_btn');
    if(launch_demo_btn){
      launch_demo_btn.addEvent('click', this.handle_demo_click.bind(this));
    }
    
    
    $$('a[target="ipopup"]').each(function(_anchor){
      new IPopup(_anchor, {onShow: this.handle_popup_show.bind(this)});
    }.bind(this))
  }, 

  handle_popup_show: function(ipopup){
    
    if(this.quote_form){
      this.quote_form._response.hide();
      this.quote_form._form.show();
      this.quote_form.popup = ipopup;    
      ipopup._element.removeClass('error').removeClass('success');
    }   
    if(OverText != null){
      OverText.update();
    }
  },
  handle_demo_click: function(e){
    if(e && e.stop){
      e.stop();
    }
    if(this.scrollshow && this.scrollshow.active_view){
      this.scrollshow.active_view.open_first_popup();
    }
  }
});
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Smp
 * Extends: Page
 * Description: None
 */
Page.Smp = new Class(
{
  initialize: function()
  {
    this.quote_form = new RequestQuoteForm($('quote_form'));    
    $$('a[target="ipopup"]').each(function(_anchor){
      new IPopup(_anchor, {onShow: this.handle_popup_show.bind(this)});
    }.bind(this))
  },
  handle_popup_show: function(ipopup){
    
    if(this.quote_form){
      this.quote_form._response.hide();
      this.quote_form._form.show();
      this.quote_form.popup = ipopup;    
      ipopup._element.removeClass('error').removeClass('success');
    }   
    if(OverText != null){
      OverText.update();
    }
  }
});
/*
 * REOL Services - JavaScript
 * Copyright 2010, 2011. All rights reserved.
 *
 * Class: Page.Srv
 * Extends: Page
 * Description: None
 */
Page.Srv = new Class(
{
  initialize: function()
  {          
    
   
    var ferris = new Ferris($('ferris'));     
    
    var _buttons = $$('.w_ferris_button');
    
    var hash = window.location.hash;
    
    if(hash){    
      window.location.hash = null;          
      hash = hash.replace("#", ''); 
      var _button = document.id(hash);  
      display_idx = _buttons.indexOf(_button);
      if(display_idx >= 0){
         ferris.launch(ferris.buttons[display_idx]);
      }  
    }         
        
    
  } 
});
/*
--- 
description: ContactForm
authors: 
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires: 
- core/1.3: '*'
provides: [ContactForm]
...
*/
var ContactForm = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_form'
  },
  initialize: function(_element, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        cls   = opts.cls,
        fcls  = '.'+cls,
        _this = document.id(this);
        
    this._form = _form = this._element.getElement('form');
    this._inputs = _inputs = _form.getElements('input[type=text], textarea');
    this._response = this._element.getElement(fcls+'_response') || new Element('div', {'class': cls+'_response'}).hide().inject(this._element, 'top');
    _inputs.each(function(_input, i)
    {
      var _lbl = _input.getPrevious('label');
      new OverText(_input,
      {
        element: 'span',
        textOverride: _lbl.get('text'),
        positionOptions:{'offset': {'x': 10, 'y': 12}},
        labelClass: cls+'_overtext',
        poll: true
      });
    }.bind(this));
    
    var contact_rpc = _form.getProperty('action').trim(),
        contact_rpc = contact_rpc.substr(1, contact_rpc.length);
        
    this.remote = null;

    _form.addEvent('submit', function(e)
    {
      e.stop();
      this.remote = new Remote(
      {
        rpc_path: '',
        rpc: contact_rpc,
        extra_query_string: _form.toQueryString(),
        onSuccess: this.process_data.bind(this)
      });
    }.bind(this));
  },
  process_data: function()
  {
    var data = this.remote.get_data();
    this._element.removeClass('_error')
                 .removeClass('_success')
                 .addClass('_'+data.status);

    if(data && data.status == 'error' && data.errors){
      this.handle_errors(data.errors);
    }else if(data && data.status == 'success'){
      this.handle_success(data.message);
    }
    

      if(data.ga){
        var site = Gv.site;
        if(site && site.pageTracker){
          site.pageTracker._trackPageview(data.ga);
        }
      }
    this.fireEvent(data.status, [this, data]);
    this.update_overtext();
  },
  update_overtext: function(){
   if(OverText){
      OverText.update();
   }
  },
  handle_success: function(message){
     var _form = this._form,
          _fields = this._fields || {};
     Object.each(_fields, function(_f){
         if(_f != 1){
            _f.set('text', '');
         }
      });
      this._response.set('html', message).show();
      this._form.hide().reset();
  },
  handle_errors: function(errors){
      var _form = this._form,
          _fields = this._fields || {};
      Object.each(_fields, function(_f){
         if(_f != 1){
            _f.set('text', '').hide();
         }
      });
      Object.each(errors, function(value, key){
         if(!_fields[key]){
            var _inp = _form.getElement('#'+key);
            if(_inp){
               _fields[key] = _inp.getNext('label.error') || new Element('label', {'class':'error'}).inject(_inp, 'after');
            }else{
               _fields[key] = 1;
            }
         }
         if(_fields[key] && 1 != _fields[key]){
            _fields[key].set('text', value).show();
         }
      }.bind(this));
      this._fields = _fields;
  }
});
/*
--- 
description: Ferris
authors: 
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires: 
- core/1.3: '*'
provides: [Ferris]
...
*/
var Ferris = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_ferris'
  },
  initialize: function(_element, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        fcls  = '.'+opts.cls,
        _this = document.id(this);
    
    this.buttons = [];
    this.active = null;

    _this.getElements(fcls+'_button').each(function(_button, i)
    {
      this.buttons.push(new Ferris.Button(_button, i, this));
    }.bind(this));
    
    this._veil = _this.getElement(fcls+'_veil');
    this.veil = new Ferris.Veil(this._veil, this);
    
    this._popup = _this.getElement(fcls+'_popup');
    this.popup = new Ferris.Popup(this._popup, this);
    
    this.animate.delay(300, this);
  },
  animate: function()
  {
    this.buttons.each(function(button, i)
    {
      button.show();
    });
  },
  goto_button: function(button)
  {
    if (this.active)
      this.active.turn_active(false);
    
    this.set_active(button);
    button.turn_active(true);
    this.popup.set_item(button);
  },
  goto_next: function()
  {
    var current_id = this.active.id,
        length     = this.buttons.length,
        next_id    = (current_id+1 >= length) ? 0 : current_id+1;
    
    this.goto_button(this.buttons[next_id]);
  },
  goto_previous: function()
  {
    var current_id = this.active.id,
        length     = this.buttons.length,
        previous_id= (current_id-1 < 0) ? length-1 : current_id-1;
    
    this.goto_button(this.buttons[previous_id]);
  },
  hide_item: function()
  {
    this.veil.hide();
    this.popup.hide();
    this.active.turn_active(false);
  },
  launch: function(button)
  {
    this.popup.show();
    this.veil.show();
 
    this.goto_button(button);
  },
  set_active: function(active_button)
  {
    this.active = active_button;
  },
  toElement: function()
  {
    return document.id(this._element);
  }
});

Ferris.Button = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_ferris_button'
  },
  initialize: function(_element, id, ferris, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this.id = id;
      this._element = _element;
      this.ferris = ferris;
      this.build();
    }
  },
  build: function()
  {
    var opts = this.options;
        fcls = '.'+opts.cls;
    
    this.fx = new Fx.Morph(this._element, {link: 'cancel'});
    this._description = this._element.getElement(fcls+'_description');
    
    document.id(this).getElement('a').addEvents(
    {
      mouseenter: function(e)
      {
        this.turn_on(e);
      }.bind(this),
      mouseleave: function(e)
      {
        this.turn_off(e);
      }.bind(this),
      click: function(e)
      {
        e.stop();
        this.ferris.launch(this);
      }.bind(this)
    });
  },
  get_content: function()
  {
    return this._description.get('html');
  },
  show: function()
  {
    (function()
    {
      this._element.setOpacity(0);
      this._element.setStyle('visibility', 'visible');
      var pos = this._element.getPosition(),
          pos_x = pos.x - this._element.getOffsetParent().getPosition().x;
      this._element.addClass('move');
      this.fx.start(
      {
        left: [pos_x-20, pos_x],
        opacity: [0, 1]
      });
    }.delay(this.id*50*Math.sqrt(this.id), this));
  },
  turn_off: function(e)
  {
    e.stop();
    document.id(this).removeClass('hover');
  },
  turn_on: function(e)
  {
    e.stop();
    document.id(this).addClass('hover');
  },
  turn_active: function(is_active)
  {
    if (is_active)
      document.id(this).addClass('active');
    else
      document.id(this).removeClass('active');
  },
  toElement: function()
  {
    return document.id(this._element);
  }
});

Ferris.Popup = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_ferris_popup'
  },
  initialize: function(_element, ferris, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element;
      this.ferris = ferris;
      this.build();
    }
  },
  build: function()
  {
    var opts = this.options,
        fcls = '.'+opts.cls;
    //this._element.setOpacity(0);
    if(Core.isIE()){
      this._element.setStyle('visibility', 'hidden');
    }else{
      this._element.fade('hide');
    }
    this.fx = new Fx.Morph(this._element, {link: 'cancel'});
    this._next     = this._element.getElement(fcls+'_next');
    this._previous = this._element.getElement(fcls+'_previous');
    this._close    = this._element.getElement(fcls+'_close'); 
    this._content  = this._element.getElement(fcls+'_content');
    
    this._next.addEvent('click', this.ferris.goto_next.bind(this.ferris));
    this._previous.addEvent('click', this.ferris.goto_previous.bind(this.ferris));
    this._close.addEvent('click', this.ferris.hide_item.bind(this.ferris));
  },
  set_item: function(button)
  {
    this._content.set('html', button.get_content());
  },
  show: function()
  {
    this._element.addClass('popup');
    this._element.removeClass('popdown');
    this._element.setStyle('visibility', 'visible');
    /*
    this.fx.start(
    {
      opacity: 1
    });
    */
    if(Core.isIE()){
      this._element.setStyle('visibility', 'visible');
    }else{
      this._element.fade('in');
    }
  },
  hide: function()
  {
    this._element.addClass('popdown');
    this._element.removeClass('popup');
    /*
    this.fx.start(
    {
      opacity: 0
    });
    */
    if(Core.isIE()){
      this._element.setStyle('visibility', 'hidden');
    }else{
      this._element.fade('out');
    }
  }
});

Ferris.Veil = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_ferris_veil'
  },
  initialize: function(_element, ferris, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element;
      this.ferris = ferris;
      this.build();
    }
  },
  build: function()
  {
    var screen_width = document.id(document.body).getSize().x,
        _parent_offset = this._element.getOffsetParent(),
        parent_offset_width = _parent_offset.getPosition().x;
    this._element.setStyles(
    {
      width: screen_width,
      left: 0-parent_offset_width
    });
    
    this._element.setOpacity(0);
    this.fx = new Fx.Morph(this._element, {link: 'cancel'});
    
    this._element.addEvent('click', this.ferris.hide_item.bind(this.ferris));
  },
  show: function()
  {
    this._element.setStyle('visibility', 'visible');
    this.fx.start(
    {
      opacity: 0.7
    });
  },
  hide: function()
  {
    this.fx.start(
    {
      opacity: 0
    });
  }
});
var IE6 = new Class({
  Implements: Options,
  options:
  {
    cls: 'w_ie6'
  },
  initialize: function(_element, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element; 
      this.build();
    }
  },
  build: function(){
    var opts = this.options,
        _self = this._element,
        _close = _self.getElement('.'+opts.cls+'_close');
    if(_close){
      _close.addEvent('click', this.close.bind(this));
    }
  },
  close: function(e){
    if(e && e.stop){
      e.stop();
    }          
    this._element.destroy();
  }
});
var IPopup = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_ipopup'
  },
  initialize: function(_anchor, options)
  {
    this.setOptions(options);
    if (_anchor)
    {
      this._anchor = _anchor; 
      var href = _anchor.get('href').toString().trim().replace('#', '');
      this._element = document.id(href);    
      if(this._element){
        this.build();
      }
    }
  },
  build: function(){
     var opts = this.options,
         _self = this._element;         
         
     if(!_self.hasClass(opts.cls)){
       var _element = new Element('div', {'class': opts.cls}),                      
           _inner = new Element('div', {'class': opts.cls+'_inner'}).inject(_element),
           _close = new Element('a', {'href': '#', 'class': opts.cls+'_close'}).inject(_inner),   
           _body =  new Element('div', {'class': opts.cls+'_body'}).inject(_inner);
       this._element.inject(_body);
       this._element = _element.inject(this._anchor, 'after');
       this._close = _close;
     }
         
     this._anchor.addEvent('click', this.handle_anchor_click.bind(this));
     this._close = this._close || _self.getElement('.'+opts.cls+'_close');
     if(this._close){
       this._close.addEvent('click', this.hide.bind(this));
     }
  },
  handle_anchor_click: function(e){
    if(e && e.stop){
      e.stop();
    }           
    if(!this.fx){
      this.fx =  new Fx.Scroll($(window), {link: 'cancel'});
    }
    
    this.show();
    this.fx.toElement(this._element);
  }, 
  show: function(){ 
    this._element.show();  
    this._anchor.addClass('_active');   
    var pos = this._anchor.getPosition(this._element.getParent());
    var dim = this._element.measure(function(){ return this.getSize();});  
    if(pos.y - dim.y < 0){
      this._element.setStyle('top', 0);         
    }else{
      this._element.setStyle('top', pos.y - dim.y);
    }
    this.fireEvent('show', this);   
  }, 
  hide: function(e){
    if(e && e.stop){
      e.stop();
    }          
    this._element.hide();  
    this._anchor.removeClass('_active'); 
    this.fireEvent('hide', this);
  }
});
/*
--- 
description: ContactForm
authors: 
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires: 
- core/1.3: '*'
provides: [ContactForm]
...
*/
var RequestQuoteForm = new Class
({
  Extends: ContactForm,
  build: function(){
    this.parent();
    
    var opts  = this.options,
        cls   = opts.cls,
        fcls  = '.'+cls,              
        _self = this._element,
        _form = this._form,
        _company_type = this._form.getElement('#company_type');
    /*
    if(_company_type){     
      this._company_type = _company_type;   
      var target_sel = _company_type.get('data-show-target');
      if(target_sel){   
        var _target = _self.getElement(target_sel);
        if(_target){    
          this._target = _target;
          _company_type.addEvent('change', this.handle_company_type_change.bind(this));
        }
      }
      
    }
    */
  },
  handle_company_type_change: function(e){
    if(!this._company_type){
      return;
    }
    
    var _selected = this._company_type.getSelected(),
        show = _selected.get('data-show-target');
    if(show.toString() == '1'){
      this._target.show();
    }else{
      this._target.hide();
    }         
    
    if(OverText != null){
      OverText.update();
    }
  }
});
var Rotate = new Class({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_rotate',
    delay: 10000
  },
  initialize: function(_element, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element; 
      this.build();
    }
  },
  build: function(){
    var opts = this.options,
        _self = this._element,
        _items = _self.getElements('.'+opts.cls+'_body ul li');
    if(_items.length > 1){
      _items.fade('hide')[0].fade('show');
    }      
    this._list = _self.getElements('.'+opts.cls+'_body ul');                 
    this._demo = _self.getElement('.'+opts.cls+'_demo') || new Element('a');       
              
    this._items = _items;
    this.current_index = -1; 
    this.play_next();
    
    this.timer = this.play_next.periodical((opts.delay || 3000), this);
  },
  play_next: function(){
    var cur_idx = this.current_index,
        total = this._items.length,
        next_idx = cur_idx < total - 1 ? cur_idx + 1 : 0,
        _next_item = this._items[next_idx]; 
          
    if(_next_item){   
      var _anchor = _next_item.getElement('a');
      if(_anchor){
        this._demo.set('href', _anchor.get('href')); 
        var title =  _anchor.get('title');
        if(title){
          this._demo.getFirst().set('text', title); 
        }else if(this._demo.getFirst()){
          this._demo.getFirst().set('text', 'View a Demo'); 
        } 
        
        var ga_data =  _anchor.get('data-ga-external-demo');
        this._demo.set('data-ga-external-demo', ga_data); 
        
      }
    }  
    var dim = _next_item.getSize();  
    this._list.setStyle('height', dim.y);
    
    if(cur_idx >= 0){
      this._items[cur_idx].fade('hide');           
    } 
    _next_item.fade('show');
    this.current_index = next_idx;  
   
  }
});
/*
--- 
description: Scrollshow
authors: 
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires: 
- core/1.3: '*'
provides: [Scrollshow]
...
*/
var Scrollshow = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_scrollshow'
  },
  initialize: function(_element, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element;
      this.build();
    }
  },
  build: function()
  {      
    var opts  = this.options,
        fcls  = '.'+opts.cls,
        _this = document.id(this);
        
    this.data = _this.getElement(fcls+'_data').get('text').toString().trim();
    
    this.views = [];
    this.active_view = null;
    
    this._strip = _this.getElement(fcls+'_strip_wrap');  
    
    
    this.remote = new Remote(
    {
      rpc: this.data,
      onSuccess: this.defer_build.bind(this)
    });
    
  },
  defer_build: function()
  {  
    var remote_data = this.remote.get_data();
    this.view_default   = new Scrollshow.View.Default(this.get_all_views_array(), this);    
    this.views.push(this.view_default);
          
    if(remote_data.views.property){
      this.view_property  = new Scrollshow.View.Property(remote_data.views.property, this); 
      this.views.push(this.view_property);   
    }
    if(remote_data.views.corporate){
      this.view_corporate = new Scrollshow.View.Corporate(remote_data.views.corporate, this);
      this.views.push(this.view_corporate);   
    }
    if(remote_data.views.ipad){
      this.view_ipad = new Scrollshow.View.IPad(remote_data.views.ipad, this);     
      this.views.push(this.view_ipad);                 
    }
    if(remote_data.views.email){
      this.view_email = new Scrollshow.View.EmailMarketing(remote_data.views.email, this);              
      this.views.push(this.view_email);                 
    }  
      
    if(remote_data.views.generic){
     this.view_generic = new Scrollshow.View.Generic(remote_data.views.generic, this);              
      this.views.push(this.view_generic);
      this.set_view.delay(300, this, this.view_generic);                 
    }else{
      this.set_view.delay(300, this, this.view_default);
    }   
     
    
    
    $(window).addEvent('resize', this.center_active_view.bind(this));
  },
  center_active_view: function()
  {
    if (this.active_view)
      this.active_view.center_view();
  },
  center_all_views: function()
  {
    this.views.each(function(view)
    {
      view.center_view();
    });
  },
  get_all_views_array: function()
  {
    var views = this.remote.get_data().views;    
    var arr = [];
    if(views.corporate){
      arr.include(views.corporate);
    }
    if(views.property){
      arr.include(views.property);
    }
    if(views.email){
      arr.include(views.email);
    }
    return arr;
  },
  get_strip: function()
  {
    return this._strip;
  },
  search_view_by_id: function(id)
  {
    var found_view = null;
    this.views.some(function(view)
    {
      if (view.options.identifier == id)
      {
        found_view = view;
        return true;
      }
      return false;
    });
    return found_view;
  },
  set_view: function(view)
  {
    if (view instanceof Scrollshow.View)
    {
      if (this.active_view)
      {
        this.clear_view(this.active_view);
      }
      this.active_view = view;
      view.show();
    }
  },
  set_view_by_id: function(id)
  {
    var view = this.search_view_by_id(id);
    if (view)
    {
      this.set_view(view);
    }
  },
  clear_view: function(view)
  {
    if (view instanceof Scrollshow.View)
    {
      view.hide();
    }
  },
  clear_view_by_id: function(id)
  {
    var view = this.search_view_by_id(id);
    if (view)
    {
      this.clear_view(view);
    }
  },
  toElement: function()
  {
    return this._element;
  }
});

Scrollshow.View = new Class
({
  Implements: [Events, Options],
  options:
  {
    identifier: null,
    cls: 'w_scrollshow_view'
  },
  initialize: function(data, scrollshow, options)
  {          
    this.setOptions(options);
    if (data)
    {
      this.data = data;
      this.scrollshow = scrollshow;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options;
    this.initialized = false;
    this.items = new Scrollshow.Items(this, this.scrollshow);
    
    this._element = new Element('div',
    {
      'class': opts.cls,
      styles: 
      {
        display: 'none'
      }
    }).inject(this.scrollshow.get_strip());
    
    if (typeOf(this.data) == 'array')
    {
      this.data = this.unify_views_items();
    }
  },
  center_view: function()
  {
    var window_w = $(document.body).getSize().x,
        item_midpoint = Math.floor(this.items.get_count() / 2),
        item_w = this.items.item_w,
        canvas_w = item_midpoint * item_w;
        
    if (canvas_w < window_w)
    {
      this._element.setStyles(
      {
        left: Math.floor(window_w/2)-Math.floor(canvas_w/2)
      });
    }
  },
  unify_views_items: function()
  {
    var ar = [];
    this.data.each(function(data_obj)
    {                         
      if(data_obj.items && data_obj.items.length){
        data_obj.items.each(function(item){
          if(item.featured){
            ar[item.featured.toInt()] = item;    
          }
        });
      }
    });   
    return { items: ar.filter(function(a){ return (a != null) }) };
  },
  create_thumbnails: function()
  {
    this.data.items.each(function(item)
    {
      this.items.push(
        new Scrollshow.Item(item, this, this.scrollshow)
      );
    }.bind(this));
    this.initialized = true;
  },
  hide: function()
  {
    this.items.leave();
    this._element.setStyles(
    {
      display: 'none'
    });
  },
  show: function()
  {
    this._element.setStyles(
    {
      display: 'block'
    });
    if (!this.initialized)
    {
      this.create_thumbnails();
    }
    this.center_view();
    this.items.enter();
  },
  toElement: function()
  {
    return this._element;
  },
  open_popup: function(item){
    var total = item.view.items.get_count();
    var current = item.view.items.items.indexOf(item); 
    if(!this.popup_view){
      this.popup_view = new Scrollshow.View.Popup(this);
    } 
    this.popup_view.show(item);
  } 
});  
Scrollshow.View.Generic = new Class({
   Implements: [Events, Options], 
   Extends: Scrollshow.View, 
   options:
   {
     cls: 'w_scrollshow_view_generic'
   },
  show: function()
  { 
    this._element.setStyles(
    {
      display: 'block'
    });
    if (!this.initialized)
    {
      this.create_thumbnails();        
      
      var ss = this.scrollshow,
          ss_opts = ss.options;
          
      var _btn = ss._element.getElement('.'+ss_opts.cls+'_launch_btn') || new Element('a', {'href': '#', 'text': 'Launch', 'class': ss_opts.cls+'_launch_btn'}).inject(ss._element);
      _btn.addEvent('click', this.open_first_popup.bind(this));
    }
  },
  open_first_popup: function(){  
    if(this.items && this.items.items && this.items.items[0]){
      this.open_popup(this.items.items[0]);
      if(!this.fx){
        this.fx = new Fx.Scroll($(window), {link: 'cancel'});              
      }  
      this.fx.toElement(this.popup_view._element);              
    }    
    return false;
  }
});

Scrollshow.View.Popup = new Class({
   Implements: [Events, Options], 
   options:
   {
     cls: 'w_scrollshow_view_popup'
   },                        
   initialize: function(view, options)
   {
      this.setOptions(options);
      this.view = view; 
      this.el_id = (('popup '+this.view.options.identifier).replace(' ', '-').camelCase() || 'popupGeneric');
      this.build();
    }, 
    build: function(){
      var opts = this.options,
          cls = opts.cls,
          _body = $(document.body);  
      this._veil = _body.getElement('.'+cls+'_veil') || this.build_veil().inject(_body);
      this._veil.addEvent('click', this.hide.bind(this));
      this._element = _body.getElement('div[data-view='+this.el_id+']') || this.build_element() || new Element('div');  
      if(Core.is_ipad){
         $(window).addEvent('orientationchange', this.handle_ipad_orientation_change.bind(this));
         this.handle_ipad_orientation_change();
      }
    },   
    handle_ipad_orientation_change: function(){
      var d = document,
          h = Math.max(Math.max(d.body.scrollHeight, d.documentElement.scrollHeight), Math.max(d.body.offsetHeight, d.documentElement.offsetHeight), Math.max(d.body.clientHeight, d.documentElement.clientHeight));
      this._veil.setStyle('height', h);
    },
    build_veil: function(){
      var opts = this.options,
          cls = opts.cls,
          _el = new Element('div', {'class': cls+'_veil'});        
      return _el.addClass('_inactive').fade('hide');
    },
    build_element: function(){
      var opts = this.options,
          cls = opts.cls,
          _el = new Element('div', {'class': cls, 'data-view':this.el_id}),
          _inner = new Element('div', {'class': cls+'_inner'}),
          _content_wrapper = new Element('div', {'class': cls+'_content_wrapper'}).inject(_inner),
          _nav = new Element('div', {'class': cls+'_nav'}).inject(_inner),                        
            _next_btn = new Element('a', {'href': '#', 'class': cls+'_nav_next', 'text': 'Next'}).inject(_nav),
            _prev_btn = new Element('a', {'href': '#', 'class': cls+'_nav_prev', 'text': 'Previous'}).inject(_nav),
          _caption = new Element('div', {'class': cls+'_caption'}).inject(_inner),
          _link = new Element('a', {'href': '#', 'class': cls+'_link w_juicy tk-primary', 'target': '_blank', 'html': '<span class="w_juicy_wrap">View Website</span>'}).inject(_inner),
          _mobile_link = new Element('a', {'href': '#', 'class': cls+'_mobile_link w_juicy tk-primary', 'target': '_blank', 'html': '<span class="w_juicy_wrap">View Mobile Version</span>'}).inject(_inner),
          _close = new Element('a', {'href': '#', 'class': cls+'_close', 'text': 'Close'}).inject(_inner);
      

      _inner.inject(_el);   
      _el.inject($(document.body));
      this._content_wrapper = _content_wrapper;
      this.items = [];                            
      this.view.items.items.each(function(item){
        this.items.include( new Scrollshow.View.Popup.Item(item, this, {'onBuild': this.extent_content_wrapper.bind(this)}) );
      }.bind(this));
      
      this._caption = _caption;
      this._link = _link.fade('hide'); 
      this._mobile_link = _mobile_link.fade('hide');
      this._close = _close.addEvent('click', this.hide.bind(this));
      this._next_btn = _next_btn.addEvent('click', this.show.bind(this, ['next']));
      this._prev_btn = _prev_btn.addEvent('click', this.show.bind(this, ['prev']));    
      if(this.view.data.items.length <= 1 && this.view.data.items[0].images.length <= 1){
        _nav.hide();
      }
      
      if(Gv.site){     
         this._link.addEvent('click', Gv.site.handle_ga_demo_track.bind(Gv.site) );   
         this._mobile_link.addEvent('click', Gv.site.handle_ga_demo_track.bind(Gv.site) );       
      } 
      _el.addClass('_inactive');
      if(Core.isIE()){
         return _el.hide();
      }else{
         return _el.fade('hide');
      }
      
    },      

    extent_content_wrapper: function(popup_item, _el){
      _el.hide().inject(this._content_wrapper);   
    },
    hide: function(e){
      if(e && e.stop){
        e.stop();
      } 
      this._veil.addClass('_inactive').fade('hide');
      this._element.addClass('_inactive');
      if(Core.isIE()){
         this._element.hide();
      }else{
         this._element.fade('hide'); 
      }
      if(this.current_item){
        this.current_item.hide();
      }
    },   
    show: function(what, from_index){ 
      if(this.current_index == null){
        this.current_index = 0;
      }
      if(what == 'next'){       
        var ind = this.current_index,  
            total = this.items.length,
            set = this.current_item || this.items[0],
            set_ind = set.current_index,
            set_total = set.get_total();
        
        if(set_ind < set_total - 1){
           set.go_to_image_index(set_ind+1);
        }else{
          // next set
          ind = ind+1;   
          if(ind >= 0 && ind <= total - 1){
            this.show(this.items[ind], 0);  
          }else if(ind > total - 1) {
            this.show(this.items[0], 0);  
          }
        }
      }else if(what == 'prev'){
        var ind = this.current_index,  
            total = this.items.length,
            set = this.current_item || this.items[0],
            set_ind = set.current_index,
            set_total = set.get_total();
      
        if(set_ind <= 0){
          // go to previous set
          if(ind > 0){
            this.show(this.items[ind-1], this.items[ind-1].get_total() - 1);  
          }else{
            this.show(this.items[total-1], this.items[total-1].get_total() - 1);     
          }
        }else{
          set.go_to_image_index(set_ind-1);    
        } 
        
            
      }else if(what instanceof Scrollshow.Item){
        var ind = this.view.items.items.indexOf(what);
        if(ind >= 0 && ind <= this.view.items.get_count() - 1){     
          this.show(this.items[ind]);  
        }
      }else if(what instanceof Scrollshow.View.Popup.Item){     
        var ind = this.items.indexOf(what);   
        if(ind >= 0 && ind <= this.items.length - 1){  
          if(this.current_index != null){
            this.items[this.current_index]._element.hide();
          }
          this.current_index = ind;     
          //this.check_nav();                                   
          this.update_caption(what.item);
          this.update_link(what.item); 
          if(this.current_item){
            this.current_item.hide();
          } 
          this.current_item = what;
          what.show(from_index)._element.show();
        }
      } 
      this._veil.removeClass('_inactive').fade('in');
      if(Core.isIE()){
         this._element.removeClass('_inactive').show();  
      }else{
         this._element.removeClass('_inactive').fade('in');  
      }
      
      return false;  
    },
    update_link: function(item){
      var link = item.data.url || '#';
      this._link.set('href', link);
      
      if(link != '#'){
        this._link.fade('in');
      }else{
        this._link.fade('out');
      } 
      
      var mobile_link = item.data.mobile_url || "#";
      this._mobile_link.set('href', mobile_link);     
      if(mobile_link != '#'){
        this._element.addClass('_has_mobile');
        this._mobile_link.fade('in');
      }else{
        this._element.removeClass('_has_mobile');
        this._mobile_link.fade('out');
      }
      
    },
    update_caption: function(item, description){                
       var opts = this.options,
           cls = opts.cls,
           _title = new Element('h2', {'class':cls+'_caption_title tk-primary', 'text': (item.data.title || this.view.options.identifier || '')}),
           _text = new Element('div', {'class':cls+'_caption_text', 'html': (description || item.data.description || '')})
       _text.inject(this._caption.empty().grab(_title));
    },
    check_nav: function(){                  
      var ind = this.current_index,
          __disabled = 'disabled';
      if(ind <= 0){
        this._prev_btn.addClass(__disabled);
      }else{
        this._prev_btn.removeClass(__disabled);
      }                      
      if(ind >= this.items.length - 1){
        this._next_btn.addClass(__disabled);
      }else{
        this._next_btn.removeClass(__disabled);
      }                      
    },
    get_content_wrapper: function(){
      return this._content_wrapper;
    }
}); 
Scrollshow.View.Popup.Item = new Class({
   Implements: [Events, Options], 
   options:
   {
     cls: 'w_scrollshow_view_popup_item',
     delay: 5000
   },                                  
   initialize: function(item, popup, options)
   {
      this.setOptions(options);
      this.item = item;
      this.popup = popup; 
      this.build();
    }, 
    build: function(){
      var opts = this.options,
          cls = opts.cls;
      this._element = new Element('div', {'class': cls}); 
      this.fireEvent('build', [this, this._element]);
    },
    show: function(index){
      if(this.built != true){  
        this.defer_build();
      } 
      this.go_to_image_index( (index || 0) ); 
      return this;
    },   
    hide: function(){   
       //this.block_auto_play = false;
       //clearTimeout(this.timer);
    },
    defer_build: function(){
      if(!this.item || !this.item.data || !this.item.data.images){
        return;
      }
      var opts = this.options,                             
          cls = opts.cls,
          _self = this._element,
          _pagination = new Element('div', {'class': cls+'_pagi'}),
          _stage = new Element('div', {'class': cls+'_stage'}).inject(_self),
          
          data = this.item.data,
          _first_anchor = null,
          single_width = 0;
          this._items = [];
          this._anchors = [];
      data.images.each(function(image, i){   
         var _item = new Element('div', {'class': cls+'_image ' + (image.item_cls || '')}).inject(_stage); 
         var _img = new Element('img', {'src':image.src}).inject(_item);
         this._items.include(_item);
         var _a = new Element('a', {'href':'#', 'html':"&nbsp;", 'title': (i+1), 'data-index':i} ).inject(_pagination);
         this._anchors.include(_a);
         if(i == 0){
           _first_anchor = _a;
         }
         _a.addEvent('click', this.go_to_image.bind(this) );
      }.bind(this));        
      if(data.images.length <= 1){
        _pagination.hide();
      }
      this.built = true;     
    },
    go_to_image: function(e){
      if(e && e.stop){
        e.stop();
      }
      var _target = $(e.target);                                     
      this.block_auto_play = true;
      this.go_to_image_index(_target.get('data-index').toInt());
    },
    go_to_image_index: function(ind){
      if(this.current_index != null && this._anchors[this.current_index]){    
        this._anchors[this.current_index].removeClass('active');  
        this._items[this.current_index].hide();
      } 
      this.current_index = ind;                      
      this._anchors[this.current_index].addClass('active');  
      this._items[this.current_index].fade('hide').show().fade('in');   
      this.popup.update_caption(this.item, (this.item.data.images[this.current_index].description));          
    },
    get_total: function(){  
      if(!this._items){
        this.defer_build();
      }
      return this._items.length;
    }
});
Scrollshow.Items = new Class
({
  Implements: Events,
  initialize: function(view, scrollshow)
  {
    if (view)
    {
      this.view       = view;
      this.scrollshow = scrollshow;
      
      this.build();
    }
  },
  build: function()
  {
    this.items = [];
    
    this.item_w = 300;
    this.item_h = 220;
    this.delayed = 70;
    this.is_computed = false;
    this.col_1_offset_x;
    this.col_1_offset_y = 20;
    this.col_2_offset_x;
    this.col_2_offset_y = this.item_h + this.col_1_offset_y + 0;
  },
  compute: function()
  {
    this.is_computed = true;
  },
  enter: function()
  {
    if (!this.is_computed)
      this.compute();

    var len = this.items.length,
        mid = Math.ceil(len/2);
        
    // Series moves 0,1,4,2,5,3,6,7
    this.items.each(function(item, i)
    {
      var w  = this.item_w,
          h  = this.item_h;
      
      j = (i < mid) ? i : i-mid;
      k = (i < mid) ? i : i-mid+1;
          
      x = w*j;
      y = (i < mid) ? this.col_1_offset_y : this.col_2_offset_y;
      delay = this.delayed * k * Math.sqrt(k);

      item.flip_to(x, y, delay);
    }.bind(this));
/*  
    // Serie moves 0,1,3,5,2,4,6,7
    this.items.some(function(item, i)
    {
      if (i < mid)
      {
        var incrementor = (i - 1 < 0) ? 0 : i - 1,
            delay_pointer = i + incrementor;

        var w  = this.item_w,
            h  = this.item_h;
          
        var k = (i < mid) ? i : i-mid;
            
        x = w*k;
        y = this.col_1_offset_y;
        delay = this.delayed * delay_pointer * Math.sqrt(delay_pointer);
        
        item.flip_to(x, y, delay);
        
        // For 2nd column element
        var j = i + mid;
        incrementor = (mid-i-2 < 0) ? 0 : (mid-i-2);

        delay_pointer = j - incrementor;
        
        x = w*k;
        y = this.col_2_offset_y;
        delay = this.delayed * delay_pointer * Math.sqrt(delay_pointer);
        
        this.items[j].flip_to(x, y, delay);
        
        return false;
      }
      return true;
    }.bind(this));
*/
/*  
    // Serie moves 0,1,2,3,4,5,6,7
    this.items.each(function(item, i)
    {
      var w  = this.item_w,
          h  = this.item_h;
          
      j = (i < mid) ? i : i-mid;
          
      x = w*j;
      y = (i < mid) ? this.col_1_offset_y : this.col_2_offset_y;
      delay = this.delayed * i * Math.sqrt(i);
      
      item.flip_to(x, y, delay);
    }.bind(this));
*/
  },
  leave: function()
  {
    this.items.each(function(item, i)
    {
      item.hide();
    });
  },
  cancel: function()
  {
    this.items.each(function(item)
    {
      clearTimeout(item.timer);
    });
  },
  push: function(item)
  {
    this.items.push(item);
  },
  get_count: function()
  {
    return this.items.length;
  }
});

Scrollshow.View.Default = new Class
({
  Extends: Scrollshow.View,
  options:
  {
    identifier: 'Default'
  }
});

Scrollshow.View.Property = new Class
({
  Extends: Scrollshow.View,
  options:
  {
    identifier: 'Property Websites'
  }
});
Scrollshow.View.Corporate = new Class
({
  Extends: Scrollshow.View,
  options:
  {
    identifier: 'Corporate Websites'
  }
});

Scrollshow.View.IPad = new Class
({
  Extends: Scrollshow.View,
  options:
  {
    identifier: 'iPad Leasing Apps',
    item_cls: '_ipad'
  },
  create_thumbnails: function()
  {
    this.data.items.each(function(item)
    {
      this.items.push(
        new Scrollshow.Item(item, this, this.scrollshow, {'additional_cls': '_ipad'})
      );
    }.bind(this));
    this.initialized = true;
  }
});

Scrollshow.View.EmailMarketing = new Class
({
  Extends: Scrollshow.View,
  options:
  {
    identifier: 'Email Marketing'
  }
});

Scrollshow.Item = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_scrollshow_item',
    additional_cls: ''
  },
  initialize: function(data, view, scrollshow, options)
  {
    this.setOptions(options);
    if (data)
    {
      this.data       = data;
      this.view       = view;
      this.scrollshow = scrollshow;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        _view = document.id(this.view),
        data = this.data;
    
    this._element = new Element('div',
    {
      'class': opts.cls + ' ' + opts.additional_cls,
      styles:
      {
        opacity: 0
      }
    }).inject(_view);
    
    this._anchor = new Element('a',
    {
      'class': opts.cls+'_anchor',
      'href': data.url
    }).inject(this._element);
    
    this._element.addEvent('click', this.handle_click.bind(this));
    
    this._image = new Element('img',
    {
      src: data.src
    }).inject(this._anchor);
    
    this.fx_element = new Fx.Morph(this._element, {duration: 300, link: 'cancel'});  
  },
  hide: function()
  {
    this.fx_element.cancel();
    clearTimeout(this.timer);
    this._element.removeClass('flip');
    this._element.setOpacity(0);
  },  
  handle_click: function(e){
    if(e && e.stop){
      e.stop();
    }                                                 
    this.view.open_popup(this);
  },
  flip_to: function(x, y, delayed)
  {
    this.timer = (function()
    {
      this._element.addClass('flip');
      this.fx_element.start(
      {
        opacity: 1,
        left: [x-20, x],
        top: [y-20, y]
      });
    }.delay(delayed, this));
  }
});
/*
--- 
description: Show
authors: 
- David Chan CK (http://www.reol.com)
license:
- MIT-style license
requires: 
- core/1.3: '*'
provides: [Show]
...
*/
var Show = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_show'
  },
  initialize: function(_element, options)
  {
    this.setOptions(options);
    if (_element)
    {
      this._element = _element;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        fcls  = '.'+opts.cls,
        _this = document.id(this);
    
    var _data = _this.getElement(fcls+'_data');    
    if(_data){
      this.data = _data.get('html').trim();
    }
    
    this.is_first = true;
    this.pagination = null;
    
    if(this.data){
      this.remote = new Remote(
      {
        rpc: this.data,
        onSuccess: this.defer_build.bind(this, this.remote.get_data())
      });
    }
  },
  defer_build: function(data)
  {
    if (data)
    {  
      var opts = this.options;
      this.rpc_data = data;        
      if(!data.item_per_page){
        data.item_per_page = opts.item_per_page || 6;        
      }  
      if(!data.num_pages){
        data.num_pages = Math.ceil(data.items.length/data.item_per_page);
      } 
      //if (data.num_pages > 1)
      //{
        this.pagination = new Show.Pagination(this);
      //}
      this.thumbs   = new Show.Thumbs(data.items, this);
      this.stage    = new Show.Stage(data.items, this);
      this.caption  = new Show.Caption(data, this);
      
      if (this.pagination)
        this.pagination.set_page(0);
      else
        this.thumbs.set_position(null, 0);
      this.caption.open();
      this.set_image.delay(300, this, 0);
    }
    else
    {
      console.log('error with data: '+data);
    }
  },
  set_image: function(index)
  {
    this.thumbs.set_thumb(this.thumbs.get_thumb_by_index(index));
    this.stage.set_image_by_index(index);       
    
    if(this.pagination && this.pagination.fx){  
      //if(this.pagination.current_page_index < this.rpc_data.num_pages - 1 && (index+1)%this.rpc_data.item_per_page == 0 )
      this.pagination.set_page(this.pagination.current_page_index);
    }
    
    
    
  },
  toElement: function()
  {
    return this._element;
  }
});

Show.Caption = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_show_caption'
  },
  initialize: function(data, show, options)
  {
    this.setOptions(options);
    if (show)
    {
      this.data = data;
      this.show = show;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        cls   = opts.cls,
        fcls  = '.'+cls,
        data  = this.data,
        _this;
    this._element = document.id(this.show).getElement(fcls) || new Element('div', {'class': cls, 'html': (data.caption || '') }).inject( document.id(this.show));
    
    if(data.url){
      var text = data.url_text || data.url.toString().replace(/http[s]?:\/\//i, "");
      var _link = new Element('a', {'class':cls+'_link', 'text': text, 'href': data.url, 'target':'_blank'}).inject(this._element, 'after');
    }
    
  },
  open: function()
  {
    this._element.addClass('active');
  },
  toElement: function()
  {
    return this._element;
  }
});

Show.Pagination = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_show_pagination'
  },
  initialize: function(show, options)
  {
    this.setOptions(options);
    if (show)
    {
      this.show = show;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        cls   = opts.cls,
        data  = this.show.rpc_data,
        _this;
        
    this.items = [];
    this.thumbs = null;
    this.current_page_index = 0;
    this.item_per_page = data.item_per_page;
    
    _this = this._element = new Element('div',
    {
      'class': cls
    }).inject(document.id(this.show));
    
    this._next = new Element('a', {'href': '#', 'class':cls+'_next', 'html': 'Next', 'title': 'Next'}).inject(_this);
    this._previous = new Element('a', {'href': '#', 'class':cls+'_previous', 'html': 'Previous', 'title': 'Previous'}).inject(_this);
    this._next.addEvent('click', this.go_next_page.bind(this));
    this._previous.addEvent('click', this.go_previous_page.bind(this));
    
    this._wrap = new Element('div',
    {
      'class': cls+'_wrap'
    }).inject(_this);       
    
    if(data.num_pages > 1){
      data.num_pages.times(function(i)
      {
        var item = new Element('div',
        {
          'class': cls+'_item',
          events:
          {
            click: this.set_page.bind(this, i)
          }
        }).inject(this._wrap);
      
        if (i == data.num_pages-1)
        {
          item.addClass('last');
        }
      
        this.items.push(item);
      }.bind(this));  
    } 
    this.reposition();  
    this.check_nav();   
  },
  get_current_page_index: function()
  {
    return this.current_page_index;
  },
  reposition: function()
  {
    var width = this._element.getSize().x,
        wrap_width = this._wrap.getSize().x,
        new_center = Math.floor(width/2 - wrap_width/2);
        
    this._wrap.setStyles(
    {
      visibility: 'visible',
      left: new_center,
      opacity: 1
    });
  },   
  go_next_page: function(e){
    if(e && e.stop){
      e.stop();
    }       
    if(this._next.hasClass('_disabled')){
      return;
    }
    var page_index = this.get_current_page_index() + 1; 
    if(page_index >= this.items.length){
      page_index = 0;
    }            
    
    var item_index = page_index*this.item_per_page;
    this.show.thumbs.set_thumb(this.show.thumbs.get_thumb_by_index(item_index));    
    this.show.set_image(item_index); 
    this.set_page(page_index);   
  },  
  go_previous_page: function(e){
    if(e && e.stop){
      e.stop();
    }    
    if(this._previous.hasClass('_disabled')){
      return;
    }                       
    var page_index = this.get_current_page_index() - 1;
    
    if(page_index < 0){
      page_index = this.items.length - 1;
    }
        
    var item_index = page_index*this.item_per_page;
    this.show.thumbs.set_thumb(this.show.thumbs.get_thumb_by_index(item_index));    
    this.show.set_image(item_index);
    this.set_page(page_index);   

  }, 
  set_page: function(page)
  { 
    if(!this.items || this.items.length <= 0){
      return;
    }   
    this.items[this.current_page_index].removeClass('selected');
    this.current_page_index = page;
    if (!this.thumbs)
    {
      this.thumbs = this.show.thumbs.get_overflow();
      this.fx = new Fx.Scroll(this.thumbs, { link: 'cancel', duration: 400 });
      this.fx.set(0);
    }
    var item_index = page*this.item_per_page;
    this.items[page].addClass('selected');               
    this.fx.toElement(this.show.thumbs.get_thumb_by_index(item_index));    
    this.check_nav();
  },      
  check_nav: function(){
     var page_index = this.get_current_page_index();        
     var __disabled = '_disabled';
     if(page_index <= 0){
       this._previous.addClass(__disabled);
     }else{
       this._previous.removeClass(__disabled);
     }
     if(page_index >= this.items.length - 1){
        this._next.addClass(__disabled)
     }else{
        this._next.removeClass(__disabled);
     }          
   
  },
  toElement: function()
  {
    return this._element;
  }
});

Show.Thumbs = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_show_thumbs'
  },
  initialize: function(data, show, options)
  {
    this.setOptions(options);
    if (show)
    {
      this.data = data;
      this.show = show;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        cls   = opts.cls,
        data  = this.data,
        _this;
        
    this.items = [];
    
    _this = this._element = new Element('div',
    {
      'class': cls
    }).inject(document.id(this.show));
 
    this._wrap = new Element('div',
    {
      'class': cls+'_wrap'
    }).inject(_this);
    
    this._selector = new Element('div',
    {
      'class': cls+'_selector'
    }).inject(this._wrap);
    
    this.fx_selector = new Fx.Morph(this._selector, { link: 'cancel', fps: 60, duration: 300 });
    
    data.each(function(item_data, i)
    {
      this.items.push(new Show.Thumb(item_data, i, this, this.show));
    }.bind(this));
  },
  get_container: function()
  {
    return this._wrap;
  },
  get_overflow: function()
  {
    return this._element;
  },
  get_thumb_by_index: function(index)
  {
    return this.items[index];
  },
  set_position: function(x, y)
  {
    if (x !== null)
      this._element.setStyle('left', x);
    if (y !== null)
      this._element.setStyle('top', y);
  },
  set_thumb: function(thumb)
  {
    var offset_pos = document.id(thumb).getOffsetParent().getPosition(),
        pos = document.id(thumb).getPosition();
    
    var pos_x = pos.x - offset_pos.x,
        pos_y = pos.y - offset_pos.y;
    
    var current_page = (this.show.pagination) ? this.show.pagination.get_current_page_index() : 0,
        thumbs_width = this._element.getSize().x+2,
        offset_x = current_page*thumbs_width;
    
    this.fx_selector.start(
    {
      left: pos_x+offset_x
    });
    this._selector.setStyles(
    {
      top: pos_y,
      visibility: 'visible'
    });
  },
  toElement: function()
  {
    return this._element;
  }
});

Show.Thumb = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_show_thumb'
  },
  initialize: function(data, index, show_thumbs, show, options)
  {
    this.setOptions(options);
    if (show)
    {
      this.data = data;
      this.index = index;
      this.show_thumbs = show_thumbs;
      this.show = show;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        cls   = opts.cls,
        data  = this.data,
        _this;

    _this = this._element = new Element('div',
    {
      'class': cls,
      events:
      {
        //click: this.show_thumbs.set_thumb.bind(this.show_thumbs, this)
        click: this.show.set_image.bind(this.show, this.get_index())
      }
    }).inject(this.show_thumbs.get_container());
    
    this._img = new Element('img',
    {
      src: data.thumb
    }).inject(_this);
  },
  get_index: function()
  {
    return this.index;
  },
  toElement: function()
  {
    return this._element;
  }
});

Show.Stage = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_show_stage'
  },
  initialize: function(data, show, options)
  {
    this.setOptions(options);
    if (show)
    {
      this.data = data;
      this.show = show;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        cls   = opts.cls,
        data  = this.data,
        _this;
    
    this.active_item = null;
    this.items = [];
    this.times_accessed = 0;
    this.is_preloaded = false;
    
    new Element('div',
    {
      'class': 'clear'
    }).inject(document.id(this.show));
    
    _this = this._element = new Element('div',
    {
      'class': cls
    }).inject(document.id(this.show));
    
    this._wrap = new Element('div',
    {
      'class': cls+'_wrap'
    }).inject(_this);

    data.each(function(item_data, i)
    {
      this.items.push(new Show.StageItem(item_data, this, this.show));
    }.bind(this));
  },
  preload: function()
  {
    var current_page_index = (this.show.pagination) ? this.show.pagination.current_page_index : 0,
        item_per_page      = this.data.item_per_page;
    
    if (!this.is_preloaded && this.times_accessed > 1)
    {
      //console.log('preloading first active page');
      this.is_preloaded = true;
      this.items.some(function(item, i)
      {
        if (i == 0)
          return false;

        if (current_page_index*item_per_page < i && (current_page_index+1)*item_per_page > i)
          item.preload.delay(300*i, item);
      });
    }
  },
  get_container: function()
  {
    return this._wrap;
  },
  set_image: function(item)
  {
    if (this.active_item)
    {
      this.active_item.close();
    }
    this.active_item = item;
    item.open();
    item.set_image();
    this.preload.delay(1000, this);
    this.times_accessed++;
  },
  set_image_by_index: function(index)
  {
    this.set_image(this.items[index]);
  },
  toElement: function()
  {
    return this._element;
  }
});

Show.StageItem = new Class
({
  Implements: [Events, Options],
  options:
  {
    cls: 'w_show_stage_item'
  },
  initialize: function(data, stage, show, options)
  {
    this.setOptions(options);
    if (show)
    {
      this.data = data;
      this.stage = stage;
      this.show = show;
      this.build();
    }
  },
  build: function()
  {
    var opts  = this.options,
        cls   = opts.cls,
        data  = this.data,
        _this;

    this.is_loaded = false;

    _this = this._element = new Element('div',
    {
      'class': cls
    }).inject(this.stage.get_container());
    this.width = this._element.getSize().x;
    this.fx = new Fx.Morph(document.id(this), { link: 'cancel', duration: 320 });
  },
  close: function()
  {
    document.id(this).removeClass('active');
    this.fx.start(
    {
      opacity: 0,
      left: -this.width
    });
  },
  preload: function()
  {
    Asset.image(this.data.stage);
  },
  load_image: function()
  {
    Asset.image(this.data.stage,
    {
      onLoad: function(img)
      {                  
        this.is_loaded = true;
        this.set_image();
      }.bind(this)
    });
  },
  open: function()
  {
    if (this.show.is_first)
    {
      this.show.is_first = false;
      this._element.setStyles
      ({
        visibility: 'visible',
        opacity: 1
      });
      document.id(this).addClass('shadow');
      return;
    }
    
    document.id(this).removeClass('shadow');
    document.id(this).addClass('active');
    
    this._element.setStyles
    ({
      visibility: 'visible',
      opacity: 0.1
    });
    
    this.fx.start(
    {
      opacity: 1,
      left: [this.width, 0]
    }).chain(function()
    {
      document.id(this).addClass('shadow');
    }.bind(this));
  },
  set_image: function()
  {
    if (!this.is_loaded)
      this.load_image();
    else
    {    
      var _el = document.id(this);
      if (!this._image)
      {
        this._image = new Element('img',
        {
          src: this.data.stage
        }).inject(_el);
      } 
      this.stage._element.setStyle('height', _el.getSize().y);
    }
  },
  toElement: function()
  {
    return this._element;
  }
});
/*
 * FED - REOL
 * Copyright 2010. All rights reserved.
 *
 * Main Entry Point
 */
window.addEvent('domready', function(){
  var site = new Site(); 
  Gv.site = site;
});


