var GMX = { //global application object



 // utility to scroll page, useful when doing animations

 scroll: {

  top: function(event) { new Effect.ScrollTo('header'); },

  bottom: function(event) { new Effect.ScrollTo('footer'); },

  details: function(event) { new Effect.ScrollTo($$('a.button-view-details').first()); }

 },



 // details object

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

 details : {

  setup: function() {

   var details_btn = $$('a.button-view-details').first();

   if(!details_btn) return;

   details_btn.observe('click',function(event){

    Event.stop(event);

    if ($('details').visible()) {

     GMX.player.open();

     GMX.episodes_navigation.open();

     // give time to player and navigation episodes to open

     setTimeout(function() { GMX.details.close(); }, 300);

    } else {

     GMX.scroll.top();

     // give time to scroll top

     setTimeout(function() {

      GMX.player.close();

      GMX.episodes_navigation.close();

      GMX.details.open();

     }, 1000);

    }

   });

  },

  open: function() {

   $$('a.button-view-details').first().addClassName('on');

   Effect.BlindDown('details',{duration:0.8, afterFinish: function() {

    GMX.scroll.details();

    //GMX.carousels.setup();



    //Initialize the detail box carousels

    var detail_c_carousel = new GMX.Carousel('detail-c-carousel',{

     url:'data/get_ajax_template.php?template=xml/titles/awards/index.htm'

    });

    var detail_d_carousel = new GMX.Carousel('detail-d-carousel',{

     url:'data/get_ajax_template.php?template=xml/titles/deal/index.htm'

    });



    $('details').setStyle({display:'block'});

    }

   });



  },

  close: function() {

   $$('a.button-view-details').first().removeClassName('on');

   // give time to scroll top

   GMX.scroll.top();

   setTimeout(function() { Effect.BlindUp('details',{duration:0.8}); }, 1000);

  }

 },





 // faq - show/hide faq answer

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

 faq: {

  setup: function() {



   // add click event to expand button

   $('faq-button-expand').observe('click',function(event){

    Event.stop(event);

    // show answer

    $$('.text li').each(function(el){

     el.addClassName('selected');

    });

   });



   // add click event to collapse button

   $('faq-button-collapse').observe('click',function(event){

    Event.stop(event);

    // hide answer

    $$('.text li').each(function(el){

     el.removeClassName('selected');

    });

   });



   // add click event to all questions

   $$('.text a.question').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      var container = el.up();

      // show / hide answer

      if(container.hasClassName('selected')) {

       container.removeClassName('selected');

      } else {

       container.addClassName('selected');

      }

     });

    }

   );

  }

 },





 // more bio button - show more bio info in team page

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

        more_bio: {

  setup: function() {

   // add click event to all button

   $$('.staff-item a.show-bio').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      var container = el.up();

      // add class to show more bio info

      container.addClassName('more-bio');

     });

    }

   );

  }

 },



 // utility methods for global site usage

 utility: {

	   ie: {

		   pngfix: function(){

			if(Prototype.Browser.IE){

			 //Fix IE pngs via an added class (ie-fix-opacity)

			 $$('.pngfix').each(function(el){

			  var bg = el.currentStyle.backgroundImage;

			  var img = bg.substring(bg.indexOf('"') + 1, bg.lastIndexOf('"'));

			  el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img + "', sizingMethod='scale')";

			  el.style.backgroundImage = "none";

			 });

			}

		   },



		  btnfix: function(){

			if(Prototype.Browser.IE){

				$$('button.blue-btn').each(function(el){

					el.observe('mousedown', function(){

						el.style.backgroundPosition = "1 2px";

					});

				});



				$$('button.blue-btn').each(function(el){

					el.observe('mouseup', function(){

						el.style.backgroundPosition = "0 1px";

					});

				});



				$$('button.green-btn').each(function(el){

					el.observe('mousedown', function(){

						el.style.backgroundPosition = "1 2px";

					});

				});



				$$('button.green-btn').each(function(el){

					el.observe('mouseup', function(){

						el.style.backgroundPosition = "0 1px";

					});

				});



			}

		}

	}

},





 // options object

 options:{

  // last dropdown openned

  last_option: null,

  // main dropdown object

  dropdown: null,

  // timeout to out event

  timeout: null,

  timeout_over: null,

  current_option:null,

  // out event

  out: function() {

   // cleartimeout

   clearTimeout(GMX.options.timeout);

   // show hidden options button

   if(this.last_option) this.last_option.removeClassName('dropdown-options-on');

   // hide dropdown menu

   if(this.dropdown) this.dropdown.hide();

   this.current_option=null;

  },

  // over event

  over: function(el) {

   // out event to close openned dropdowns

   GMX.options.out();

   // if this option button is on, quit

   if(el.hasClassName('dropdown-options-on')) return;

   this.current_option=el;

   // remove light gray layout

   this.dropdown.removeClassName('dropdown-options-light');

   // if this option button is light gray, apply light gray layout to droddown

   if(el.hasClassName('dropdown-options-light')) this.dropdown.addClassName('dropdown-options-light');

   // set droddown position

   var pos = el.cumulativeOffset();

   var margin_top = el.getStyle('margin-top').split('px').join('');

   this.dropdown.setStyle({left:pos.left+'px',top:pos.top-margin_top+'px'});

   // hide this option button

   el.addClassName('dropdown-options-on');

   // show dropdown

   this.dropdown.show();

   // save option button

   this.last_option = el;

   // add over event to clear out timeouts

   this.dropdown.stopObserving('mouseover');

   this.dropdown.observe('mouseover',function(event){

    Event.stop(event);

    clearTimeout(GMX.options.timeout);

   });

   // add out events

   this.dropdown.stopObserving('mouseout');

   this.dropdown.observe('mouseout',function(event){

    Event.stop(event);

    clearTimeout(GMX.options.timeout);

    // ou mouseout, add timeout to close option drodown

    GMX.options.timeout = setTimeout(function() {

     GMX.options.out();

    }, 100);

   });

   // add click event to each link child of the dropdown, gets id from option button: <div class="dropdown-options" id="options-123" />

   $$('div.options-content a').each(function(item){

    item.observe('mouseover', function(){

     item.addClassName('over-light');



    });

    item.observe('mouseout', function(){

     item.removeClassName('over-light');

    });

   });



  },

  // setup object

  setup: function() {

   GMX.options.out();

   // add over event to all option buttons

   $$('#main div.dropdown-options').each(

    function(el){

     el.stopObserving('mouseover');

     el.observe('mouseover',function(event){

      Event.stop(event);

      GMX.options.timeout_over = setTimeout( function() {

       clearTimeout(GMX.options.timeout_over);

       GMX.options.over(el);

      },300 );



     });

     el.observe('mouseout',function(event){

      Event.stop(event);

      clearTimeout(GMX.options.timeout_over);

     });

    }

   );

   if(!this.dropdown) {



    this.dropdown = $('options-dropdown-div');

    // hide it
    if(this.dropdown){
    this.dropdown.hide();
    }

   }

  }

 },



 // updates setup

 updates:{

  setup: function() {

   // add click event to each updates more buttom

   $$('#main .sidebar .updates a.more').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // if container visible, close, if not, open

      var container = el.up();

      if(container.hasClassName('updates-on')) {

       container.removeClassName('updates-on');

      } else {

       container.addClassName('updates-on');

      }

     });

    }

   );

  }

 },



 // side_bar setup

        // Note - This latest code merge should work.  If it does not, revert

        // side_bar back to previous version and lock this object down.

 side_bar:{

  // expand all sections

  expandAll: function() {

   $$('#main .sidebar-navigation .section').each(

    function(el) {

     el.addClassName('section-on');

    }

   );

  },

  // collapse all sections

  collapseAll: function() {

   $$('#main .sidebar-navigation .section').each(

    function(el) {

     el.removeClassName('section-on');

    }

   );

  },

  openSection: function(clsNameSection){

	$$('div.sidebar-navigation div.section').each(function(item){

		item.removeClassName("section-on");

		if(item.hasClassName(clsNameSection)){

			item.addClassName("section-on");

		}

	});

  },

  // removes link sections

    removeLink: function(el) {

        if(el){
           if(el.hasChildNodes()){

            var span = document.createElement('span');

            for(var i=0; i<el.childNodes.length; i++){

                span.appendChild(el.childNodes[i].cloneNode(true))

            }

            el.parentNode.insertBefore(span, el);

        }

        el.parentNode.removeChild(el);
        }
    },

  setup: function() {

   // add click event to each side_bar more buttom

   $$('#main .sidebar-navigation a.more').each(

    function(el){

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // if container visible, close, if not, open

      var container = el.up();

      if(container.hasClassName('section-on')) {

       container.removeClassName('section-on');

      } else {

       container.addClassName('section-on');

      }

     });

    }

   );

            $$('#main .sidebar-navigation ul.subnavigation a').each(

                function(el){
                    if(el.firstChild){
                        if($('activeLink')){
                            if(el.firstChild.nodeValue == $('activeLink').value){

                                var parentDiv = el.up().up().up();

                                GMX.side_bar.removeLink(el);

                                parentDiv.addClassName('section-on');

                            }
                        }
                    }
                }

                );

            // add expandAll/collapseAll button event

   var button = $('button-expand');

   if(button) {

    button.observe('click',function(event){

     Event.stop(event);

     GMX.side_bar.expandAll();

    });

   }

   button = $('button-collapse');

   if(button) {

    button.observe('click',function(event){

     Event.stop(event);

     GMX.side_bar.collapseAll();

    });

   }

  }

 },



 // quick_links setup

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

          quick_links: {

  setup: function() {

   $$('div.quick-links a').each(

    function(el){

     // add click events

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // get hash name

      var scrollto = (' ' +el.hash).split('#')[1];

      if($(scrollto)){

          new Effect.ScrollTo(scrollto);

      }

     });

    }

   );

  }

 },



 // toc_links setup

 toc_links: {

  setup: function() {

   $$('ol#toc-list a').each(

    function(el){

     // add click events

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // get hash name

      var scrollto = (' ' +el.hash).split('#')[1];



      if($(scrollto)) new Effect.ScrollTo(scrollto);



     });

    }

   );



   $$('a.back-to-top').each(

    function(el){

     // add click events

     el.observe('click',function(event){

      // stop event propagation

      Event.stop(event);

      // get hash name

      var scrollto = (' ' +el.hash).split('#')[1];



      GMX.scroll.top();

     });

    }

   );





  }

 },



 // player object: edited by daryl bowden @ HUGE on 4/22/2009

	player: {

		is_loaded: false,

		obj: null,

		// setup player

		setup: function() {

			// if loaded, don't get object again

			if(this.is_loaded) return true;

			// set loaded flag

			this.is_loaded = true;

			// set player container

			this.obj = $('player');

		},

		// open player

		open: function() {

			// setup player

			this.setup();

			// if there is no player, quit

			if(!this.obj) return;

			// open player container

			Effect.BlindDown(this.obj,{ duration: 0.3, afterFinish: GMX.player.play});



		},

		// close player

		close: function() {

			// setup player

			this.setup();

			// if there is no player, quit

			if(!this.obj) return;

			GMX.player.stop();

			// close player container

			Effect.BlindUp(this.obj,{ duration: 0.3, afterFinish: GMX.player.enableToggle });

			//this.stop();

		},

		// stop video

		stop: function() {

			if(typeof(	$('AkamaiFlashPlayer').pauseMovie) == "function"){

				$('AkamaiFlashPlayer').pauseMovie();

			}

		},

		enableToggle: function(){

			$$("div.trailer-toggle a").first().observe('click',function(event){

				// Stop the onclick event propagation

				Event.stop(event);

				$$("div.trailer-toggle a").first().stopObserving('click');

				if(Event.element(event).hasClassName("closed")){

					// Open the trailer

					Event.element(event).removeClassName("closed");

					GMX.player.open();

				} else {

					// Close the trailer

					Event.element(event).addClassName("closed");

					// Scroll to the top of the page

					GMX.scroll.top();

					// Give time to scroll top

					setTimeout(function() {

						GMX.player.close();

						GMX.episodes_navigation.close();

						//GMX.details.open();

					}, 1000);

				}

			});

		},

		// play video

		play: function() {

			if(typeof($('AkamaiFlashPlayer').playMovie) == "function"){

					$('AkamaiFlashPlayer').playMovie();

			}

			GMX.player.enableToggle();

		}

	},

	// END 4/22/09 edits



    package_player: {

        obj: null,

        is_loaded: false,

        // setup player

        // open player

        setup: function() {

            if(this.is_loaded) return true;

			// set loaded flag

			this.is_loaded = true;

            this.obj = $('package_player');

        },



        open: function() {

            // setup player

            this.setup();

            // if there is no player, quit

            if(!this.obj) return;

            // open player container

            Effect.BlindDown(this.obj,{duration: 0.3,afterFinish: GMX.package_player.play});



        },

        // close player

        close: function() {

            // setup player

            this.setup();

            // if there is no player, quit

            if(!this.obj) return;

            GMX.package_player.stop();

            // close player container

            Effect.BlindUp(this.obj,{duration: 0.3,afterFinish: GMX.package_player.enableToggle});

        //this.stop();

        },

  		play: function() {

			if(typeof($('AkamaiFlashPlayer').playMovie) == "function"){

					$('AkamaiFlashPlayer').playMovie();

			}

			GMX.package_player.enableToggle();

		},

        stop: function() {

			if(typeof(	$('AkamaiFlashPlayer').pauseMovie) == "function"){

				$('AkamaiFlashPlayer').pauseMovie();

			}

		},

        enableToggle: function(){

            $$("div.trailer-toggle a").first().observe('click',function(event){

                // Stop the onclick event propagation

                Event.stop(event);

                $$("div.trailer-toggle a").first().stopObserving('click');

                if(Event.element(event).hasClassName("closed")){

                    // Open the trailer

                    Event.element(event).removeClassName("closed");

                    GMX.package_player.open();

                } else {

                    // Close the trailer

                    Event.element(event).addClassName("closed");

                    // Scroll to the top of the page

                    GMX.scroll.top();

                    // Give time to scroll top

                    setTimeout(function() {

                        GMX.package_player.close();

                        GMX.episodes_navigation.close();

                    //GMX.details.open();

                    }, 1000);

                }

            });

        }

    },







 // breadcrumb object

 breadcrumb: {

  obj: null,

  open: function() {

   // open breadcrumb

   if(this.obj) Effect.BlindDown('breadcrumb',{ duration: 0.3 });

   else if(this.obj==null){

    if($('breadcrumb')) {

     this.obj = true;

     this.open();

    }

   }

  },

  close: function() {

   // close breadcrumb

   if(this.obj) Effect.BlindUp('breadcrumb',{ duration: 0.3 });

   else if(this.obj==null){

    if($('breadcrumb')) {

     this.obj = true;

     this.close();

    }

   }

  }

 },



 // form_steps object

 form_steps: {

  form: null,

  steps: null,

  setup: function(frm,steps) {

   this.form = frm;

   this.steps = steps;

   // create all fieldsets

   for(var i=0,len=this.steps.length;i<len;i++) {

    var fieldset = document.createElement('fieldset');

    fieldset.id = 'step-'+i;

    $(this.form).insert(fieldset);

   }

   // load first fieldset

   this.load(0);

  },

  load: function(n) {

   // remove all active fieldsets

   $$('fieldset.active').each(

    function(el) {

     el.removeClassName('active');

    }

   );

   // remove all active steps header titles

   $$('#steps-header strong').each(

    function(el) {

     el.removeClassName('active');

    }

   );

   // set header active title

   $('title-step-'+n).addClassName('active');

   // if step was not loaded before, do ajax call

   if(!this.steps[n].loaded) {

    $(this.form).addClassName('loading');

    this.steps[n].loaded = true;

    var url = this.steps[n].url;

    var onload = this.steps[n].onload;

    new Ajax.Updater('step-'+n,url,

    {

        method:'get',

        onComplete: function(){

      if(onload) onload();

      $('step-'+n).addClassName('active');

      $(GMX.form_steps.form).removeClassName('loading');

      GMX.select.setup();

      GMX.tooltip.setup();

      GMX.static_tooltip.setup();

        }

    });

   } else {

    $('step-'+n).addClassName('active');

    if(onload) onload();

   }

  }

 },



 // gmx_menu object

 gmx_menu: {

  setup: function(){

   if($('gmx-menu')==null) return;

   // open gmx_menu dropdown on mouseover

   $('gmx-menu').observe('mouseover', function(){

    this.addClassName('menu-on');

    if(Prototype.Browser.IE){

      $('search').style.zIndex = -1;

 $('main').style.position = 'relative';

 $('main').style.zIndex = -1;

    }

   });

   // close gmx_menu dropdown on mouseout

   $('gmx-menu').observe('mouseout', function(){

    this.removeClassName('menu-on');

    if(Prototype.Browser.IE){

       $('search').style.zIndex = 10;

   $('main').style.zIndex = 1;

  $('main').style.position = '';

        }

   });

  }

 },



 // episodes_navigation object

 episodes_navigation: {

  is_loaded: false,

  obj: null,

  // setup episodes_navigation

  setup: function() {

   // if loaded, don't get object again

   if(this.is_loaded) return true;

   // set loaded flag

   this.is_loaded = true;

   // set episodes_navigation container

   this.obj = $('episodes-navigation');

  },

  // open episodes_navigation

  open: function() {

   // setup episodes_navigation

   this.setup();

   // if there is no episodes_navigation, quit

   if(!this.obj) return;

   // open episodes_navigation container

   Effect.BlindDown(this.obj,{ duration: 0.3 });

  },

  // close episodes_navigation

  close: function() {

   // setup player

   this.setup();

   // if there is no episodes_navigation, quit

   if(!this.obj) return;

   // close episodes_navigation container

   Effect.BlindUp(this.obj,{ duration: 0.3 });

  }

 },





 // header dropdown_navigation object

        /** Locked down by Ascent.

          * This method should no longer be subject to code drops by Huge.  All changes

          * should be internal only.

          */

          dropdown_navigation: {

   close: function() {

            // open breadcrumb

            GMX.breadcrumb.open();

            // open episodes_navigation

            GMX.episodes_navigation.open();

            //GMX.player.open(); // removed, player does not open/close anymore

            // call back function, hide dropdown_navigation after dropdown_navigation close

            GMX.dropdown_navigation.hide();

            var afterFinish = GMX.dropdown_navigation.hide;

            // close container

            Effect.BlindUp('dropdown-navigation',{ duration: 0.3, afterFinish:afterFinish });

        },



  // open dropdown_navigation container

  open: function(callback) {

   // close breadcrumb

   GMX.breadcrumb.close();

   // close episodes_navigation

   GMX.episodes_navigation.close();

   //GMX.player.close(); // removed, player does not open/close anymore

   // call back function, show dropdown_navigation after dropdown_navigation open

   var afterFinish = GMX.dropdown_navigation.show;

   if(callback) afterFinish = callback;

   // open container

   Effect.BlindDown('dropdown-navigation',{ duration: 0.3, afterFinish:afterFinish });

  },

  // show dropdown_navigation content

  show: function() {

   // get dropdown_navigation content

   var div = $$('#dropdown-content div.dropdown-content').first();

   // if there...

   if(div)  {

    // set to transparent

    div.setOpacity(0);

    // show it

    div.setStyle({display:'block'});

    // fade opacity

    div.fade({ duration: 0.3, from: 0, to: 1 });



    $$('#dropdown-content div.dropdown-content a img').each(

                    function(el){

                        el.src = unescape(el.src);

                    }

                    );

   }

   // remove classes loading and closed

   $('dropdown-content').removeClassName('loading');

   $('dropdown-content').removeClassName('closed');

  },



// hide dropdown_navigation content

        hide: function() {

            // get dropdown_navigation content

            var div = $$('#dropdown-content div.dropdown-content').first();

            // set to transparent

            if(div){

                if (Prototype.Browser.IE){

                    div.hide();

                }

                div.setOpacity(0);

            }

            // remove class loading

            $('dropdown-content').removeClassName('loading');

            // add class closed

            $('dropdown-content').addClassName('closed');

        },





  // setup dropdown_navigation

  setup: function(){

   // add dropdown-navigation element

   var obj = $$('#header .content').first();

   if(!obj) obj = $('header');

   obj.insert( {after:'<div id="dropdown-navigation" style="display:none"><div id="dropdown-content"></div></div>'} );

  }

 },



    // tooltip object

    /** Locked down by Ascent.

      * This method should no longer be subject to code drops by Huge.  All changes

      * should be internal only.

      */

    tooltip: {

        // add onclick event to all tooltip links

        setup: function() {

            $$('a.tooltip').each(

                function(el) {

                    // if tooltip was loaded before, quit

                    if(el.hasClassName('tooltip-loaded')) return;

                    el.addClassName('tooltip-loaded');

                    el.stopObserving('mouseover');

                    el.observe('mouseover', function(event){

                        if(el.hasClassName('tooltip-over')) return;

                        el.addClassName('tooltip-over');

                        clearTimeout(GMX.tooltip.timeout);

                        Event.stop(event);

                        GMX.tooltip.timeout = setTimeout( function(){

                            var evt = window.event || event //cross browser event object

                            GMX.tooltip.open(el, evt);

                        }, 0 );

                    });

                    el.stopObserving('mouseout');

                    el.observe('mouseout', function(event){

                        clearTimeout(GMX.tooltip.timeout);

                        Event.stop(event);

                        GMX.tooltip.timeout = setTimeout( function(){

                            var evt = window.event || event //cross browser event object

                            GMX.tooltip.close(el, evt);

                        }, 0 );

                    });

                }

                );

        },

        // open tooltip

        open: function(el, e) {

            // close other tooltips

            GMX.tooltip.close(el, e);

            // if ie, get different left arrow (in IE6, the layout of the tooltip has a different shadow)

            var arrow = '<img src="' + requestContext + '/img/tootip-arrow.png" width="32" height="32" alt="Arrow" />';

            if(Prototype.Browser.IE){

                var version = parseFloat(navigator.appVersion.split('MSIE')[1]);

                if ((version >= 5.5) && (version < 7)) arrow = '<img src="' + requestContext + '/img/tootip-arrow-ie6.png" width="32" height="32" alt="Arrow" />';

            }

            // tooltip htm

            var tooltip = '<div id="tooltip" class="tooltip">\
                            <table border="0" cellspacing="0" cellpadding="0">\
                             <tr>\
                              <td class="tooltip-top-left">&#160;</td>\
                              <td class="tooltip-top">&#160;</td>\
                              <td class="tooltip-top-right">&#160;</td>\
                             </tr>\
                             <tr>\
                              <td class="tooltip-left">' + arrow + '</td>\
                              <td id="tooltip-content-wrapper" class="tooltip-content tooltip-content-loading">\
                               <div id="tooltip-content"></div><div id="tooltip-content-dummy" style="display:none;"></div>\
                              </td>\
                              <td class="tooltip-right">&#160;</td>\
                             </tr>\
                             <tr>\
                              <td class="tooltip-bottom-left">&#160;</td>\
                              <td class="tooltip-bottom">&#160;</td>\
                              <td class="tooltip-bottom-right">&#160;</td>\
                             </tr>\
                            </table>\
                       </div>';

            // append tooltip htm

            $('main').insert(tooltip);

            // get tooltip position and load it

            var obj = $('tooltip');

            if(el.hasClassName("tooltip-list")){

            	var leftOffset = -10;

            }else{

            	var leftOffset = 55;

            }

      		obj.clonePosition(el, {setWidth: false, setHeight: false, offsetLeft: leftOffset, offsetTop: -45});

            obj.stopObserving('mouseout');

            obj.observe('mouseout', function(event){

                clearTimeout(GMX.tooltip.timeout);

                Event.stop(event);

                GMX.tooltip.timeout = setTimeout( function(){

                    var evt = window.event || event //cross browser event object

                    GMX.tooltip.close(el, evt);

                }, 0 );

            });

            obj.stopObserving('mouseover');

            obj.observe('mouseover', function(event){

                Event.stop(event);

                clearTimeout(GMX.tooltip.timeout);

            });

            if(el.rel){

                var obj = $('tooltip-content-wrapper'); // remove tooltip loading gif

                if(obj) obj.removeClassName('tooltip-content-loading');

                $('tooltip-content').innerHTML = el.rel;

            }else{

                GMX.tooltip.load(el);

            }

        },

        // close all tooltip

        close: function(el, e) {

            if(el){

                if(el) el.removeClassName('tooltip-over');

                var obj = $('tooltip'); // remove tooltip object

                if(obj) obj.up().removeChild(obj);

            }

        },

        parentForm:function(el){

            var parent = el.parentNode;

            while(parent.nodeName.toLowerCase() != 'form' && parent.nodeName.toLowerCase() != 'body') {

                parent = parent.parentNode;

            }

            return parent;

        },

        // load tolltip

        load: function(el) {

            var obj = $('tooltip-content-dummy');

            if(obj) {

                // get ajax content

                var parentForm = GMX.tooltip.parentForm(el);

                var linkName = el.name;

                new Ajax.Updater(obj, parentForm.action,

                    {   asynchronous: false,

                        method: "post",

                        parameters: "ajax=true&action=getTooltip&itemId=" + parentForm.tooltipItemId.value + "&itemType=" + parentForm.tooltipItemType.value + "&formId=" + parentForm.id + "&linkName=" + linkName,

                        onComplete: function(req){



                            if(req.responseText != null &&  req.responseText != ''){

                                var responseText =  req.responseText;

                                if(responseText.indexOf('homePage()', 0) > 0 ){

                                    //alert('Your session expired...');

                                    location.href=requestContext;

                                    return;

                                }else{

                                    var obj = $('tooltip-content-wrapper'); // remove tooltip loading gif

                                    if(obj) obj.removeClassName('tooltip-content-loading');

                                    $('tooltip-content').innerHTML =  $('tooltip-content-dummy').innerHTML;

                                    if(req.responseText != null &&  req.responseText != '') el.rel = req.responseText;

                                }

                            }

                        },

                        onFailure: function(){ }

                    });

            }

        }

    },



   /////////// Static Tooltip ///////////

   // static_tooltip object

   static_tooltip: {

		// add onclick event to all static_tooltip links

		setup: function() {

			$$('a.tooltip').each(

				function(el) {

					// if tooltip was loaded before, quit

					if(el.hasClassName('tooltip-loaded')) return;

					el.addClassName('tooltip-loaded');

					el.stopObserving('click');

					el.observe('click', function(event){

						Event.stop(event);

					});

					el.stopObserving('mouseover');

					el.observe('mouseover', function(event){

						clearTimeout(GMX.static_tooltip.timeout);

						Event.stop(event);

						GMX.static_tooltip.timeout = setTimeout( function(){ GMX.static_tooltip.open(el); }, 200 );

					});

					el.stopObserving('mouseout');

					el.observe('mouseout', function(event){

						clearTimeout(GMX.static_tooltip.timeout);

						Event.stop(event);

						GMX.static_tooltip.timeout = setTimeout( function(){ GMX.static_tooltip.close(); }, 100 );

					});

				}

			);

		},

		// open static_tooltip

		open: function(el) {

			// close other static_tooltips

			GMX.static_tooltip.close();

			// if ie, get different left arrow (in IE6, the layout of the static_tooltip has a different shadow)
			var arrow = '<img src="'+requestContext+'/img/tootip-arrow.png" width="32" height="32" alt="Arrow" style="top:40px;"/>';

			if(Prototype.Browser.IE){

				var version = parseFloat(navigator.appVersion.split('MSIE')[1]);

				if ((version >= 5.5) && (version < 7)) arrow = '<img src="'+requestContext+'/img/tootip-arrow-ie6.png" width="32" height="32" alt="Arrow" />';

			}

			// static_tooltip htm

			var tooltip = '<div id="tooltip" class="tooltip">\
				<table border="0" cellspacing="0" cellpadding="0">\
					<tr>\
						<td class="tooltip-top-left">&#160;</td>\
						<td class="tooltip-top">&#160;</td>\
						<td class="tooltip-top-right">&#160;</td>\
					</tr>\
					<tr>\
						<td class="tooltip-left">' + arrow + '</td>\
						<td id="tooltip-content-wrapper" class="tooltip-content tooltip-content-loading">\
							<div id="tooltip-content"></div>\
						</td>\
						<td class="tooltip-right">&#160;</td>\
					</tr>\
					<tr>\
						<td class="tooltip-bottom-left">&#160;</td>\
						<td class="tooltip-bottom">&#160;</td>\
						<td class="tooltip-bottom-right">&#160;</td>\
					</tr>\
				</table>\
			</div>';
			// append tooltip htm

			$('container').insert(tooltip);

			// get static_tooltip position and load it

			var obj = $('tooltip');

			//obj.setStyle({left:pos.left+w+'px',top:pos.top+h+'px'});

			obj.clonePosition(el, {setWidth: false, setHeight: false, offsetLeft: 55, offsetTop:-45});

			obj.stopObserving('mouseout');

			obj.observe('mouseout', function(event){

				clearTimeout(GMX.static_tooltip.timeout);

				Event.stop(event);

				GMX.static_tooltip.timeout = setTimeout( function(){ GMX.static_tooltip.close(); }, 0 );

			});

			obj.stopObserving('mouseover');

			obj.observe('mouseover', function(event){

				Event.stop(event);

				clearTimeout(GMX.static_tooltip.timeout);

			});

			GMX.static_tooltip.load(el);



		},

		// close all static_tooltip

		close: function(el) {

			// remove static_tooltip object

			var obj = $('tooltip');

			if(obj) obj.up().removeChild(obj);

		},

		// load tolltip

		load: function(el) {

			var obj = $('tooltip-content');

			if(obj) {

				// get ajax content
                var parentDiv =el.up();
                var tooltipDivName;
                if(parentDiv && parentDiv.className.indexOf('tooltip-id:', 0) >= 0){
                    var totalLen = parentDiv.className.length;
                    var exLen = 'tooltip-id:'.length;
                    tooltipDivName= parentDiv.className.substr(exLen, totalLen);
                }
				new Ajax.Updater(obj,el.href,

				{

				    method:'get',

				    onComplete: function(){

						// remove static_tooltip loading gif

						var obj = $('tooltip-content-wrapper');

						if(obj) obj.removeClassName('tooltip-content-loading');
                        if(tooltipDivName){
                            $(tooltipDivName).style.display='block';
                        }
				    }

				});

			}

		}

	},





 // custom select object

 select: {

  open_selects: [],

  close: function(el) {

   // hide options

          /* Condition added to resolve javascript error on clicking

           * rootCategory in category select box in Ask a question page

           */

            var selectedElem = el.select('div.options').first();

            if(selectedElem){

                selectedElem.hide();

            }

        //el.select('div.options').first().hide();

  },

  open: function(el) {

   // hide all select options of every custom select in the page

   this.closeAll();

   // save open custom selects

   this.open_selects.push(el);

   // show options

   el.select('div.options').first().show();

  },

  closeAll: function() {

   // hide all select options of every custom select in the page

   // if the user clicks outsite the select, every select should close

   for(var i=0,len=this.open_selects.length;i<len;i++) {

    var el = this.open_selects.pop();

    this.close(el);

   }

  },

  setup: function() {

   // create custom select html

   $$('select.custom-select').each(

    function(el) {

     if(el.hasClassName('select-loaded')) return;

     el.addClassName('select-loaded');

     var wrapper = document.createElement('div');

     wrapper.className = 'custom-select-wrapper';

     var select = document.createElement('div');

     select.className = 'custom-select';

     if(el.hasClassName('custom-select-white')) select.className = 'custom-select custom-select-white';

     if(el.hasClassName('custom-select-gray')) select.className = 'custom-select custom-select-gray';

     var space = document.createElement('div');

     space.className = 'custom-select-space';

     space.appendChild(document.createTextNode('.'))

     var options = document.createElement('div');

     options.className = 'options';

     var space1 = document.createElement('div');

     space1.className = "options-separator";

     options.appendChild(space1);

     var c = 0;

     el.select('option').each(function(el) {

      //the option with the 'optgroup' simulates the optgroup functionality in a regular select with optgroup tags

      if(el.className == 'optgroup'){

       var span = document.createElement('span');

       span.innerHTML = el.text;

       options.appendChild(span);

      }else{

       var a = document.createElement('a');

       a.href = '#' + el.value;

       a.innerHTML = el.text;

       // if first option, create selected element

       if(c==0) {

        var a_sel = a.cloneNode(true);

        a_sel.className = 'selected';

        select.appendChild(a_sel);

       }

       if(el.selected == true) a.className = 'will-be-selected';

       options.appendChild(a);

       c++;

      }

     });

     select.appendChild(options);

     wrapper.appendChild(select);

     wrapper.appendChild(space);

     // duplicate original select, and wrap inside the wrapper

     var el_dup = el.cloneNode(true);

     wrapper.appendChild(el_dup);

     el.insert({after:wrapper});

     // remove original select

     el.up().removeChild(el);

    }

   );

   GMX.select.events();

  },

  click: function(ev,element) {

   var el = null;

   if(ev) {

    el = Event.element(ev);

				Event.stop(ev);

			} else{

				el = element;

			}

			var container = el.up().up();

			GMX.select.close(container);

			// get last selected element

			var a = container.select('a');

			// save selected element

          /* Condition added  to resolve javascript error on clicking

           * rootCategory in category select box in Ask a question page

           */

            if(el.href){

                a.first().href = el.href;

                a.first().innerHTML = el.innerHTML;

            }

			a.each(

				function(el) {

					el.removeClassName('select-on');

				}

			);

			// show that the element was selected

			el.addClassName('select-on');

			// change form select value

			var test = (' ' + el.href).split('#')[1];

			var list = container.up().select('select').first();

          /* Condition added to resolve javascript error on clicking

           * rootCategory in category select box in Ask a question page

           */

            if(list){

                if(list.onchange) list.onchange();

                list.value = test;

                var options = list.getElementsByTagName('option');

                options = $A(options);

                var opt = options.find(function(o){

                    if(o.value == test) {

                        o.selected = true;

                    }

                });

            }

		},

		events: function() {

			// apply events to custom selects

			$$('body').first().stopObserving('click');

			$$('body').first().observe('click', function(event){

				// close all open custom selects on the page

				GMX.select.closeAll();

			});

			$$('div.custom-select').each(

				// for each custom select

				function(el){

					if(el.hasClassName('select-loaded')) return;

					el.addClassName('select-loaded');

					// set width

					var w = el.getWidth()+25+'px';

					el.setStyle({width:w});

					el.up().setStyle({width:w});

					// hide option and form select

					el.select('div.options').first().hide();

					el.up().select('select').first().hide();

					// add click event to container, to open and close

					el.stopObserving('click');

					el.observe('click', function(event){

						Event.stop(event);

						if(el.select('div.options').first().visible()) {

							GMX.select.close(el);

						} else {

							GMX.select.open(el);

						}

					});

				}

			);

			$$('div.custom-select div.options a').each(

				function(el) {

					el.stopObserving('click');

					el.observe('click', GMX.select.click);

				}

			);

			$$('div.custom-select div.options a.will-be-selected').each(

				function(el) {

					el.removeClassName('will-be-selected');

					GMX.select.click(null,el);

				}

			);

		}

	},



	// tabs object

	tabs: {

		setup: function(){

			$$('ul.tabs a').each(

				// for each tabs item

				function(el){

					// add click event

					el.observe('click', function(event){

						Event.stop(event);

						// hide all selected content

						el.up().up().up().select('div.tabs-content').each(

							function(el) {

								el.removeClassName('tabs-content-on');

							}

						);

						// show selected content

						//$((' ' +el.href).split('#')[1]).addClassName('tabs-content-on');



						 /*Condition added by offshore to resolve javascript on clicking of open/close tabs*/

                        var splittedVar = $((el.href).split('#')[1]);



                        if(splittedVar){

                            splittedVar.addClassName('tabs-content-on');

                        }

                        /*Condition added by offshore to resolve javascript on clicking of open/close tabs*/



						el.up().up().select('li').each(

							function(el) {

								el.removeClassName('tabs-on');

							}

						);

						// disable all selected tabs items

						el.up().addClassName('tabs-on');

					});

				}

			);

		}

	},



	// tabs_carousel

	tabs_carousel: {

        setup: function(id, content_tabs){

            // get all tab itens

            var links = $(id).select('ul.tabs a');

            // load first carousel

            try{

                var category_carousel =  new GMX.Carousel(content_tabs[0].id,{

                    //url:content_tabs[0]['url'],

                    width:612

                });

            }catch (exp){

            }

            links[0].addClassName('item-loaded');

            // for each tab, add click event to load each carousel

            for(var i = 1; i < content_tabs.length; i++) {

                var el = links[i];

                if (el != null) {

                    el.tab = content_tabs[i];

                    el.observe('click', function(event){

                        Event.stop(event);

                        // prevent carousel from loading again

                        if(event.target.hasClassName('item-loaded')) return;

                        event.target.addClassName('item-loaded');

                        var tab = event.target.tab;

                        try{

                            new GMX.Carousel(tab.id,{

                                //url:tab.url,

                                width:612

                            });

                        }catch(exp){

                        }

                    });

                }

            }

        }

    },



    // header navigation object

    /** Locked down by Ascent.

      * This method should no longer be subject to code drops by Huge.  All changes

      * should be internal only.

      */

    navigation: {

        over_element: null,

        over_old_element: null,

        // navigation mouseout event

        out: function(){

            GMX.navigation.timeout = clearTimeout(GMX.navigation.timeout);

        },

        // navigation mouseover event

        over: function(url) {

            // get obj dropdown-content, if it is closed or loading, quit

            var obj = $('dropdown-content');

            if(obj.hasClassName('loading')) return;

            // if titles, change class to bigger dropdown

            if(this.over_element.hasClassName('titles')) $('dropdown-navigation').addClassName('dropdown-big');

            else $('dropdown-navigation').removeClassName('dropdown-big');

            this.over_old_element = this.over_element;

            // adding loading classe

            obj.addClassName('loading');

            // set call back function

            var callbackOpen = function(){

                var objDummy = document.createElement('div');

                new Ajax.Updater(objDummy,url,

                {

                    method:'get',

                    onComplete: function(req){

                        if(req.responseText != null &&  req.responseText != ''){

                            var responseText =  req.responseText;

                            if(responseText.indexOf('homePage()', 0) > 0 ){

                                //alert('Your session expired...');

                                location.href=requestContext;

                                return;

                            }else{

                                var obj = $('dropdown-content');

                                obj.innerHTML = objDummy.innerHTML;

                                // show dropdown-content

                                GMX.dropdown_navigation.show();

                            }

                        }

                    }

                });

            }

            if(!obj.hasClassName('closed')) callbackOpen();

            // open dropdown_navigation, and call the ajax url

            else GMX.dropdown_navigation.open(callbackOpen);

        },

        // setup navigation

        setup: function(){

            // add class closed to #dropdown-content

            $('dropdown-content').addClassName('closed');

            // add mouse over event to #dropdown-content, this will stop mouseover propagation to #container, and keep the #dropdown-content openned

            $('dropdown-navigation').observe('mouseover',function(event){

                // stop event propagation

                Event.stop(event);

            });

            // add mouse over event to #container, this will act like a mouseout event, and close the #dropdown-content

            $$('body').first().observe('mouseover',function(event){

                // stop event propagation

                Event.stop(event);

                // call navigation mouse out event

                GMX.navigation.out();

                // get obj, if obj is loading or it is closed, quit

                var obj = $('dropdown-content');

                if(obj.hasClassName('closed') || obj.hasClassName('loading')) return;

                // add class loading

                obj.addClassName('loading');

                // close dropdown_navigation

                GMX.dropdown_navigation.close();

            });

            $$('#navigation li a').each(function(el){

                el.up().observe('mouseover',function(event){

                    // stop event propagation

                    Event.stop(event);

                });

            });

            //highlight navigation tab

            $$('#navigation li a').each(

                function(el){

                    if(el.className == $('navigationPage').value){

                        el.up().addClassName('on');

                    }

                    el.observe('mouseover',function(event){

                        GMX.navigation.over_element = el;

                        // stop event propagation

                        Event.stop(event);

                        // call navigation out event

                        GMX.navigation.out();

                        // get url for the ajax call

                        var url = requestContext + '/content/header/flyout_menu/' + el.className + '_content.jsf';

                        // set a timeout, if no mouse out detected, the ajax call will be made

                        GMX.navigation.timeout = setTimeout( function(){

                            GMX.navigation.over(url);

                        }, 500 );

                    });

                }

                );



            $$('#navigation-join li a').each(

                function(el){

                    if(el.className == $('navigationPage').value){

                        el.up().addClassName('on');

                    }

                }

                );

        }

    },



 // setup page object

 pages: {

  list: [],

  setup: function(name) {

   // initialize all page components

   var components = this.list[name].components;

   var init = this.list[name].init;

   for(var i=0,len=components.length;i<len;i++) {

    var obj = components[i];

    GMX[obj].setup();

   }

   // initialize gmx_menu

   //GMX.gmx_menu.setup();

   // initialize navigation

   //GMX.dropdown_navigation.setup();

   //GMX.navigation.setup();

   // load callback function

   if(init) init();

  },

  // add page object

		add: function(name,components,init) {

			this.list[name] = ( { components:components,init:init } );

		}

	},



	// fancy select change handler

	options_handler: {

		setup: function(el) {

			$(el).onchange = function() {

				// if it is still loading, quit

				if(this.hasClassName('loading')) return;

				this.addClassName('loading');

				var container = this;

				var url = (this.value).split('|')[0];

				var carousel_url = (this.value).split('|')[1];

				var obj = $(this.id+'-content');

				var carousel = this.up('div.feature');

				var w = 612;

				// figure out which carousel should start

				if(!carousel) {

					carousel = $('companies-carousel');

					w = 980;

				}

				var spinner = carousel.select('.spinner').first();

				var callback = function() {

					// show loading spinner

					if(!spinner.visible()) spinner.setOpacity(0).show().fade({ duration: 0.3, from: 0, to: 0.8, queue:'end' });

					// get carousel content from option value

					// option value ="first-url | second-url"

					// first-url -> entire carousel content

					// seconde-url -> carousel page content

					new Ajax.Updater(obj,url,

					{

					    method:'get',

					    onComplete: function(){

							GMX.options.setup();

							GMX.tooltip.setup();

                            GMX.static_tooltip.setup();

							container.removeClassName('loading');

							// fade in carousel and start carousel object

							obj.setOpacity(0).show().fade({ duration: 0.3, from: 0, to: 1, queue:'end' });

							var featured_producers_carousel = new GMX.Carousel(carousel.id,{

								url:'data/get_ajax_template.php?template='+carousel_url,

								width:w

							});

					    }

					});

				}

				// fade out carousel

				obj.fade({ duration: 0.3, from: 1, to: 0, queue:'end', afterFinish: callback });

			}

		}

	},



	//show/hide past events links

	past_events:{

		setup: function(){

			$('show-past-events').observe('click', function(){

				new Effect.SlideDown('past-events',{duration: 1.0});

				this.hide();

			});

			$('hide-past-events').observe('click', function(){

				new Effect.SlideUp('past-events',{duration: 1.0});

				$('show-past-events').show();

			});

		}

	},

	show_more:{

		setup: function(){

			$$('a.show-more').each(function(item){

				/*when link is clicked the previous is shown or not and the links text and arrow changes*/

				item.observe('click', function(){

					if(item.hasClassName('arrow-more')){

						new Effect.SlideDown(item.up(0).previous(0).id,{duration: 1.0, afterFinish: function(){

							item.innerHTML = 'SHOW LESS';

							item.removeClassName('arrow-more');

							item.addClassName('arrow-less');

							}

						});



					}

					else if(item.hasClassName('arrow-less')){

						new Effect.SlideUp(item.up(0).previous(0).id, {duration:1.0, afterFinish: function(){

							item.innerHTML = 'SHOW MORE';

							item.removeClassName('arrow-less');

							item.addClassName('arrow-more');

							}

						});

					}

					else if(item.hasClassName('more')){

						new Effect.SlideDown(item.up(0).previous(0).id,{duration: 1.0, afterFinish: function(){

							item.innerHTML = "&lsaquo; SHOW LESS";

							item.removeClassName('more');

							item.addClassName('less');

							}

						});

					}

					else if(item.hasClassName('less')){

						new Effect.SlideUp(item.up(0).previous(0).id, {duration:1.0, afterFinish: function(){

							item.innerHTML = "SHOW MORE &rsaquo;";

							item.removeClassName('less');

							item.addClassName('more');

							}

						});

					}

					//when we don't have any arrows

				});

			});

		}

	},

	innerPopups:{



		addTo: function( ){

            var newList = function(){

                this.fade({

                    duration: 1.0

                });

                this.hide();

                $('add-new-list').show();

                $('new-list').checked = true;

                $('add-list-select').checked = false;

                togleListSelection($('new-list'));

            };



            if('existing' == $('add-to-selection-mode').value){

                $('add-list-select').checked = true;

                $('create-new').setStyle('display:inline');

                $('add-new-list').setStyle('display:none');



                //create new list link

                $('create-new').observe('click', newList);



            }

            else if('existing-new' == $('add-to-selection-mode').value){

                $('create-new').setStyle('display:none');

                $('add-new-list').setStyle('display:block');

                $('add-list-select').checked = false;

                $('new-list').checked = true;



                //create new list link

                $('create-new').observe('click', newList);

            }



            if('new' == $('add-to-selection-mode').value){



            }



            GMX.popups.closeSetup();



            $$('a.button-cancel').each(function(item){

                item.stopObserving('click');

                item.observe('click', function(){

                    if(GMX.popups.idWrapperPopup != null){

                        $(GMX.popups.idWrapperPopup).fade({

                            duration: 0.3,

                            from: 1,

                            to: 0 ,

                            afterFinish: function(){

                                $('allover').style.display = "none";

                                $(GMX.popups.idWrapperPopup).removeClassName('open');

                                GMX.popups.idWrapperPopup = null;

                            }

                        });

                    }

                });

            });

        },



		contact: function(contactType){

			//setting the width manually for the select
            GMX.popups.closeSetup();
            $$('a.button-cancel').each(function(item){

                item.stopObserving('click');

                item.observe('click', function(){

                    if(GMX.popups.idWrapperPopup != null){

                        $(GMX.popups.idWrapperPopup).fade({

                            duration: 0.3,

                            from: 1,

                            to: 0 ,

                            afterFinish: function(){

                                $('allover').style.display = "none";

                                $(GMX.popups.idWrapperPopup).removeClassName('open');

                                GMX.popups.idWrapperPopup = null;

                            }

                        });

                    }

                });

            });


			$$('div.custom-select-wrapper').each(function(it){

				it.style.width = '200px';

			});

			$$('div.select-loaded').each(function(it){

				it.style.width = '200px';

			});

			//initialize default divs

			if(contactType == 'seller'){

				$$('#contact-seller-popup div.step1').first().setStyle('display:block');

				$$('#contact-seller-popup div.step2').first().setStyle('display:none');

			}else if(contactType == 'company'){

				$$('#contact-company-popup div.step1').first().setStyle('display:block');

				$$('#contact-company-popup div.step2').first().setStyle('display:none');

			}else if(contactType == 'person'){

				$$('#contact-company-popup div.step1').first().setStyle('display:block');

				$$('#contact-company-popup div.step2').first().setStyle('display:none');

			}

			//SUBMIT buttons seller

			$('seller-contact-submit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('contact-seller-popup').fade({ duration: 1 }); $('contact-seller-popup').removeClassName('open'); }, 3000);

			});

			//SUBMIT buttons company

			$('company-contact-submit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('contact-company-popup').fade({ duration: 1 }); $('contact-company-popup').removeClassName('open'); }, 3000);

			});

			//SUBMIT buttons person

			$('person-contact-submit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('contact-person-popup').fade({ duration: 1 }); $('contact-person-popup').removeClassName('open'); }, 3000);

			});




		},

    addToDeals: function( ){
            var newDeal = function(){
                this.fade({
                    duration: 1.0
                });
                this.hide();
                $('add-new-deal').show();
                $('new-deal').checked = true;
                $('add-to-deals-select').checked = false;
                togleDealsSelection($('new-deal'));
            };

            if('existing' == $('add-to-deals-selection-mode').value){
                $('add-to-deals-select').checked = true;
                $('create-new-deal').setStyle('display:inline');
                $('add-new-deal').setStyle('display:none');

                //create new list link
                $('create-new-deal').observe('click', newDeal);

            }
            else if('existing-new' == $('add-to-deals-selection-mode').value){
                $('create-new-deal').setStyle('display:none');
                $('add-new-deal').setStyle('display:block');
                $('add-to-deals-select').checked = false;
                $('new-deal').checked = true;

               //create new list link
                $('create-new-deal').observe('click', newDeal);
            }
            GMX.popups.closeSetup();
            $$('a.button-cancel').each(function(item){
                item.stopObserving('click');
                item.observe('click', function(){
                    if(GMX.popups.idWrapperPopup != null){
                        $(GMX.popups.idWrapperPopup).fade({
                            duration: 0.3,
                            from: 1,
                            to: 0 ,
                            afterFinish: function(){
                                $('allover').style.display = "none";
                                $(GMX.popups.idWrapperPopup).removeClassName('open');
                                GMX.popups.idWrapperPopup = null;
                            }
                        });
                    }
                });
            });
        },

		getConnected: function(){

			//initialize the default display and hidden divs

			$$('#get-connected-popup div.step1').first().setStyle('display:block');

			$$('#get-connected-popup div.step1 #send-request').first().setStyle('display:none');

			$$('#get-connected-popup div.step2').first().setStyle('display:none');

			$$('#get-connected-popup div.step3').first().setStyle('display:none');

			$$('#get-connected-popup div.step4').first().setStyle('display:none');

			//none of the radio buttons  should be checked at first

			$$('.connection-options').each( function(item){

				item.checked = false;

			});

			//MUTUAL CONNECTION

			$('mutual-connection').observe('click', function(){

				$('send-request').hide();

				this.up(2).hide();

				this.up(2).next().show();

				//initialize the mutual connections select width

				$$('div.custom-select-wrapper').each(function(it){

					it.style.width = '200px';

				});

				$$('div.select-loaded').each(function(it){

					it.style.width = '200px';

				});

			});

			//SEND REQUEST

			$('request-connection').observe('click', function(){

				$('send-request').show();

			});

			//SEND button

			$('send-button').observe('click', function(){

				//form validation for "Connection selection"

				var isValid = true;

				if($('get-connected-select').selectedIndex == 0){

					isValid = false;

				}

				if(isValid){

					this.up(1).hide();

					this.up(1).next(1).show();

					setTimeout(function() { $('get-connected-popup').fade({ duration: 1 });$('get-connected-popup').removeClassName('open'); }, 3000);



				}else{

					this.up(1).hide();

					this.up(1).next(0).show();

					setTimeout(function() { $('get-connected-popup').fade({ duration: 1 });$('get-connected-popup').removeClassName('open'); }, 3000);

				}

			});

			//CONNECT button

			$('connect-submit').observe('click', function(){

				var isValid = false;

				$$('input.connection-options').each( function(it){

					if(it.checked){

						isValid = true;

					}

				});

				if(isValid){

					this.up(1).hide();

					this.up(1).next(2).show();

					setTimeout(function() { $('get-connected-popup').fade({ duration: 1 });$('get-connected-popup').removeClassName('open'); }, 3000);

				}

			});



		},

		giveScore: function(){

			$$('#score-popup div.step1').first().setStyle('display:block');

			$$('#score-popup div.step2').first().setStyle('display:none');

			//SUBMIT BUTTON

			$('score-commit').observe('click', function(){

				this.up(1).hide();

				this.up(1).next(0).show();

				setTimeout(function() { $('score-popup').fade({ duration: 1 }); $('score-popup').removeClassName('open'); }, 3000);

			});



		},

		shareWith: function(){

			$$('div#share-popup div.step1').first().setStyle('display:block');

			$$('div#share-popup div.step2').first().setStyle('display:none');

			$$('div#share-popup div.step3').first().setStyle('display:none');

			$$('div#share-popup div.step4').first().setStyle('display:none');

			//add existing connections - Step1

			$('share-to').value = "E-mail or existing connection";

			$('share-to').observe('focus', function(){

				this.value = "";

			});

			$$('div#share-popup div.step1 .add-existing').each(function(item){

				item.observe('click', function(){

					this.up(0).hide();

					this.up(0).next(0).show();

					this.up(0).next(0).down(0).next(0).show();

					this.up(0).next(0).down(0).next(1).hide();



					//cancel search for contacts

					$$('div#share-popup a.cancel-search').each(function(item){

						item.observe('click', function(){

							this.up(1).previous(0).show();

							this.up(1).hide();

						});

					});

					//search button

					$$('div#share-popup .search-button').each(function(item){

						item.observe('click', function(){

							this.up(1).next(1).show();

							this.up(1).next(0).hide();

						});

					});

					//DONE

					$('done-submit').observe('click', function(){

						this.up(3).next(0).show();

						this.up(3).hide();

						$$('div a.recipient-name-close').each(function(item){

							item.observe('click', function(){

								this.up(1).hide();

							});

						});

						//SHARE BUTTON

						$$('div#share-popup div.step3 .share-submit').each(function(item){

							item.observe('click', function(){

								item.up(1).hide();

								$('share-step4').show();

								setTimeout(function() { $('share-popup').fade({ duration: 1 });$('share-popup').removeClassName('open'); }, 3000);

							});

						});

					});

					$$('div.step2 a.cancel-select').each(function(item){

						item.observe('click', function(){

							this.up(4).down(0).next(0).show();

							this.up(3).hide();

						});

					});

				});

			});



			//add existing connections - Step3

			$$('div#share-popup div.step3 .add-existing').each(function(item){

				item.observe('click', function(){

					this.up(0).hide();

					$('share-step2').show();

					//search button

					$('search-button').stopObserving('click');

					$('search-button').observe('click', function(){

						return false;

					});

					//DONE

					$('done-submit').stopObserving('click');

					$('done-submit').observe('click', function(){

						this.up(2).hide();

						$('share-step3').show();



					});

				});

			});





			//SHARE BUTTON

			$$('div#share-popup div.step1 .share-submit').each(function(item){

				item.observe('click', function(){

					item.up(1).hide();

					$('share-step4').show();

					setTimeout(function() { $('share-popup').removeClassName('open');$('share-popup').fade({ duration: 1 }); }, 3000);

				});

			});





			$$('div.step3 a.button-cancel').each( function(it){

			   it.observe('click', function(){

					$('share-popup').removeClassName('open');

					$('share-popup').fade({ duration: 0.3 });

				});

			});

		},



		setAlert: function(){

			$$("#set-alert-popup div.step1").first().setStyle('display:block');

			$$("#set-alert-popup div.step2").first().setStyle('display:none');

			//SUBMIT ALERT

			$('submit-alert').observe('click', function(){

				this.up(1).hide();

				this.up(1).next().show();

				setTimeout(function() { $('set-alert-popup').fade({ duration: 1 });$('set-alert-popup').removeClassName('open'); }, 3000);

			});



		},



		getPermission: function(){

			//initialize visible divs

			$$('#get-permissions-popup div.step1').first().setStyle('display:block');

			$$('#get-permissions-popup div.step2').first().setStyle('display:none');

			//when click to add text , the default one should disappear

			$('message-box').value = "Optional message...";

			$('message-box').observe('focus', function(){

				this.value = "";

			});

			//submit button

			$('submit-request').observe('click', function(){

				this.up(1).hide();

				this.up(1).next(0).show();

				setTimeout(function() { $('get-permissions-popup').fade({ duration: 1 });$('get-permissions-popup').removeClassName('open'); }, 3000);

			});



		},



		setup: function(){



			//GMX.select.setup();





			if($('add')){

				/*$('add').down(0).observe('click',function(){

					GMX.popups.launchPopUp('add-to');

					GMX.innerPopups.addTo();



				});*/

			}

			if($('share')){

				/*$('share').down(0).observe('click',function(){

					GMX.popups.launchPopUp('share-popup');

					GMX.innerPopups.shareWith();

				});*/

			}

			if($('alert')){

				/*$('alert').down(0).observe('click',function(){

					GMX.popups.launchPopUp('set-alert-popup');

					GMX.innerPopups.setAlert();

				});*/

			}

			if($('contact')){

				/*$('contact').down(0).observe('click',function(){

						// open popup

					GMX.popups.launchPopUp('contact-seller-popup');

					GMX.innerPopups.contact('seller');

				});*/

			}

			if($('connect')){

				/*$('connect').down(0).observe('click',function(){

						// open popup

					GMX.popups.launchPopUp('get-connected-popup');

					GMX.innerPopups.getConnected();

				});*/

			}

			if($('score')){

				/*$('score').down(0).observe('click',function(){

						// open popup

					GMX.popups.launchPopUp('score-popup');

					GMX.innerPopups.giveScore();

				});*/

			}

			if($('permissions')){

				/*$('permissions').down(0).observe('click',function(){

					GMX.popups.launchPopUp('get-permissions-popup');

					GMX.innerPopups.getPermission();

				});*/

			}







			/* BUTTONS: DROPDOWN BAR

			----------------------------------------------------- */

            $$('a.add').each(

            function(el){

                el.observe('click',

                function(){

                    // Findout which OPTION is clicked and get the itemId,type and name associated with it.

                    var itemType;

                    var itemId;

                    var itemName;

                    var popupPanel='option-add-to-popup';

                    var toolbarDiv=GMX.options.current_option;

                    toolbarDiv = toolbarDiv.childNodes;

                    if(toolbarDiv && toolbarDiv.length > 0){

                        for( var i=0; i < toolbarDiv.length; i++){

                            var child = toolbarDiv[i];

                            if(child && child.type == 'hidden' && child.id.indexOf("itemType", 0) >= 0 ){

                                itemType = "" +child.value;

                            }else if(child && child.type == 'hidden' && child.id.indexOf("itemId", 0) >= 0 ){

                                itemId = "" + child.value;

                            }else if(child && child.type == 'hidden' && child.id.indexOf("itemName", 0) >= 0 ){

                                itemName = "" + child.value;

                            }

                        }

                    }



                    $('itemid-for-addto-option').value=itemId;

                    $('itemtype-for-addto-option').value=itemType;

                    $('itemname-for-addto-option').value=itemName;

                    // Launch popup

                    GMX.popups.launchPopUp('option-add-to-popup');

                    updateAddToPopup();

                }

            );

            });

			$$('a.share').each(

				function(el){

					el.observe('click',

						function(){

							GMX.popups.launchPopUp('share-popup');

							GMX.innerPopups.shareWith();

						});

				}

			);



			$$('a.alert').each(

				function(el){

					el.observe('click',

						function(){

							GMX.popups.launchPopUp('set-alert-popup');

							GMX.innerPopups.setAlert();

						});

				}

			);



			$$('a.contact').each(

				function(el){

                            el.observe('click',

                                function(){
                            // Findout which OPTION is clicked and get the itemId,type and name associated with it.

                            var itemType;

                            var itemId;

                            var itemName;

                            var popupPanel='option-contact-popup';

                            var toolbarDiv=GMX.options.current_option;

                            toolbarDiv = toolbarDiv.childNodes;

                            if(toolbarDiv && toolbarDiv.length > 0){

                                for( var i=0; i < toolbarDiv.length; i++){

                                    var child = toolbarDiv[i];

                                    if(child && child.type == 'hidden' && child.id.indexOf("itemType", 0) >= 0 ){

                                        itemType = "" +child.value;

                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemId", 0) >= 0 ){

                                        itemId = "" + child.value;

                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemName", 0) >= 0 ){

                                        itemName = "" + child.value;

                                    }

                                }

                            }



                            $('itemid-for-contact-option').value=itemId;

                            $('itemtype-for-contact-option').value=itemType;

                            $('itemname-for-contact-option').value=itemName;

                            // Launch popup

                            GMX.popups.launchPopUp('option-contact-popup');

                            updateContactPopup();

						});

				}

			);

			$$('a.score').each(
                function(el){
                    el.observe('click',
                        function(){
                            var itemType;
                            var itemId;
                            var itemName;
                            var popupPanel='option-add-to-deals-popup';
                            if($(popupPanel)){
                            var toolbarDiv=GMX.options.current_option;
                            toolbarDiv = toolbarDiv.childNodes;
                            if(toolbarDiv && toolbarDiv.length > 0){
                                for( var i=0; i < toolbarDiv.length; i++){
                                    var child = toolbarDiv[i];
                                    if(child && child.type == 'hidden' && child.id.indexOf("itemType", 0) >= 0 ){
                                        itemType = "" +child.value;
                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemId", 0) >= 0 ){
                                        itemId = "" + child.value;
                                    }else if(child && child.type == 'hidden' && child.id.indexOf("itemName", 0) >= 0 ){
                                        itemName = "" + child.value;
                                    }
                                }
                            }
                            $('itemid-for-addto-deals-option').value=itemId;
                            $('itemtype-for-addto-deals-option').value=itemType;
                            $('itemname-for-addto-deals-option').value=itemName;
                            if($('user-role-select')){
                                $('user-role-select').show();
                            }
                            GMX.popups.launchPopUp(popupPanel);
                            updateDealsPopup();
                            }
                        });
                }
			);

			$$('a.permissions').each(

				function(el){

					el.observe('click',

						function(){

							GMX.popups.launchPopUp('get-permissions-popup');

							//GMX.popups.launchPopUp('get-permissions-popup');

							GMX.innerPopups.getPermission();

						});

				}

			);



			// CHECK TO SEE IF THE COMPARE VERSIONS BUTTON IS CLICKED

			$$('a.compare-versions-btn', 'a.close-popup-btn').each(function(el){

				el.observe('click',function(){

					// close popup

					GMX.popups.launchComparePopUp('compare-popup');

				});

			});





		}



	},

	popups: {

		idWrapperPopup:null,

		/* POPUP DROP SHADOW SCRIPT

		------------------------------------------------------------- */

		// adds a drop shadow to a given element/popup

		addDropShadow: function(element){

			element = $(element);

			// create diff sections of drop shadow

			var i1 = new Element('div', { 'class': 'i1' });

			var i2 = new Element('div', { 'class': 'i2' });

			var i3 = new Element('div', { 'class': 'i3 cf' });



			i2.appendChild(i3);

			i1.appendChild(i2);



			$A(element.childNodes).each(function(e){ i3.appendChild(e); });

			// create the divs that will contain the shadow images

			var bfunc = function(className){

				var e = new Element('div', { 'class': className });

				e.appendChild(new Element('div'));

				return e;

			};



			element.addClassName('cp');

			element.appendChild(bfunc('bt'));

			element.appendChild(i1);

			element.appendChild(bfunc('bb'));

		},

		/* POPUP SCRIPT FOR COMPARE VERSIONS

		------------------------------------------------------------- */

		launchComparePopUp: function(element) {

			element = $(element);

			for (var n = 1; n < 4; n++){

				var hiddentables = $$('.hidden-table'+n);

				hiddentables.each(

					function(el){

						el.style.display = 'none';

				});

			}

			checkboxes = $$('#filter-bar input');

			checkboxes.each(function(elem){

				elem.observe('click', function(){

				checked = 0;

				for(var i = 0; i < checkboxes.length; i++){

					if (checkboxes[i].checked == true){

						checked++;

					}

				}

				if(checked == 0) {

					//uncheck all but first box

					for (var n=0; n < checkboxes.length; n++){

						if(n != 0){

							checkboxes[n].checked = false;

						}else{

							checkboxes[n].checked = true;

						}

					}

					element.style.width = "515px";

					element.toggleClassName('open');

					element.fade({ duration: 0.3, from: 1, to: 0 });

				}



				if (checked == 4){

					checkboxes.each(

						function(el){

							if (el.checked == false){

								el.disabled = true;

							}

						});

				}



				//check to make sure no more than 4 boxes are checked

				if(checked <= 4){

					if(elem.checked){ //do this if they checked the box

						for (var n = 1; n < (checked); n++){

							var hiddentables = $$('.hidden-table'+n);

							if (hiddentables[0].getStyle("display") == "none"){

								hiddentables.each(

									function(el){

										el.style.display = '';

								});

							}

						}

					}else{ // do this if they unchecked the box

						var hiddentables = $$('.hidden-table'+checked);

						hiddentables.each(

							function(el){

								el.style.display = 'none';

							});

						checkboxes.each(

							function(el){

								el.disabled = false;

						});

					}

					switch(checked)

					{

						case 1:

							element.style.width = "515px";

							centerComparePopUp();

							break;

						case 2:

							element.style.width = "680px";

							centerComparePopUp();

							break;

						case 3:

							element.style.width = "845px";

							centerComparePopUp();

							break;

						case 4:

							element.style.width = "1020px";

							centerComparePopUp();

							break;



					}



				}else{

					elem.checked = false;

					alert("You may only select up to 4 options");

				}

				});

			});



			if(element.hasClassName('open')){

				//uncheck all but first box

				for (var n=0; n < checkboxes.length; n++){

					checkboxes[n].disabled = false;

					if(n != 0){

						checkboxes[n].checked = false;

					}

				}

				element.style.width = "515px";

				element.toggleClassName('open');

				element.fade({ duration: 0.3, from: 1, to: 0 });

			} else {

				element.appear({ duration: 0.3, from: 0, to: 1 });

				element.toggleClassName('open');



				centerComparePopUp = function(){

					var thePopup = $(element);

					var scr = document.viewport.getScrollOffsets();

					var dim = document.viewport.getDimensions();



			 		thePopup.style.top = (dim.height / 2 - thePopup.getHeight() / 2) + scr.top + 'px';

			 		thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';

			 		if(!thePopup.hasClassName('shadow')){

			 			GMX.popups.addDropShadow(thePopup);

			 			thePopup.addClassName('shadow');

			 		}

				}



				centerComparePopUp();

				// keep popup in center while scrolling

				Event.observe(window, 'resize', centerComparePopUp);

				Event.observe(window, 'scroll', centerComparePopUp);



			}

		},

		/* POPUP SCRIPT

		------------------------------------------------------------- */

        launchPopUp: function(element) {

            this.idWrapperPopup = element;

            //------------------------------------------------------------//

            /* if any other popup is open , let's close it */

            $$('div.open').each(function(item){

                if(element != item.readAttribute('id') && item.hasClassName('open')){

                    item.removeClassName('open');

                    item.hide();

                    this.idWrapperPopup = null;

                }

            });

            //------------------------------------------------------------//

            element = $(element);

            if(element.hasClassName('open')){

                // if its open then close it

                element.removeClassName('open');

                element.fade({

                    duration: 0.3,

                    from: 1,

                    to: 0

                });

                this.idWrapperPopup = null;



            } else {

                //open popup

                this.idWrapperPopup = element.readAttribute('id');

                element.appear({

                    duration: 0.3,

                    from: 0,

                    to: 1

                });

                $('allover').style.display = "block";

                $('allover').style.height = document.body.scrollHeight + 'px';

                element.addClassName('open');



                // function to center the popup on screen

                centerPopUp = function(){

                    var thePopup = $(element);

                    var scr = document.viewport.getScrollOffsets();

                    var dim = document.viewport.getDimensions();

                    // set it in middle



                    if(thePopup.getHeight() >= dim.height){

                        thePopup.style.top = scr.top + 10 + 'px';

                        thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';



                    } else {

                        thePopup.style.top = (dim.height / 2 - thePopup.getHeight() / 2) + scr.top + 'px';

                        thePopup.style.left = (dim.width / 2 - thePopup.getWidth() / 2) + scr.left + 'px';

                    }



                    // Add the dropshadow to the element

                    if(!thePopup.hasClassName('shadow')){

                        GMX.popups.addDropShadow(thePopup);

                        thePopup.addClassName('shadow');

                    }



                }

                // center

                centerPopUp();

                // keep popup in center while scrolling

                Event.observe(window, 'resize', centerPopUp);

            //Event.observe(window, 'scroll', centerPopUp);

            }



            this.closeSetup();



            //SUBMIT POPUP

            //$$('div.buttons .submit-btn').each(function(item){

            //    item.observe('click', function(){

            //        this.stopObserving('click');

            //        this.up(1).hide();

            //        $$('#'+GMX.popups.idWrapperPopup+' div.confirm').first().show();

            //        centerPopUp();

            //        setTimeout(function() {

            //            $(GMX.popups.idWrapperPopup).fade({

            //                duration: 1 ,

            //                afterFinish: function(){

            //                    $(GMX.popups.idWrapperPopup).removeClassName('open');

            //                    GMX.popups.idWrapperPopup = null;

            //                }

            //            });

            //        }, 3000);

            //    });

            //});

        },

        closeSetup: function(){

            try{

                // CHECK TO SEE IF POP CLOSE BUTTON IS CLICKED

                $$('a.close-popup-btn2').each(function(el){

                    Event.stopObserving(el, 'click');
                    el.observe('click',function(){

                        if(GMX.popups.idWrapperPopup != null){

                            $(GMX.popups.idWrapperPopup).fade({

                                duration: 0.3,

                                from: 1,

                                to: 0,

                                afterFinish: function(){

                                    try{

                                        $('allover').style.display = "none";

                                        $(GMX.popups.idWrapperPopup).removeClassName('open');

                                        GMX.popups.idWrapperPopup = null;

                                    }catch(exp){}

                                }

                            });



                        }

                        else{

                            this.up(4).fade({

                                duration: 0.3,

                                from: 1,

                                to: 0

                            });

                            $('allover').style.display = "none";

                            this.up(4).removeClassName('open');

                        }

                    });

                });

                //CANCEL POPUP - step 1 only!!!

                $$('div.step1 a.button-cancel').each(function(item){

                    Event.stopObserving(item, 'click');

                    item.observe('click', function(){

                        if(GMX.popups.idWrapperPopup != null){

                            $(GMX.popups.idWrapperPopup).fade({

                                duration: 0.3,

                                from: 1,

                                to: 0 ,

                                afterFinish: function(){

                                    $('allover').style.display = "none";

                                    $(GMX.popups.idWrapperPopup).removeClassName('open');

                                    GMX.popups.idWrapperPopup = null;

                                }

                            });



                        }

                    });

                });

            }catch(exp){}

        },

        setup: function(){



        }

 },

 characters_count:{

  //element - the id of the textarea for which we will count the characters

  //limit - the number of characters maximum allowed

  //countCh - the id of the element which will show how many characters we still have to use

  countCh:function(element,limit,countCh){

   var element = $(element);

   var elemSize = limit - element.value.length;

   var countCh = $(countCh);

   if(countCh) countCh.innerHTML = elemSize;

   $(element).observe('keyup',function(){

    if(limit - this.value.length >0){

     if(countCh) countCh.innerHTML = limit - this.value.length;

    }else{

     if(countCh) countCh.innerHTML = 0;

     this.value = this.value.substr(0,limit);

    }

   });

   element.observe('keydown',function(){

    if(limit - this.value.length >0){

     if(countCh) countCh.innerHTML = limit - this.value.length;

    }else{

     if(countCh) countCh.innerHTML = 0;

     this.value = this.value.substr(0,limit);

    }

   });

  },

  setup: function(){



  }



 },


