/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 *
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com)
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 *
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 *
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","visible");
		});
	}
})(jQuery);

function getActive(){
  var path = location.pathname.substring(1);
  $('#Menu a[href="/' + path + '"]').addClass('active');
  
  $('ul.slideMenu li a[href="/' + path + '"]').parent().addClass('active');
  $('ul.slideMenu li ul li a[href="/' + path + '"]').parent().addClass('active');
  
}

function slideMenu() {
	$('ul.slideMenu ul').hide();
	$.each($('ul.slideMenu li'), function(){
        if ($(this).hasClass('active')){
          $(this).children('ul').show();
        }
	});
	$.each($('ul.slideMenu li ul li'), function(){
        if ($(this).hasClass('active')){
          $(this).parents('ul').show();
        }
	});
	$('ul.slideMenu li a, ul.slideMenu li ul.subMenu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
      			$('#' + parent + ' ul:visible').slideUp('normal');
                return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
       			$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
                return false;
			}
		}
	);
}

// Slide Show
function ssSlide() {
    var $active = $('#ssSlide img.active');

    if ( $active.length == 0 ) $active = $('#ssSlide img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#ssSlide img:first');


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
//            if ($('#ssSlide img.active').attr("alt") == "") {$("#ssCaption").html("&nbsp;");$("#ssCaption").slideUp("slow")}
//            else {$("#ssCaption").text($('#ssSlide img.active').attr("alt"));$("#ssCaption").slideDown("slow")}
        });
}

// Start Slide Show
$(function() {
//  if ($("#ssCaption").is(":hidden")) {
//    $("#ssCaption").text($('#ssSlide img.active').attr("alt"))
//    if ($('#ssSlide img.active').attr("alt") != "") {$("#ssCaption").slideDown("slow");}
//  }
    setInterval( "ssSlide()", 7000 );
});

//http://swip.codylindley.com/jquery.popupWindow.js
(function($){
	$.fn.popupWindow = function(instanceSettings){

		return this.each(function(){

		$(this).click(function(){

		$.fn.popupWindow.defaultSettings = {
			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
			height:500, // sets the height in pixels of the window.
			left:0, // left position when the window appears.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			width:500, // sets the width in pixels of the window.
			windowName:null, // name of window set from the name attribute of the element that invokes the click
			windowURL:null, // url used for the popup
			top:0, // top position when the window appears.
			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
		};

		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});

		var windowFeatures =    'height=' + settings.height +
								',width=' + settings.width +
								',toolbar=' + settings.toolbar +
								',scrollbars=' + settings.scrollbars +
								',status=' + settings.status +
								',resizable=' + settings.resizable +
								',location=' + settings.location +
								',menuBar=' + settings.menubar;

				settings.windowName = this.name || settings.windowName;
				settings.windowURL = this.href || settings.windowURL;
				var centeredY,centeredX;

				if(settings.centerBrowser){

					if ($.browser.msie) {//hacked together for IE browsers
						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
					}else{
						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
					}
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else if(settings.centerScreen){
					centeredY = (screen.height - settings.height)/2;
					centeredX = (screen.width - settings.width)/2;
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else{
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();
				}
				return false;
			});

		});
	};
})(jQuery);

