/* ========================================================================= */

function strstr (haystack, needle, bool) {
    // Finds first occurrence of a string within another  
    // 
    // version: 1103.1210
    // discuss at: http://phpjs.org/functions/strstr
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strstr('Kevin van Zonneveld', 'van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: strstr('Kevin van Zonneveld', 'van', true);
    // *     returns 2: 'Kevin '
    // *     example 3: strstr('name@example.com', '@');
    // *     returns 3: '@example.com'
    // *     example 4: strstr('name@example.com', '@', true);
    // *     returns 4: 'name'
    var pos = 0;
 
    haystack += '';
    pos = haystack.indexOf(needle);
    if (pos == -1) {
        return false;
    } else {
        if (bool) {
            return haystack.substr(0, pos);
        } else {
            return haystack.slice(pos);
        }
    }
}

/* ========================================================================= */

function change_style(current_url, org_url) {

  $('#print_header').hide();
  //$('#header-bg').show();
  $('#footer-bg').slideDown('fast');
    
  // jquery ui stuff
  $('.tabs').tabs();
  $(".accordionh5").accordion({ header: "h5", active: false, 
                                autoHeight: false,
                                collapsible: true });
  $(".dialog").dialog();

  // format buttons
  if (current_url == org_url +  "index.php") {
    $('#home_button').addClass("button_active");
  } else if (current_url == org_url + "members/index.php") {
    $('#members_button').addClass("button_active");
  } else if (current_url == org_url + "contact/index.php") {
    $('#contact_button').addClass("button_active");
  }

  // help stuff
  $("em").hide();
  $(".help a").hover(function() {
                       $(this).next("em").animate({opacity: "show", 
                                                   top: "-75"}, 
                                                  "slow"); 
                     }, 
                     function() {
                       $(this).next("em").animate({opacity: "hide", 
                                                   top: "-85"}, 
                                                  "fast");
                     });

  // format form stuff
  $("input").addClass("text");
  $("select").addClass("select");
  $("input, select").addClass("ui-widget-content");
  $("input, select").addClass("ui-corner-all");
  $("button, input:submit").button();  
  $(".buttonset").buttonset();
    
  // handle quick_lookup stuff
  $('.accordionh5 h5').click(function() {
      var id = $(this).attr("id");
      $('#' + id + "-div").addClass("height200");
      $('#' + id + "-div").append("<div class=\"center icon-loading icon-loading-black\"></div>");
      $.ajax({ url: org_url + "html/quick_lookup/" + id + ".html",
               cache: false,
               success: function(data) {
                   $('#' + id + "-div").html(data);
               }
             });
  });

  // xhtml 1.0 strict method for target=_blank replacement
  $('a[rel="external"]').click(function() {
                                 window.open( $(this).attr('href'));
                                 return false;
                               });
  
  // format slider
  $( "#slider-price" ).slider(
  {
    range: true,
    min: 0,
    max: 100000,
    step: 500,
    values: [ 5000, 45000 ],
    slide: function( event, ui ) {
      $("#price").val("$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ]);
    }
  });


  // format price
  $("#price").val("$" + $("#slider-price").slider("values", 0) +
                  " - $" + $( "#slider-price").slider("values", 1));

  handle_help_icons();

}

/* ========================================================================= */

function handle_help_icons() {

  $(".tooltip_input").tooltip(
    {
      position: "center right", // place tooltip on the right edge
      offset: [-2, 10], // a little tweaking of the position
      effect: "fade",
      opacity: 0.7 // custom opacity setting
    });

  $(".tooltip_item").tooltip({ position: "top left", offset: [30, 345], effect: 'slide' }); 
    //.dynamic({ bottom: { direction: 'down', bounce: true } });

  // hack for tooltips in jquery ui tabs
  $(".tooltip_item_tab").tooltip({ position: "top left", offset: [-255, 140], effect: 'slide' }); 
    //.dynamic({ bottom: { direction: 'down', bounce: true } });

  // hack for tooltips in query ui tabs for upload button
  $(".tooltip_item_tab_upload").tooltip({ position: "top left", offset: [-270, 30], effect: 'slide' }); 
    //.dynamic({ bottom: { direction: 'down', bounce: true } });

}

/* ========================================================================= */