selectManyCheckbox:{
   setup: function(){
       $$('table.select-many-chkbox tr input').each(function(inputChk){
            inputChk.stopObserving('click');
            inputChk.observe('click',function(){
                this.parentNode.addClassName('fakeClass');
            });
        });
        $$('table.select-many-chkbox tr label').each(function(inputLabel){
            inputLabel.stopObserving('mousedown');
            inputLabel.observe('mousedown',function(){
                this.parentNode.addClassName('fakeClass');
            });
        });
        $$('table.select-many-chkbox td').each(function(parentTd){
            parentTd.style.width= '100%';
            parentTd.stopObserving('mouseover');
            parentTd.observe('mouseover',function(){
                this.style.backgroundColor='#CCC';
            });
            parentTd.stopObserving('mouseout');
            parentTd.observe('mouseout',function(){
                this.style.backgroundColor='#FFF';
            });
            parentTd.stopObserving('click');
            parentTd.observe('click',function(){
                var chk = this.down(0);
                if(this.hasClassName('fakeClass')){
                    this.removeClassName('fakeClass');
                }else{
                    if(chk && !chk.disabled && chk.checked){
                        chk.checked=false;
                    }else if(chk && !chk.disabled && !chk.checked){
                        chk.checked=true;
                    }
                }
            });
        });
    }
  }
};