// Alternate background colors // set equal coumn heights // hide / reveal items.
$(document).ready(function(){
  getActive();
  slideMenu();
  $(".alternate:odd").addClass("alternate-odd");
  $(".alternate:even").addClass("alternate-even");
  $(".revealTarget").addClass("hide");
//########### REMOVE IF USING RESIZING COLUMNS ##########
//  $(".column").equalHeights();
//########### REMOVE IF USING RESIZING COLUMNS ##########
  $('#PricingPop').hover(function(){
        $(this).addClass('pPopOver');
  },function(){
        $(this).removeClass('pPopOver');
  });
  $('#PricingPop').popupWindow({
      height:800,
      width:500,
      centerScreen:1,
      scrollbars:1
  });
    $('ul.slideMenu li.helpBubble').hover(
        function () {
            $(this).css("overflow","visible");
            $(this).find("div.popup").stop()
	    	.css("display","block")
            .css("z-index","2147483647")
    		.animate({left: "140", opacity:1}, "fast")
	    }, function() {
		    $(this).find("div.popup").stop()
            .css("z-index","0")
    		.animate({left: "110", opacity: 0}, "fast");
            $(this).css("overflow","hidden");
	    }
    );

  // Show / Hide gallery items.
  $("a.revealLink").click(function(){
    var $myTarget = $(this).attr("href");

    $($myTarget).children(".galleryBox").children("a").children(".replaceThumb").each(function(){
      $(this).attr("src",$(this).attr("title"));
    });

    if ($($myTarget).hasClass("hide")){$($myTarget).removeClass("hide");}
    else {$($myTarget).addClass("hide");}
//########### REMOVE IF USING RESIZING COLUMNS ##########
//    $(".column").equalHeights();
//########### REMOVE IF USING RESIZING COLUMNS ##########
  });

  // Show all / Used in the FAQ page.
  $("a.revealer").click(function(){
    var $count = 0;
    $(".hide").each(function(){
      $count = ($count + 1);
    });
    if ($count > 0){
      $("a.revealer").text("Colapse All");
      $(".hide").removeClass("hide");
    }
    else {
      $("a.revealer").text("Expand All");
      $(".revealTarget").addClass("hide");
    }
//########### REMOVE IF USING RESIZING COLUMNS ##########
//    $(".column").equalHeights();
//########### REMOVE IF USING RESIZING COLUMNS ##########
  });
// Display fake password box so that the "Password" title text shows up
$('#password').show();
if($('#password').attr('name') == 'password'){ // Don't hide the "real" password box if the other doesn't exist (login page)
        $('#member_password').hide();
}
$('#password').focus(function() {
    $('#password').hide();
    $('#member_password').show();
    $('#member_password').focus();
});
$('#member_password').blur(function() {
    if($('#member_password').val() == '' && $('#password').attr('name') == 'password') {
        $('#password').show();
        $('#member_password').hide();
    }
});
// Display item "title" inside of an input.
$('input[title]').each(function() {
    if($(this).val() === '') {
	    $(this).val($(this).attr('title'));
    	    $(this).addClass('auto_title_empty');
	}

	$(this).focus(function() {
		if($(this).val() === $(this).attr('title')) {
			$(this).val('').removeClass('auto_title_empty');
		        if($(this).attr('id') == 'member_password'){
                                $(this).attr('type','password')
		        }
		}
	});

	$(this).blur(function() {
		if($(this).val() === '') {
		        if($(this).attr('id') == 'member_password'){
                                $(this).attr('type','text')
		        }
			$(this).val($(this).attr('title')).addClass('auto_title_empty');
		}
	});
});

// Memeber Login
		$('#member_form').submit(function() {
			$.ajax({
				url: '/site/?command=memberLogin&ajax=1',
				type: 'POST',
				data: $('#member_form').serialize(),
				dataType: 'json',
				success: function(msg) {
					if (msg != false) {
						location.reload(true);
					} else {
						$('#member_login_status').text("Incorrect username and password.");
						$('#member_login_status').show();
					}
				}
			});
			return false;
		});



//### Search By Manuf. ###
    $('#SideSearchBox').mouseover(function(){
        if($('#manufactureSelect').attr('rel') == ''){
            $('#manufactureSelect').attr('rel','ajax');
            $.ajax({
                url: '/site/?command=mod_getManus&ajax=1&ajdt=1',
                dataType: 'json',
                async: false,
                success: function(data){
                    $.each(data, function(i,item) {
                        $('#manufactureSelect').append('<option value="'+item.vendor_code+'">'+item.vendor_name+'</option>');
                    });
                }
            });
        }
    });
    $('#manufactureSelect').change(function(){
        var partNumberValue = $('#partnumberSideSearch').val();
        if (partNumberValue == 'Part Number Search'){partNumberValue = ''}
        var keyWordValue = $('#keywordSideSearch').val();
        if (keyWordValue == 'Keyword Search'){keyWordValue = ''}
        var manufactValue = $('#manufactureSelect').val();
        if(partNumberValue == '' && keyWordValue == ''){
        	$('#manufactureListForm').append('<input type="hidden" name="partnumber" value="'+manufactValue+'"/><input type="hidden" name="manuOnly" value="1"/>');
        	$('#manufactureListForm').submit();
        }
        if(partNumberValue != ''){
        	$('#manufactureListForm').append('<input type="hidden" name="partnumber" value="'+partNumberValue+'"/><input type="hidden" name="manuABBR" value="'+manufactValue+'"/>');
        	$('#manufactureListForm').submit();
        }
        if(keyWordValue != ''){
        	$('#manufactureListForm').append('<input type="hidden" name="keyword" value="'+keyWordValue+'"/><input type="hidden" name="keywordManu" value="'+manufactValue+'"/>');
        	$('#manufactureListForm').submit();
        }
    });
//### End Search By Manuf. ###

});
/*
 * jQuery Tools 1.2.5 - The missing UI library for the Web
 *
 * [scrollable]
 *
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 *
 * http://flowplayer.org/tools/
 *
 * File generated: Wed Sep 22 08:56:49 GMT 2010
 */
