//****Nav State holder********************************//
function navRollState(){
	$temp = false;
	$('ul#headerNav li ul').mouseover(function() {
		if($(this).siblings('a').hasClass('active')){
			$(this).siblings('a').removeClass('active');
			$temp = true;
		}
		$(this).siblings('a').addClass('hover');
	});	
	$('ul#headerNav li ul').mouseleave(function() {
		if($temp == true){
			$(this).siblings('a').addClass('active');
			$temp = false;
		}
		$('a.hover').removeClass('hover');
	});
	
	$('ul#headerNav li').mouseover(function() {
		$(this).children('ul').css('left','0px');
		$(this).mouseleave(function() {
			$(this).children('ul').css('left','-9999px');
		});
	});
	
	$('#content').mouseover(function() {
		$('ul#headerNav li ul').css('left','-9999px');
		$('a.hover').removeClass('hover');
	});	
	
	$('ul.subnav li:first-child').addClass('top');
	$('ul.subnav li:last-child').addClass('bottom');
}
//****Product Detail Page, Quote Form Show and Hide****************************************//
function quoteForm(){
	$('.product-detail .info a.quote').click(function() {
		if($('.product-detail form').is(':hidden')){
			$('.product-detail form').toggle('slow');
		}else{
			$('.product-detail form').fadeOut('slow');
		}
		return false;
	});
	$('.products a.quote').click(function() {
		if($('.products form').is(':hidden')){
			$('.products form').toggle('slow');
		}else{
			$('.products form').fadeOut('slow');
		}
		return false;
	});
}
//*****Slider image switcher, uses CSS classes*********************************************//
function slider() {
	$("#slider .carousel").jCarouselLite({
			btnNext: "#prev",
			btnPrev: "#next",
			scroll: 4,
			speed: 800
	});
	
	$("#slider .carousel ul li:eq(3) a").addClass("active");
	$("#slider ul li a").click(function() {
		$("#slider img.large").hide();
		$("#slider img.large").attr("src", $(this).children('img').attr("src"));
		$("#slider img.large").fadeIn('slow');
		$('#slider ul li a').removeClass('active');
		$(this).addClass('active');
		return false;
	})
}
//*****Replace align attribute with class**************************************************//
function replaceAlign() {
  if (!document.getElementsByTagName('img')) return false;
  $('img[align="left"]').addClass('left').removeAttr('align');
  $('img[align="right"]').addClass('right').removeAttr('align');
  $('img[align="middle"]').addClass('middle').removeAttr('align');
}
//*****Replace target attribute with class**************************************************//
function replaceTarget() {
  if (!document.getElementsByTagName('a')) return false;
  $('a[target]').addClass('newwindow').removeAttr('target');
}
//*****The following function make it possible to have web standard popups**************************************************//
function strictNewWindow() {
  if (!document.getElementsByTagName('a')) return false;
  $('a.newwindow').click(function() {
    window.open($(this).attr('href'));
    return false;
  });
}
//*****jQuery clear value from july 21st 2009 comment on http://www.joesak.com/2008/11/19/a-jquery-function-to-auto-fill-input-fields-and-clear-them-on-click*****//
function clearDefaultValue() {
  $(':input').focus(function() {
    if($(this).val() == $(this).attr('title')) {
      $(this).val('');
    }
  }).blur(function() {
    if($(this).val() == '') {
      $(this).val($(this).attr('title'));
    }
  });
  $('.sendbutton').mouseup(function() {
	  $(':input').each(function (i) {
      if($(this).val() == $(this).attr('title')) {
        $(this).val('');
      }
    });
		setTimeout("validationStates()", 50);
  });
}
function validationStates(){
	$("label.cf_li_err").siblings("label").css({'color': '#EE7733', 'font-weight': 'bold'});
}
//*****Load all functions**************************************************//
$(document).ready(function(){
  replaceAlign();
  replaceTarget();
  strictNewWindow();
  clearDefaultValue();
	slider();
	quoteForm();
	navRollState();
});