Event.observe(window, 'load', function(){



if(Prototype.Browser.IE){



	GMX.utility.ie.btnfix();

	// fix IE 6 problems requesting background images on mouseover

	try {

		document.execCommand("BackgroundImageCache", false, true);

	} catch(err){}

	GMX.utility.ie.pngfix();

}



 // initialize gmx_menu

 GMX.gmx_menu.setup();

 // initialize navigation

 GMX.dropdown_navigation.setup();

 GMX.navigation.setup();





});







function getScrollOffsetX(){

	var x=0;

	if (self.pageXOffset) {// all except Explorer

		x = self.pageXOffset;

	}else if (document.documentElement && document.documentElement.scrollLeft)	{

		x = document.documentElement.scrollLeft;

	}else if (document.body){ // all other Explorers

		x = document.body.clientWidth;

	}

    return x;



}



function getScrollOffsetY(){

	var y=0;

	if (self.pageYOffset){ // all except Explorer

		y = self.pageYOffset;

	}else if (document.documentElement && document.documentElement.scrollTop){

		y = document.documentElement.scrollTop;

	}else if (document.body){ // all other Explorers

		y = document.body.clientHeight;

	}

    return y;

}



    function posX() {

        return (document.body) ? document.body.scrollLeft : window.pageXOffset;

    }

    function posY() {

        return (document.body) ? document.body.scrollTop : window.pageYOffset;

    }