(function(e){function p(f,c){var b=e(c);return b.length<2?b:f.parent().find(c)}function u(f,c){var b=this,n=f.add(b),g=f.children(),l=0,j=c.vertical;k||(k=b);if(g.length>1)g=e(c.items,f);e.extend(b,{getConf:function(){return c},getIndex:function(){return l},getSize:function(){return b.getItems().size()},getNaviButtons:function(){return o.add(q)},getRoot:function(){return f},getItemWrap:function(){return g},getItems:function(){return g.children(c.item).not("."+c.clonedClass)},move:function(a,d){return b.seekTo(l+
a,d)},next:function(a){return b.move(1,a)},prev:function(a){return b.move(-1,a)},begin:function(a){return b.seekTo(0,a)},end:function(a){return b.seekTo(b.getSize()-1,a)},focus:function(){return k=b},addItem:function(a){a=e(a);if(c.circular){g.children("."+c.clonedClass+":last").before(a);g.children("."+c.clonedClass+":first").replaceWith(a.clone().addClass(c.clonedClass))}else g.append(a);n.trigger("onAddItem",[a]);return b},seekTo:function(a,d,h){a.jquery||(a*=1);if(c.circular&&a===0&&l==-1&&d!==
0)return b;if(!c.circular&&a<0||a>b.getSize()||a<-1)return b;var i=a;if(a.jquery)a=b.getItems().index(a);else i=b.getItems().eq(a);var r=e.Event("onBeforeSeek");if(!h){n.trigger(r,[a,d]);if(r.isDefaultPrevented()||!i.length)return b}i=j?{top:-i.position().top}:{left:-i.position().left};l=a;k=b;if(d===undefined)d=c.speed;g.animate(i,d,c.easing,h||function(){n.trigger("onSeek",[a])});return b}});e.each(["onBeforeSeek","onSeek","onAddItem"],function(a,d){e.isFunction(c[d])&&e(b).bind(d,c[d]);b[d]=function(h){h&&
e(b).bind(d,h);return b}});if(c.circular){var s=b.getItems().slice(-1).clone().prependTo(g),t=b.getItems().eq(1).clone().appendTo(g);s.add(t).addClass(c.clonedClass);b.onBeforeSeek(function(a,d,h){if(!a.isDefaultPrevented())if(d==-1){b.seekTo(s,h,function(){b.end(0)});return a.preventDefault()}else d==b.getSize()&&b.seekTo(t,h,function(){b.begin(0)})});b.seekTo(0,0,function(){})}var o=p(f,c.prev).click(function(){b.prev()}),q=p(f,c.next).click(function(){b.next()});if(!c.circular&&b.getSize()>1){b.onBeforeSeek(function(a,
d){setTimeout(function(){if(!a.isDefaultPrevented()){o.toggleClass(c.disabledClass,d<=0);q.toggleClass(c.disabledClass,d>=b.getSize()-1)}},1)});c.initialIndex||o.addClass(c.disabledClass)}c.mousewheel&&e.fn.mousewheel&&f.mousewheel(function(a,d){if(c.mousewheel){b.move(d<0?1:-1,c.wheelSpeed||50);return false}});if(c.touch){var m={};g[0].ontouchstart=function(a){a=a.touches[0];m.x=a.clientX;m.y=a.clientY};g[0].ontouchmove=function(a){if(a.touches.length==1&&!g.is(":animated")){var d=a.touches[0],h=
m.x-d.clientX;d=m.y-d.clientY;b[j&&d>0||!j&&h>0?"next":"prev"]();a.preventDefault()}}}c.keyboard&&e(document).bind("keydown.scrollable",function(a){if(!(!c.keyboard||a.altKey||a.ctrlKey||e(a.target).is(":input")))if(!(c.keyboard!="static"&&k!=b)){var d=a.keyCode;if(j&&(d==38||d==40)){b.move(d==38?-1:1);return a.preventDefault()}if(!j&&(d==37||d==39)){b.move(d==37?-1:1);return a.preventDefault()}}});c.initialIndex&&b.seekTo(c.initialIndex,0,function(){})}e.tools=e.tools||{version:"1.2.5"};e.tools.scrollable=
{conf:{activeClass:"active",circular:false,clonedClass:"cloned",disabledClass:"disabled",easing:"swing",initialIndex:0,item:null,items:".items",keyboard:true,mousewheel:false,next:".next",prev:".prev",speed:400,vertical:false,touch:true,wheelSpeed:0}};var k;e.fn.scrollable=function(f){var c=this.data("scrollable");if(c)return c;f=e.extend({},e.tools.scrollable.conf,f);this.each(function(){c=new u(e(this),f);e(this).data("scrollable",c)});return f.api?c:this}})(jQuery);

