var $j = jQuery.noConflict();
$j(document).ready(function() {

    $jassigned_buttons = $j('#buttons').children();
    $jassigned_buttons.each(function(index) {
        var assigned_button = '#' + $j(this).attr('id');
        $j(assigned_button).click(function() {tabClick($j(this));});
    });



});

function opentab3() {
    $j('#button3').click()
}


function tabClick(pushed_button)  {

    $jrank = $j('#buttons').children();
    pushed_number = pushed_button.attr('id').substr(-1);

    $jrank.each(function(index) {
        var current_button = $j(this);
		      $j('#checkstockexpand').hide();

        if (pushed_button.attr('id') != current_button.attr('id'))    {
            hideGroup(current_button);
        } else {
            $j(idString(current_button.attr('id'))).addClass('selected');
            if ($j(returnTabId(current_button)).css('display') == 'block')   {
                if (current_button.attr('id') == 'button1') 
		  {
                    $j('#tab1').slideUp('slow');
                    $j('#button1').removeClass('selected');
                } else {
	             hideGroup(current_button);
                    $j('#tab1').slideDown('slow');
                    $j('#button1').addClass('selected');
		  }
            } else {$j(returnTabId(current_button)).slideDown('slow');}
        }

    });

}

function idString(name) {

    return '#' + name;
}


function hideGroup(current_button)    {
    $j(returnTabId(current_button)).hide();
    $j(idString(current_button.attr('id'))).removeClass('selected');
}


function returnTabId(current_button)  {
    
    return '#tab' + current_button.attr('id').substr(current_button.attr('id').length-1, 1);
    
}



$j(document).ready(function() {
  $j('#buttons .button').hover(function() {
    $j(this).addClass('hover');
  }, function() {
    $j(this).removeClass('hover');
  });


});



$j(document).ready(function() {

   $j('#gowarehouse').click(function() {    //check stock expansion triggered by button
    $j('#button3').addClass('selected');
    $j('#button2').removeClass('selected');
    $j('#button1').removeClass('selected');
   $j('#warehouselanding').slideDown('slow');

   });




    $j('.gofindfabrics').click(function() {    //check stock expansion triggered by button
      $j('#button3').addClass('selected');
      $j('#button2').removeClass('selected');
      $j('#button1').removeClass('selected');
      $j('#tab3').slideDown('slow');

   });



   $j('#go').click(function() {    //check stock expansion triggered by button
   $j('#tab2').hide();
   $j('#checkstockexpand').slideDown('slow');

   });


   $j('#checkstockform input').bind('keypress', function(e) {  //check stock expansion triggered by pressing enter key
        if(e.keyCode==13){
            
                  $j('#tab2').hide();
                  $j('#checkstockexpand').slideDown('slow');
                  return false;
        }
});





  $j('#close').click(function() {
    $j('#tab3').hide();
    $j('#tab1').show();
    $j('#button1').addClass('selected');
    $j('#button3').removeClass('selected');
  });

  $j('#close2').click(function() {
    $j('#checkstockexpand').hide();
    $j('#tab2').show();

  });

  $j('#close3').click(function() {
    $j('#warehouselanding').hide();
    $j('#button3').removeClass('selected');
    $j('#button1').addClass('selected');

  });
});





/*
$j(document).ready(function() {
  var toggleStyleSwitcher = function() {
    $j('#switcher .button').toggleClass('hidden');
  };

  $j('#switcher').click(toggleStyleSwitcher);

  $j('#switcher-normal').click(function() {
    $j('#switcher').click(toggleStyleSwitcher);
  });
  $j('#switcher-narrow, #switcher-large').click(function() {
    $j('#switcher').unbind('click', toggleStyleSwitcher);
  });
});
*/
/*
$j(document).ready(function() {
  $j('#switcher').click();
});
*/

