//Event.onReady(function () {
//  GMapIt.init();
//  SizeTheGlow.doit();
// if ( $('map') ) { window.onunload = GUnload; }
/* if ( isMainIndexPage && isIE6 ) { IE6Fix.doit(); }
 /* if ( $( 'notice' ) ) {
 if ( isMainIndexPage ) { new Effect.ScrollTo( 'notice', { offset:-20 } ); }
 $( 'notice' ).visualEffect('pulsate', { delay:1, duration:1.5 });
 }*/

//});


//Event.addBehavior( {
//  'ul.results-set li:click': function ( e ) {
//    var new_html = this.innerHTML;
//    lat = this.select( '[class="latitude"]')[ 0 ].innerHTML;
//    lng = this.select( '[class="longitude"]')[ 0 ].innerHTML;
//    $( 'details' ).update(new_html);
//    GMapIt.doMap( lat, lng );
//  },




//'.sub-selected-icon:click': function ( e ) {
//  var ids = this.id.split( "_" );
//  var link_id = ids.pop();
//  var current_id = ids.pop();
//  $( 'result_set_' + current_id ).hide();
//  $( 'result_set_' + link_id ).show();
//  $$( 'ul.results-set' ).each( function( item ) { new Effect.Highlight( item, { startcolor: '#B8CCCC', endcolor: '#C9CCCC' } ) } );
//},

//'div.category-icon:click': function ( e ) {
//var cat_string = this.id.split( "-" );
//var cat_id = cat_string.pop();
//$$( 'div.category-icon' ).each( function ( item ) { item.removeClassName( 'c-selected' ) } );
//this.addClassName( 'c-selected' );
//$('subcategory-boxes').style.height = $( 'subcategory-box-' + cat_id ).getHeight() + "px";
//$$( 'ul.subcategory-box' ).each( function ( item ) { item.hide() } );
//$( 'subcategory-box-' + cat_id ).visualEffect( 'appear', { duration:1 } );
// this does not work
// if ( isIE6 ) { window.scroll( 0, $( 'page' ).scrollHeight ); }
//},

//  'ul.hover li:mouseover'           : function ( e ) { this.addClassName( 'hover' ) },
//  'ul.hover li:mouseout'            : function ( e ) { this.removeClassName( 'hover' ) },
//  'button.back-to-home:click'       : function ( e ) { document.location.href = '/main/index' },
//  'button.back-to-home:mouseover'   : function ( e ) { this.addClassName( 'hover' ) },
//  'button.back-to-home:mouseout'    : function ( e ) { this.removeClassName( 'hover' ) },
//  'button.left:click'               : function ( e ) {
//                                        CatsSlide.moveLeft();
//                                        catIndex--;
//                                        CatsSlide.showHideButtons();
//                                        if ( catIndex < 0 ) { catIndex = 0 };
//                                        return false;
//                                      },
//  'button.right:click'              : function ( e ) {
//                                        CatsSlide.moveRight();
//                                        catIndex++;
//                                        CatsSlide.showHideButtons();
//                                        if ( catIndex > ( catLastIndex - catLimit ) ) { catIndex = catLastIndex - catLimit; }
//                                        return false;
//                                     },
//  'li.q-selected:mouseover'        : function ( e ) {
//                                      var removeit_node = this.select( 'span.removeit' );
//                                      removeit_node[ 0 ].show();
//                                    },
//  'li.q-selected:mouseout'        : function ( e ) {
//                                      var removeit_node = this.select( 'span.removeit' );
//                                      removeit_node[ 0 ].hide();
//                                    },
//  'input#search_in:click'         : function ( e ) {
//                                      var inner = this.value;
//                                      if ( inner == "Zipcode or City, ST" ) { this.value = ''; }
//                                      var thebutton = $( 'go-button' );
//                                      thebutton.removeClassName( 'wait' );
//                                      thebutton.disabled = false;
//                                      thebutton.blur();
//                                    },
//  'input#search_in:blur'          : function ( e ) {
//                                      if ( this.value == "" ) {
//                                        this.value = "Zipcode or City, ST";
//                                      }
//                                      if ( this.value == "Zipcode or City, ST" ) {
//                                        var thebutton = $( 'go-button' );
//                                        thebutton.addClassName( 'wait' );
//                                        thebutton.disabled = true;
//                                        thebutton.blur();
//                                      }
//                                    }
//} )

var IE6Fix = {
    doit            : function () {
        first_row = $$('ul.subcategory-box')[ 0 ];
        first_row.hide();
        first_row.show();
    }
}

var CatsSlide = {

    moveLeft: function () {
        //icons = $$( 'div.category-icon' );
        icons = $$('.move_categories');

        icons.each(function(element) {
            sections = element.id.split("-");
            id = sections[ 2 ];
            if (id == (catIndex + catLimit ))  new Effect.Fade(element, { duration: 0.3 });
        })
        icons.each(function(element) {
            sections = element.id.split("-");
            id = sections[ 2 ];
            if (id == catIndex) new Effect.Appear(element, { delay: 0.5, duration: 0.3 });
        })
    },
    moveRight: function () {
        icons = $$('.move_categories');
        icons.each(function(element) {
            sections = element.id.split("-");
            id = sections[ 2 ];
            if (id == catIndex) new Effect.Fade(element, { duration: 0.3 });
        })
        icons.each(function (element) {
            sections = element.id.split("-");
            id = sections[ 2 ];
            if (id == ( catIndex + catLimit )) new Effect.Appear(element, { delay: 0.5, duration: 0.3 });
        })
    },
    showHideButtons    : function () {
        $$('#category-box button').each(function(item) {
            item.disabled = false;            
        });
        if (catIndex < 0) {$('left-button').disabled = true};
        if (catIndex > ( catLastIndex - catLimit )) {$('right-button').disabled = true;};
    }
};

var GU = {
    doDropProcedureOnBox  : function (el) {
        Element.hide(el);
        $$('#dropbox li').each(function (item) {
            item.removeClassName('hovering')
        });
    },
    hoveringDropBoxItems  : function () {
        $$('#dropbox li').each(function (item) {
            item.addClassName('hovering')
        });
    }
}

var GMapIt = {

    init      : function () {
        if ($('details')) {
            var lat = $('details').select('[class="latitude"]')[ 0 ].innerHTML;
            var lng = $('details').select('[class="longitude"]')[ 0 ].innerHTML;
            GMapIt.doMap(lat, lng);
        }
    },

    doMap     : function (lat, lng) {
        var centerLatitude = lat;
        var centerLongitude = lng;
        var startZoom = 14;
        var map;
        if (GBrowserIsCompatible())
        {
            map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            var location = new GLatLng(centerLatitude, centerLongitude);
            map.setCenter(location, startZoom);

            var marker = new GMarker(location);
            map.addOverlay(marker);
        }
    }
}

var SizeTheGlow = {
    doit      :function () {
        if ($('glow')) {
            $('glow').firstChild.style.height = ( $('page').getHeight() + 150 ) + 'px';
        }
    }
}
