var min_height = 0;
var footer2 = false;
var browser;
var version;
var color;

$(function() {
  var page = $('body').attr('id');
  var usr_os = $.client.os;
  browser = $.client.browser;
  version = $.browser.version;
  version = version.substr(0,1);

  $('body').addClass(usr_os);
  $('body').addClass(browser);
  $('body').addClass('version_'+version);

  set_color(page);

  if (page == 'rental') {
    add_tab_hover();
    add_scroller();
  }

  /*
  $('#wrap #header a.link.dropshadow').click(function(ev) {
    ev.preventDefault();

    var href = $(this).attr('href');
    var href_len = href.length - 4;
    var id = href.substr(0, href_len);
    if (id == 'index') id = 'home';
    set_color(id);

    href = id + '.html';


    $.ajax({
      url: href,
      cache: false,
      success: function(html) {
        $('#background_image').toggleClass('toggled');
        $('#main .center').fadeOut(300, function() {
          $('#header, #footer, #footer .center').animate({'background-color' : '#FFFFFF'}, 300, function() {
            $('body').attr('id', id);
            $('#main .center').empty().append(html);
            $('#background_image').toggleClass('toggled');
            $('#main .center').fadeIn(200, function() {
              $('#header, #footer, #footer .center').animate({'background-color' : color});
            });
          });
        });
      }
    });
  });
  */
});

function set_color(page) {
  switch (page) {
    case 'home':
      color = '#5e9fcc';
      min_height = 675;
      break;
    case 'tank_maintenance':
      color = '#bbb4ab';
      break;
    case 'construction_services':
      color = '#429f8b';
      break;
    case 'filtration_services':
      color = '#4893e8';
      break;
    case 'rental':
    case 'equipment_listing':
      color = '#acb2bc';
      break;
  }

  add_hovers(color);
}

function add_tab_hover() {
  var opacity = (browser == 'Explorer') ? '0.8' : '1';
  $('.slideshow_tab').hover(function() {
    $(this).find('img').stop().animate({'opacity' : opacity}, 500);
    if ($(this).hasClass('left_tab')) {
      $(this).stop().animate({'left' : '17px'}, 500);
    }
    else {
      $(this).stop().animate({'left' : '-7px'}, 500);
    }
  }, function() {
    $(this).find('img').stop().animate({'opacity' : '0.4'}, 500);
    if ($(this).hasClass('left_tab')) {
      $(this).stop().animate({'left' : '22px'}, 500);
    }
    else {
      $(this).stop().animate({'left' : '-14px'}, 500);
    }
  });
}

function add_scroller() {
  // custom easing called "custom"
  $.easing.custom = function (x, t, b, c, d) {
    var s = 1.70158;
    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  }


  $("#slideshow").scrollable({next: ".right_tab", prev: ".left_tab", easing: 'custom', speed: 700, circular: true}).autoscroll({interval: 4000});
}

function add_hovers(color) {
    $('#navigation li, #header h1, #header .drop').unbind().hover(function() {
      $(this).find('a.link').stop().animate({'color' : color}, 700);
    }, function() {
      $(this).find('a.link').stop().animate({'color' : '#ffffff'}, 700);
    });

    $('#footer .center a').unbind().hover(function() {
      $(this).stop().animate({'color' : color}, 700);
    }, function() {
      $(this).stop().animate({'color' : '#ffffff'}, 700);
    });

    $('.box a').unbind().hover(function() {
      $(this).stop().animate({'color' : color}, 700);
    }, function() {
      $(this).stop().animate({'color' : '#ffffff'}, 700);
    });
}

