$(function(){
		   
	$(".paging select").bind('change',function(){
		$(this).parents("form").submit();
	});
	
	//click on category on homepage
	$("div.category h2").click(function(){
		$(this).siblings("div.description").find("a").each(function(){
			if ( $(this).text() == 'Read More' ) {
				window.location.href = $(this).attr("href");
			}
		});
	});
	
	//iPhone Password
	

		//$("input:password").dPassword();

	
	//new windows links

		$("a[rel='external']").click(function(){
			this.target = "_blank";
		});

	//fieldset bg hover/focus
		$("#pageContent input, #pageContent textarea").focus(function(){
			$(this).parents("fieldset").addClass('fieldsetBg');
			
			$(this).parents("fieldset").hover(function(){
			$(this).addClass('fieldsetBg');
												  },
										 function(){
			$(this).addClass('fieldsetBg');
			});
	
		});
	
		$("#pageContent input").blur(function(){
			$(this).parents("fieldset").removeClass('fieldsetBg');
			
			$(this).parents("fieldset").hover(function(){
			$(this).addClass('fieldsetBg');
												  },
										 function(){
			$(this).removeClass('fieldsetBg');
			});
		});


		$("input.datepicker").datepicker();

	
	
	
	/*###########################################################################################################################
	##
	## clear form value, show again if nothing entered
	##
	*/
	/*$("form").find("input:text, input:password, textarea").focus(function() {
		var val = $(this).attr("value");
           
		$(this).attr("value","").blur(function(){
			if (!$(this).attr("value")){
				$(this).attr("value",val);
			}
		});
	});*/
	
	
	
	/*###########################################################################################################################
	##
	## ie6 fixes, conditional compilation just caused errors
	##
	*/
	
	///*@cc_on
	
		$("ul li:first-child, th:first-child, td:first-child").each(function(){
			$(this).addClass("first");
		});
		
		$("ul li:last-child, th:last-child, td:last-child").each(function(){
			$(this).addClass("last");
		});
		
		//hover class
		$('ul li, th, td').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	
	//	@end
	//@*/
	

	/*###########################################################################################################################
	##
	##  Main navigation accordion
	##
	*/
	//var cHeight = $("ul#categories > li.active").height();
	$("ul#categories > li").css({overflow: 'hidden'});
	$("ul#categories > li.active").css({overflow: 'visible'});
	
	var origHeight = 44;
	
	$("ul#categories li a").click(function(){
										   
		var currentHeight = $(this).parents("li").height();
		
		if (currentHeight == origHeight){
			$(this).parents("li").addClass("active").css({height:origHeight,overflow:'visible'});
			
			var expandTo = $(this).parents("li").find("ul").height();
			var expandTo = expandTo + origHeight
			
			$(this).parents("li").stop().animate({height:expandTo},600);
		}
		
		if (currentHeight > origHeight){
			$(this).parents("li").stop().css({overflow:'hidden'}).animate({height:origHeight},300).removeClass("active");
		}
		
		// checks to see if there are any children UL's, if so, cancels href click, but if the click lands on the subNav of the categories, it overrides and follows click.
		if ( $(this).parent("li").children("ul").length > 0  ){
				
				if ( $(this).parent("li").parent("ul").hasClass("list") ) {
					return true;
				}
				
			return false;
		} else {		
			return true;
		}
		
	});
	
	
	/*###########################################################################################################################
	##
	##  Vendors List
	##
	*/
	var expand = false;
	$("a#vendors").click(function(){
								  
		var countLi = $(this).next("ul").children("li").length;
		var divide = Math.ceil(countLi/5);
		var newHeight = divide * 37 + 60;
		
		if ( expand == false ){
			$(this).parents("form").animate({height: newHeight},
				function(){
					$("a#vendors").next("ul").css({display:'block',opacity:0});
					$("a#vendors").next("ul").animate({opacity:1},300);
					expand = true;
				});
		}
		if ( expand == true ){
			$(this).next("ul").animate({opacity:0},300,
				function(){
					$(this).css({display:'none'});
					$(this).parents("form").animate({height: 26})
					expand = false;
				});

		}
	
	return false;
	});
	
	
	
	
	
/* lightbox */
	
	
	$("#lightbox").css({display:'none'});
	$("a[rel='lightbox']").click(function(){
		$("#lightbox").fadeIn(100);
	});




	$("a.fancy").fancybox({
		imageScale:true,
		overlayOpacity: .7,
		zoomSpeedIn: 700,
		zoomSpeedOut: 500 
	});
	
	
	$("table tr:odd").addClass("even");
	$("table#noStyle tr").removeClass("even");
	


});//jquery

function closedAlertMessage()
{
	jQuery.ajax({type: "POST", url: "/alert-read" });
}

function ge(sId)
{
  return document.getElementById(sId);
}

function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}

function toggleDisplay(id)
{
  div = ge(id);
  if(div)
  {
    if(div.style.display == '')
    {
      div.style.display = 'none';
    }
    else
    {
      div.style.display = '';
    }
  }
}

function clearInputField(id, defaultText)
{
  element = ge(id);
  if(element.value == defaultText)
    element.value = '';
}