/* create a timeOut function in jQuery */
jQuery.fn.idle = function(time){
    return this.each(function(){
        var i = $(this);
        i.queue(function(){
            setTimeout(function(){
            i.dequeue();
            }, time);
        });
    });
};
/**
 * jQuery Plugin Toggle Fade v1.0
 * Requires jQuery 1.2.3 (Not tested with earlier versions).
 * Copyright (c) 2008 Gregorio Magini [gmagini at gmail dot com] 
 * 
 *	@param: Object Array. Arguments need to be in object notation.
 *	Returns: jQuery.
 *	Options:	
 *		speedIn: Sets the speed of the fadeIn effect. Default: "normal".
 *    speedOut: Sets the speed of the fadeOut effect. Default: same as speedIn.
 *
 *	Examples: 
 *    
 *    speedIn and speedOut both "normal":
 *		$("#toggle-link").toggleFade();
 *
 *    speedIn and speedOut both "fast":
 *		$("#toggle-link").toggleFade({ speedIn : "fast");
 *
 *    different settings for speedIn and speedOut:
 *		$("#toggle-link").toggleFade({ speedIn : 800, speedOut : 150 });
 *
 */

(function($) {
  $.fn.toggleFade = function(settings)
  {
  	settings = jQuery.extend(
  		{
        speedIn: "normal",
        speedOut: settings.speedIn
  		}, settings
  	);
  	return this.each(function()
  	{
  	  var isHidden = jQuery(this).is(":hidden");
      jQuery(this)[ isHidden ? "fadeIn" : "fadeOut" ]( isHidden ? settings.speedIn : settings.speedOut);
    });
  };
})(jQuery);



// product menu accordian
/* 
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.menuProd ul').hide();
	$.each($('ul.menuProd'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.menuProd li a').click(
		
		function() {
			
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
		
			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;
			}
		}
	);
}


$(document).ready(function(){
	// initialize the produ menus
	initMenus();
	
	// show the "open" divs when page loaded
	if(document.getElementById("about")){
		$(".open").fadeIn('fast');
	}
	//top nav fade in/out
	if(document.getElementById("topMenu")){
		$('.top_linkWrapper').hover(
		function() { 
							$(this).find("a.top_link").addClass('top_linkOn');
							$('.sub', this).fadeIn('fast');},
		function() { $('.sub',this).fadeOut('slow'); 
							$(this).find("a.top_link").removeClass('top_linkOn');
		});
	}
	


	// reveal about divs

	$(".aboutNavItem").click(function(){
		var prodDiv = $(this).attr("id").replace("Link","");
		//alert(prodDiv);
		var openDiv = "#" + prodDiv;
		//$(".aboutDiv").fadeOut(2000);
		$(".aboutDiv").css("display","none");
		$(openDiv).fadeIn('fast');
		//$(".prodListing").fadeIn('fast');
	
	});
	
});