function adjust_messed_up() {
  $('.dropshadow').each(function() {
    var cur_id = $(this).attr('id');
    if (cur_id == '' || cur_id == 'f_spec_1' || cur_id == 'f_spec_2') {
      cur_id = $(this).parent().attr('id');
    }
    switch (cur_id) {
      case 'home_link':
      case 'slide_header':
      case 'call_now':
      case 'email_us':
      case 'hours':
        if (cur_id == 'slide_header' && browser == 'Explorer' && version == '7') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '2px', 'left' : '-1px'});
                break;
              case 2:
                $(this).css({'top' : '2px', 'left' : '1px'});
                break;
              case 3:
                $(this).css({'top' : '4px', 'left' : '0px'});
                break;
              case 4:
                $(this).css({'top' : '5px', 'left' : '0px'});
                break;
              case 5:
                $(this).css({'top' : '5px', 'left' : '2px'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '-1px', 'left' : '0px'});
                break;
              case 2:
                $(this).css({'top' : '0px', 'left' : '1px'});
                break;
              case 3:
                $(this).css({'top' : '0px', 'left' : '-1px'});
                break;
              case 4:
                $(this).css({'top' : '2px', 'left' : '0px'});
                break;
              case 5:
                $(this).css({'top' : '3px', 'left' : '-2px'});
                break;
            }
            i++;
          });
        }
        break;
      case 'filtration_email':
        if (browser == 'Explorer' && version == '7') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'left' : '-1px', 'top' : '4px'});
                break;
              case 2:
                $(this).css({'left' : '2px', 'top' : '5px'});
                break;
              case 3:
                $(this).css({'left' : '0px', 'top' : '4px'});
                break;
              case 4:
                $(this).css({'left' : '0px', 'top' : '6px'});
                break;
              case 5:
                $(this).css({'left' : '-1px', 'top' : '6px'});
                break;
            }
            i++;
          });
        }
        break;
      case 'rental_header1':
        if (browser == 'Explorer' && version == '7') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'color' : '#ffffff', 'top' : '5px'});
                break;
              case 2:
                $(this).css({'color' : '#ffffff', 'top' : '5px'});
                break;
              case 3:
                $(this).css({'color' : '#ffffff', 'top' : '5px'});
                break;
              case 4:
              default:
                $(this).css({'color' : '#656565', 'top' : '6px'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'color' : '#ffffff'});
                break;
              case 2:
                $(this).css({'color' : '#ffffff'});
                break;
              case 3:
                $(this).css({'color' : '#ffffff'});
                break;
              case 4:
                $(this).css({'color' : '#656565'});
            }
            i++;
          });
        }
        break;
      case 'rental_header':
        if (browser == 'Explorer' && version == '7') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '7px', 'left' : '0px'});
                break;
              case 2:
                $(this).css({'top' : '7px', 'left' : '1px'});
                break;
              case 3:
                $(this).css({'top' : '7px', 'left' : '2px'});
                break;
              case 4:
              default:
                $(this).css({'top' : '10px', 'left' : '0px'});
                break;
            }
            i++;
          });

          var i = 1;
          $(this).find('.a_shadow .bottom_header').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '-7px', 'left' : '2px'});
                break;
              case 2:
                $(this).css({'top' : '-7px', 'left' : '1px'});
                break;
              case 3:
                $(this).css({'top' : '-7px', 'left' : '0px'});
                break;
              case 4:
              default:
                $(this).css({'top' : '-7px', 'left' : '-1px'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '9px', 'left' : '0px'});
                break;
              case 2:
                $(this).css({'top' : '9px', 'left' : '1px'});
                break;
              case 3:
                $(this).css({'top' : '9px', 'left' : '-1px'});
                break;
              case 4:
              default:
                $(this).css({'top' : '11px', 'left' : '0px'});
                break;
            }
            i++;
          });

          var i = 1;
          $(this).find('.a_shadow .bottom_header').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '-7px', 'left' : '7px'});
                break;
              case 2:
                $(this).css({'top' : '-10px', 'left' : '7px'});
                break;
              case 3:
                $(this).css({'top' : '-7px', 'left' : '6px'});
                break;
              case 4:
              default:
                $(this).css({'top' : '-8px', 'left' : '7px'});
                break;
            }
            i++;
          });
        }
        break;
      case 'nav1':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'left' : '-21px', 'top' : '2px'});
              break;
            case 2:
              $(this).css({'left' : '-21px', 'top' : '3px'});
              break;
            case 3:
              $(this).css({'left' : '-22px', 'top' : '1px'});
              break;
            case 4:
              $(this).css({'left' : '-22px', 'top' : '4px'});
              break;
            case 5:
              $(this).css({'left' : '-23px', 'top' : '4px'});
              break;
          }
          i++;
        });
        break;
      case 'nav2_1':
        if (browser == 'Explorer' && version == '9') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'z-index' : '-1', 'left' : '-1px', 'top' : '0px'});
                break;
              case 2:
                $(this).css({'z-index' : '-1', 'left' : '2px', 'top' : '1px'});
                break;
              case 3:
                $(this).css({'z-index' : '-1', 'left' : '0px', 'top' : '-1px'});
                break;
              case 4:
                $(this).css({'z-index' : '-1', 'left' : '0px', 'top' : '2px'});
                break;
              case 5:
                $(this).css({'z-index' : '-1', 'left' : '-1px', 'top' : '2px'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'z-index': '-2', 'left' : '-1px', 'top' : '0px'});
                break;
              case 2:
                $(this).css({'z-index': '-2', 'left' : '2px', 'top' : '1px'});
                break;
              case 3:
                $(this).css({'z-index': '-2', 'left' : '0px', 'top' : '-1px'});
                break;
              case 4:
                $(this).css({'z-index': '-2', 'left' : '0px', 'top' : '2px'});
                break;
              case 5:
                $(this).css({'z-index': '-2', 'left' : '-1px', 'top' : '2px'});
                break;
            }
            i++;
          });
        }
        break;
      case 'nav2_2':
        if (browser == 'Explorer' && version == '7') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'left' : '-1px', 'top' : '4px'});
                break;
              case 2:
                $(this).css({'left' : '2px', 'top' : '5px'});
                break;
              case 3:
                $(this).css({'left' : '0px', 'top' : '4px'});
                break;
              case 4:
                $(this).css({'left' : '0px', 'top' : '6px'});
                break;
              case 5:
                $(this).css({'left' : '-1px', 'top' : '6px'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'z-index': '-1', 'left' : '-1px', 'top' : '-18px'});
                break;
              case 2:
                $(this).css({'z-index': '-1', 'left' : '1px', 'top' : '-18px'});
                break;
              case 3:
                $(this).css({'z-index': '-1', 'left' : '1px', 'top' : '-19px'});
                break;
              case 4:
                $(this).css({'z-index': '-1', 'left' : '-1px', 'top' : '-20px'});
                break;
              case 5:
                $(this).css({'z-index': '-1', 'left' : '-1px', 'top' : '-18px'});
                break;
            }
            i++;
          });
        }
        break;
      case 'nav3':
      case 'nav4':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '-1px', 'top' : '3px'});
              break;
            case 2:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '2px', 'top' : '4px'});
              break;
            case 3:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '0px', 'top' : '2px'});
              break;
            case 4:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '0px', 'top' : '5px'});
              break;
            case 5:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '-1px', 'top' : '5px'});
              break;
          }
          i++;
        });
        break;
      case 'slide_content':
        var i = 1;
        $(this).find('div').each(function() {
          if ($(this).css('width') == '389px') $(this).css('width', '390px');
          switch (i) {
            case 1:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '-1px', 'top' : '0px'});
              break;
            case 2:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '2px', 'top' : '1px'});
              break;
            case 3:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '0px', 'top' : '-1px'});
              break;
            case 4:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '0px', 'top' : '2px'});
              break;
            case 5:
              $(this).css({'color' : '#000000', 'border-color' : '#000000', 'left' : '-1px', 'top' : '2px'});
              break;
          }
          i++;
        });
        break;
      case 'our_clients':
      case 'what_we_do':
      case 'contact_us':
        if (browser == 'Explorer' && version == '7') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'left' : '0px', 'top' : '24px', 'color' : '#d7d7d7'});
                break;
              case 2:
                $(this).css({'left' : '0px', 'top' : '24px', 'color' : '#d7d7d7'});
                break;
              case 3:
                $(this).css({'left' : '0px', 'top' : '24px', 'color' : '#d7d7d7'});
                break;
              case 4:
                $(this).css({'left' : '0px', 'top' : '24px', 'color' : '#d7d7d7'});
                break;
              case 5:
                $(this).css({'left' : '0px', 'top' : '24px', 'color' : '#d7d7d7'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'left' : '1px', 'top' : '1px', 'color' : '#d7d7d7'});
                break;
              case 2:
                $(this).css({'left' : '1px', 'top' : '1px', 'color' : '#d7d7d7'});
                break;
              case 3:
                $(this).css({'left' : '1px', 'top' : '1px', 'color' : '#d7d7d7'});
                break;
              case 4:
                $(this).css({'left' : '1px', 'top' : '1px', 'color' : '#d7d7d7'});
                break;
              case 5:
                $(this).css({'left' : '1px', 'top' : '1px', 'color' : '#d7d7d7'});
                break;
            }
            i++;
          });
        }
        break;
      case 'rental_n1':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'left' : '-6px', 'top' : '0px'});
              break;
            case 2:
              $(this).css({'left' : '-3px', 'top' : '1px'});
              break;
            case 3:
              $(this).css({'left' : '-5px', 'top' : '-1px'});
              break;
            case 4:
              $(this).css({'left' : '-5px', 'top' : '2px'});
              break;
            case 5:
              $(this).css({'left' : '-6px', 'top' : '2px'});
              break;
          }
          i++;
        });
        break;
      case 'rental_n2':
      case 'rental_n3':
      case 'dehydrators':
      case 'vessels':
      case 'hf_vessels':
      case 'dr1':
      case 'dr2':
      case 'dr3':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'left' : '0px', 'top' : '-1px'});
              break;
            case 2:
              $(this).css({'left' : '-1px', 'top' : '0px'});
              break;
            case 3:
              $(this).css({'left' : '2px', 'top' : '1px'});
              break;
            case 4:
              $(this).css({'left' : '2px', 'top' : '2px'});
              break;
            case 5:
              $(this).css({'left' : '2px', 'top' : '2px'});
              break;
          }
          i++;
        });
        break;
      case 'rental_n4':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'left' : '-8px', 'top' : '0px'});
              break;
            case 2:
              $(this).css({'left' : '-6px', 'top' : '1px'});
              break;
            case 3:
              $(this).css({'left' : '-7px', 'top' : '-1px'});
              break;
            case 4:
              $(this).css({'left' : '-6px', 'top' : '2px'});
              break;
            case 5:
              $(this).css({'left' : '-6px', 'top' : '2px'});
              break;
          }
          i++;
        });
        break;
      case 'block_content':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'left' : '-1px', 'top' : '0px'});
              break;
            case 2:
              $(this).css({'left' : '1px', 'top' : '1px'});
              break;
            case 3:
              $(this).css({'left' : '-1px', 'top' : '-1px'});
              break;
            case 4:
              $(this).css({'left' : '1px', 'top' : '0px'});
              break;
            case 5:
              $(this).css({'left' : '2px', 'top' : '3px', 'color' : '#4E4740'});
              break;
          }
          i++;
        });
        break;
      case 'li1':
      case 'li2':
      case 'li3':
      case 'li4':
      case 'li5':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'left' : '1px', 'top' : '0px'});
              break;
            case 2:
              $(this).css({'left' : '-1px', 'top' : '0px'});
              break;
            case 3:
              $(this).css({'left' : '1px', 'top' : '-1px'});
              break;
            case 4:
              $(this).css({'left' : '0px', 'top' : '1px'});
              break;
            case 5:
              $(this).css({'left' : '2px', 'top' : '2px', 'color' : '#4E4740'});
              break;
          }
          i++;
        });
        break;
      case 'cont_page_header':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'top' : '-2px', 'left' : '0px', 'color' : '#4E4740'});
              break;
            case 2:
              $(this).css({'top' : '0px', 'left' : '2px', 'color' : '#4E4740'});
              break;
            case 3:
              $(this).css({'top' : '0px', 'left' : '-2px', 'color' : '#4E4740'});
              break;
            case 4:
              $(this).css({'top' : '2px', 'left' : '0px', 'color' : '#4E4740'});
              break;
            case 5:
              $(this).css({'top' : '-2px', 'left' : '-2px', 'color' : '#4E4740'});
              break;
            case 6:
              $(this).css({'top' : '3px', 'left' : '4px'});
              break;
          }
          i++;
        });
        break;
      case 'filter_h1':
      case 'filter_h2':
        if (browser == 'Explorer' && version == '7') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '-2px', 'left' : '0px'});
                break;
              case 2:
                $(this).css({'top' : '-2px', 'left' : '-1px'});
                break;
              case 3:
                $(this).css({'top' : '-2px', 'left' : '1px'});
                break;
              case 4:
                $(this).css({'top' : '2px', 'left' : '2px', 'color' : '#000000'});
                break;
              case 5:
                $(this).css({'top' : '3px', 'left' : '3px', 'color' : '#4E4740'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '-5px'});
                break;
              case 2:
                $(this).css({'top' : '-8px', 'left' : '-1px'});
                break;
              case 3:
                $(this).css({'top' : '-8px', 'left' : '1px'});
                break;
              case 4:
                $(this).css({'top' : '-4px', 'color' : '#4E4740'});
                break;
              case 5:
                $(this).css({'top' : '-4px', 'color' : '#4E4740'});
                break;
              case 6:
                $(this).css({'top' : '-1px', 'left' : '1px'});
                break;
            }
            i++;
          });
        }
        break
      case 'list_1':
      case 'list_2':
        if (browser == 'Explorer' && version == '9') {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '-1px', 'left' : '-2px'});
                break;
              case 2:
                $(this).css({'top' : '-1px', 'left' : '0px'});
                break;
              case 3:
                $(this).css({'top' : '3px', 'left' : '-1px', 'color' : '#4E4740'});
                break;
              case 4:
                $(this).css({'top' : '1px', 'left' : '-2px'});
                break;
              case 5:
                $(this).css({'top' : '1px', 'left' : '0px'});
                break;
            }
            i++;
          });
        }
        else {
          var i = 1;
          $(this).find('div').each(function() {
            switch (i) {
              case 1:
                $(this).css({'top' : '-1px', 'left' : '8px'});
                break;
              case 2:
                $(this).css({'top' : '-1px', 'left' : '10px'});
                break;
              case 3:
                $(this).css({'top' : '3px', 'left' : '11px', 'color' : '#4E4740'});
                break;
              case 4:
                $(this).css({'top' : '1px', 'left' : '8px'});
                break;
              case 5:
                $(this).css({'top' : '1px', 'left' : '10px'});
                break;
            }
            i++;
          });
        }
        break
      case 'filter_special_1':
      case 'filter_special_2':
        var i = 1;
        $(this).find('div').each(function() {
          switch (i) {
            case 1:
              $(this).css({'top' : '0px', 'left' : '-1px'});
              break;
            case 2:
              $(this).css({'top' : '-1px', 'left' : '-1px'});
              break;
            case 3:
              $(this).css({'top' : '-1px', 'left' : '1px'});
              break;
            case 4:
              $(this).css({'top' : '0px', 'left' : '1px'});
              break;
            case 5:
              $(this).css({'top' : '2px', 'left' : '1px'});
              break;
            case 6:
              $(this).css({'top' : '1px', 'left' : '0px'});
              break;
          }
          i++;
        });
        break;
    }
  });
}

function js_load() {
  $("body").css("visibility", "visible");
  if (browser == "Explorer") MakeDropShadow(); adjust_messed_up();
}