/* ----------------- Code Migrated from global-am.js -------------------- */

/* Function for testing textarea limit validation */

function createObject(objId) {
    if (document.getElementById) return document.getElementById(objId);
    else if (document.layers) return eval("document." + objId);
    else if (document.all) return eval("document.all." + objId);
    else return eval("document." + objId);
}


function limitText(limitField, limitCount, limitNum, eve) {

    var unicode=eve.charCode? eve.charCode : eve.keyCode ;
    limitCount = document.getElementById(limitCount);
    limitCount.value = limitNum - limitField.value.length+" characters remaining";

    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
    else if (limitField.value.length == limitNum) {
        if (unicode!=8 && unicode!=46 && (unicode <37 || unicode>40)){
            return false;
        }
    }
}

function resetCounter(limitField, limitCount, limitNum){
    document.getElementById(limitCount).value = limitNum - document.getElementById(limitField).value.length+" characters remaining";

}

/* Function for limiting the input characters in textarea
limitField - the id of the textarea for which we will count the characters
showCount - the id of the element which will show how many characters we still have to use
limitNum - the number of characters maximum allowed
eve - the event on the textarea
 */
function limitTextarea(limitField, showCount, limitNum, eve) {
    var unicode=eve.charCode? eve.charCode : eve.keyCode ;
    showCount = document.getElementById(showCount);
    var countChar = limitNum - limitField.value.length;

    if(eve.ctrlKey && (eve.charCode == 97 || eve.charCode == 99 ||  eve.charCode == 120 || eve.charCode == 65 || eve.charCode == 67 ||eve.charCode == 88  )){
        //console.debug('eve.charCode : '+ eve.charCode );
        return true;
    }else if(eve.ctrlKey && (eve.charCode == 86 || eve.charCode == 118)){

        if(countChar == 0){
            //console.debug('Paste not allowed');
            return false;
        }else{
            if (limitField.value.length > limitNum) {
                limitField.value = limitField.value.substring(0, limitNum);
                return;
            }
        }
    }

    if(countChar >= limitNum) {
        showCount.innerHTML =  countChar+" characters maximum";
    } else {
        showCount.innerHTML =  countChar+" characters remaining";
    }

    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
    else if (limitField.value.length == limitNum) {
        if (unicode!=8 && unicode!=46 && (unicode <37 || unicode>40)){
            return false;
        }
    }
}


