/* 
Simple JQuery menu.
HTML structure to use:

Notes: 

1: each menu MUST have an ID set. It doesn't matter what this ID is as long as it's there.
2: each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic

Optional extra classnames:

noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed
expandfirst : first menu item expanded at page load

<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</ul>

Copyright 2008 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
*/

function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.menu li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
if (parent.length != 0) {
			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
      }
		}
	);
  
  // Handle Product description visibility
  $('ul.menu li ul li').mouseenter(
		function() {
	    $("#imgTarget").attr('src', $(this).attr('name'));
      if($(this).attr('id') == "conc") {
        $('#concDescription').show();
        $('#chewDescription').hide();
        $('#powdDescription').hide();
        $('#cansDescription').hide();
        $('#concPrice').show();
        $('#chewPrice').hide();
        $('#powdPrice').hide();
        $('#cansPrice').hide();
      }
      if($(this).attr('id') == "chew") {
        $('#concDescription').hide();
        $('#chewDescription').show();
        $('#powdDescription').hide();
        $('#cansDescription').hide();
        $('#concPrice').hide();
        $('#chewPrice').show();
        $('#powdPrice').hide();
        $('#cansPrice').hide();
      }
      if($(this).attr('id') == "powd") {
        $('#concDescription').hide();
        $('#chewDescription').hide();
        $('#powdDescription').show();
        $('#cansDescription').hide();
        $('#concPrice').hide();
        $('#chewPrice').hide();
        $('#powdPrice').show();
        $('#cansPrice').hide();
      }
      if($(this).attr('id') == "cans") {
        $('#concDescription').hide();
        $('#chewDescription').hide();
        $('#powdDescription').hide();
        $('#cansDescription').show();
        $('#concPrice').hide();
        $('#chewPrice').hide();
        $('#powdPrice').hide();
        $('#cansPrice').show();
      }
		}
	);
  $('ul.menu li').mouseenter(
		function() {
	    $("#imgTarget").attr('src', $(this).attr('name'));
      if($(this).attr('id') == "conc") {
        $('#concDescription').show();
        $('#chewDescription').hide();
        $('#powdDescription').hide();
        $('#cansDescription').hide();
        $('#concPrice').show();
        $('#chewPrice').hide();
        $('#powdPrice').hide();
        $('#cansPrice').hide();
      }
      if($(this).attr('id') == "chew") {
        $('#concDescription').hide();
        $('#chewDescription').show();
        $('#powdDescription').hide();
        $('#cansDescription').hide();
        $('#concPrice').hide();
        $('#chewPrice').show();
        $('#powdPrice').hide();
        $('#cansPrice').hide();
      }
      if($(this).attr('id') == "powd") {
        $('#concDescription').hide();
        $('#chewDescription').hide();
        $('#powdDescription').show();
        $('#cansDescription').hide();
        $('#concPrice').hide();
        $('#chewPrice').hide();
        $('#powdPrice').show();
        $('#cansPrice').hide();
      }
      if($(this).attr('id') == "cans") {
        $('#concDescription').hide();
        $('#chewDescription').hide();
        $('#powdDescription').hide();
        $('#cansDescription').show();
        $('#concPrice').hide();
        $('#chewPrice').hide();
        $('#powdPrice').hide();
        $('#cansPrice').show();
      }
		}
	);
  
  $('#chewDescription').hide();
  $('#powdDescription').hide();
  $('#cansDescription').hide();

  $('#chewPrice').hide();
  $('#powdPrice').hide();
  $('#cansPrice').hide();


  // Handle Item selection
  $('ul.menu li ul li').click(
    function() {
        
        $('#itemSelected').html($(this).attr('desc'));
        //Hack due to being new to jQuery
        $('#ctl00_ctl00_ContentPlaceHolderOuter_ContentPlaceHolder1_hdnProductId').val($(this).attr('prodId'));
        return false;
    }
  );
  
  
  // Handle Edit sections visibility
  $('#address').hide();
  $('#btnAddress_open').hide();
  $('#btnAddress').click(
		function() {
      $('#btnAddress').hide();
      $('#btnAddress_open').show();
      $('#address').show();
      $('#btnCreditcard').show();
      $('#btnCreditcard_open').hide();
      $('#creditcard').hide();
      $('#btnNextshipment').show();
      $('#btnNextshipment_open').hide();
      $('#nextshipment').hide();
      $('#btnDeliverycycle').show();
      $('#btnDeliverycycle_open').hide();
      $('#deliverycycle').hide();
      $('#btnPassword').show();
      $('#btnPassword_open').hide();
      $('#password').hide();
			return false;
		}
	);
  $('#btnAddress_open').click(
		function() {
      $('#btnAddress').show();
      $('#btnAddress_open').hide();
      $('#address').hide();
			return false;
		}
	);
  
  $('#creditcard').hide();
  $('#btnCreditcard_open').hide();
  $('#btnCreditcard').click(
		function() {
      $('#btnAddress').show();
      $('#btnAddress_open').hide();
      $('#address').hide();
      $('#btnCreditcard').hide();
      $('#btnCreditcard_open').show();
      $('#creditcard').show();
      $('#btnNextshipment').show();
      $('#btnNextshipment_open').hide();
      $('#nextshipment').hide();
      $('#btnDeliverycycle').show();
      $('#btnDeliverycycle_open').hide();
      $('#deliverycycle').hide();
      $('#btnPassword').show();
      $('#btnPassword_open').hide();
      $('#password').hide();
			return false;
		}
	);
  $('#btnCreditcard_open').click(
		function() {
      $('#btnCreditcard').show();
      $('#btnCreditcard_open').hide();
      $('#creditcard').hide();
			return false;
		}
	);
  
  $('#nextshipment').hide();
  $('#btnNextshipment_open').hide();
  $('#btnNextshipment').click(
		function() {
      $('#btnAddress').show();
      $('#btnAddress_open').hide();
      $('#address').hide();
      $('#btnCreditcard').show();
      $('#btnCreditcard_open').hide();
      $('#creditcard').hide();
      $('#btnNextshipment').hide();
      $('#btnNextshipment_open').show();
      $('#nextshipment').show();
      $('#btnDeliverycycle').show();
      $('#btnDeliverycycle_open').hide();
      $('#deliverycycle').hide();
      $('#btnPassword').show();
      $('#btnPassword_open').hide();
      $('#password').hide();
			return false;
		}
	);
  $('#btnNextshipment_open').click(
		function() {
      $('#btnNextshipment').show();
      $('#btnNextshipment_open').hide();
      $('#nextshipment').hide();
			return false;
		}
	);
  
  $('#deliverycycle').hide();
  $('#btnDeliverycycle_open').hide();
  $('#btnDeliverycycle').click(
		function() {
      $('#btnAddress').show();
      $('#btnAddress_open').hide();
      $('#address').hide();
      $('#btnCreditcard').show();
      $('#btnCreditcard_open').hide();
      $('#creditcard').hide();
      $('#btnNextshipment').show();
      $('#btnNextshipment_open').hide();
      $('#nextshipment').hide();
      $('#btnDeliverycycle').hide();
      $('#btnDeliverycycle_open').show();
      $('#deliverycycle').show();
      $('#btnPassword').show();
      $('#btnPassword_open').hide();
      $('#password').hide();
			return false;
		}
	);
  $('#btnDeliverycycle_open').click(
		function() {
      $('#btnDeliverycycle').show();
      $('#btnDeliverycycle_open').hide();
      $('#deliverycycle').hide();
			return false;
		}
	);
  
  $('#password').hide();
  $('#btnPassword_open').hide();
  $('#btnPassword').click(
		function() {
      $('#btnAddress').show();
      $('#btnAddress_open').hide();
      $('#address').hide();
      $('#btnCreditcard').show();
      $('#btnCreditcard_open').hide();
      $('#creditcard').hide();
      $('#btnNextshipment').show();
      $('#btnNextshipment_open').hide();
      $('#nextshipment').hide();
      $('#btnDeliverycycle').show();
      $('#btnDeliverycycle_open').hide();
      $('#deliverycycle').hide();
      $('#btnPassword').hide();
      $('#btnPassword_open').show();
      $('#password').show();
			return false;
		}
	);
  $('#btnPassword_open').click(
		function() {
      $('#btnPassword').show();
      $('#btnPassword_open').hide();
      $('#password').hide();
			return false;
		}
	);
  
  
  $('#forgotPasswordForm').hide();
  $('#forgotPassword').click(
		function() {
      $('#forgotPasswordForm').show();
       $('#forgotPassword').hide();
			return false;
		}
	);
  
}
$(document).ready(function() {initMenus();});