function textCounter(field,cntfield,maxlimit) {
    showCount = document.getElementById(cntfield);
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else{
        //cntfield.value = maxlimit - field.value.length;
        if(countChar == limitNum) {
            showCount.innerHTML =  countChar+" characters maximum";
        }
        else {
            showCount.innerHTML =  countChar+" characters remaining";
        }
    }
}

/* Function for setting the value onload
limitField - the id of the textarea for which we will count the characters
showCount - the id of the element which will show how many characters we still have to use
limitNum - the number of characters maximum allowed
 */
function resetCounterText(limitField, showCount, limitNum){
    showCount = document.getElementById(showCount);
    var countChar = limitNum - document.getElementById(limitField).value.length;
    if(countChar == limitNum) {
        showCount.innerHTML =  countChar+" characters maximum";
    }
    else {
        showCount.innerHTML =  countChar+" characters remaining";
    }

}

/*This function can be used to limit the maximum characters in a textarea or h:inputTextarea
 maxlength is not an attribute of these components so the solution is to do it with javascript*/
function textAreaMaxLength(field, maxLimit){
    if(field.value.length > maxLimit){
        field.value = field.value.substring(0,maxLimit);
    }
}

//Dynamically changes the height of the element by adding the amount of pixels specified.
function changeElementHeight(el, pixels){
    var panelHeight = el.getHeight();
    panelHeight = panelHeight + pixels;
    el.style.height = panelHeight+'px';
}

//
function showLoadingIndicator(spinnerDivElement, replacementDivElement) {
    spinnerDivElement.style.display = "block";
    replacementDivElement.style.display = "none";
}

function hideLoadingIndicator(spinnerDivElement, replacementDivElement) {
    spinnerDivElement.style.display = "none";
    replacementDivElement.style.display = "block";
}


function tipsetup(orgContainer, dummyContainer){

    var appearFunc = function(){
        //dummyContainer.style.opacity = '0.1';
        try{
            var tmp = dummyContainer.firstChild.nextSibling.nextSibling.nextSibling.firstChild.nextSibling.nextSibling.nextSibling;
            if(tmp){
                tmp.style.opacity='0.1';
            }
        }catch(err){ }
        orgContainer.innerHTML = dummyContainer.innerHTML;


        $('tips-data-div').appear({
            duration: 0.5,
            from: 0.1,
            to: 1
        });
    }
    $('tips-data-div').fade({
        duration: 0.5,
        from: 1,
        to: 0.1,
        afterFinish: appearFunc
    });
}

function sleepMillis(millis)
{
    var date = new Date();
    var curDate = null;

    do {
        curDate = new Date();
    }
    while(curDate-date < millis);
}
var nextLinkOnClick = function(){

    var reqUrl = requestContext + '/content/components/support_center/try_this.jsf';

    var dummyContainer = document.createElement('div');
    new Ajax.Updater(dummyContainer, reqUrl,
    {
        method: "get",
        onComplete: function(req){
            if(req.responseText != null &&  req.responseText != ''){
                var responseText =  req.responseText;
                if(responseText.indexOf('homePage()', 0) > 0 ){
                    //alert('Your session expired...');
                    location.href=requestContext;
                    return;
                }else{
                    tipsetup($('tips-portlet-div'),dummyContainer);
                }
            }
        },
        onFailure: function(){
            alert('Something gone wrong...');
        }
    });

    return false;
}

var setTitleVal = function(id,val){
    if(!val){
        val = $(id).value;
    }
    if($(id)){
        ($(id)).setAttribute('title',val);
    }
}


function showWaitCursor(){
    document.body.style.cursor='wait';
}

function showDefaultCursor(){
    document.body.style.cursor='default';
}