jQuery(function(){
	jQuery('#siteSearchOptions').click(function(e){
		if (jQuery("#siteSearchOptionsList").is(":hidden")) {
			jQuery("#siteSearchOptions span").addClass('hover');
			jQuery("#siteSearchOptionsList").fadeIn();
		} else {
			jQuery("#siteSearchOptions span").removeClass();
			jQuery("#siteSearchOptionsList").slideUp("fast");
		}
		jQuery(document).mouseup(function(e) {
            if(jQuery(e.target).parent("#siteSearchOptionsList").length==0) {
				jQuery("#siteSearchOptions span").removeClass();
                jQuery("#siteSearchOptionsList").slideUp("fast");
            }
        }); 
	});
	
	jQuery('ul#productslist li').first().css('border-top','none');
	
	// Add pdf icons to pdf links
	jQuery("a[href$='.pdf']").addClass("pdf");
		
	if (!$.browser.webkit) {
		$('input').placeholder();
	}

	jQuery("#productslist").hide();
	
	jQuery('#products-jump').click(function(){
		if (jQuery("#productslist").is(":hidden")) {
			jQuery("#products-jump span").addClass('hover');
			jQuery("#productslist").fadeIn(300);		
		} else {
			jQuery("#products-jump span").removeClass();
			jQuery("#productslist").hide();
		}
		jQuery(document).mouseup(function(e) {
            if(jQuery(e.target).parent("#productslist").length==0) {
				jQuery("#products-jump span").removeClass();
                jQuery("#productslist").slideUp("fast");
            }
        }); 
	});
});

function initDrop()
{
	$('div.drop-content').hide();

	$('div.drop-header').click(
		function()
		{
			var headerElement = $(this);
			var contentElement = headerElement.parent().find('div.drop-content');

			$('div.drop-header').each(
				function()
				{
					if(headerElement != $(this))
					{
						$(this).find('div.drop-arrow span').removeClass('close');
						$(this).parent().find('div.drop-content').slideUp('normal');
					}
				}
				);
						

			if(contentElement.is(':visible'))
			{
				headerElement.find('div.drop-arrow span').removeClass('close');
				contentElement.slideUp('normal');
			}
			else
			{
				headerElement.find('div.drop-arrow span').addClass('close');
				contentElement.slideDown('normal');
			}

			return false;
		}
		);
};

$(document).ready(function() {
	initDrop(); 
	
	// call the cookie class and set a cookie called viewState
	$.cookie("viewState");
	
	// create a variable and set it to the value of the cookie
	var theState = $.cookie("viewState");
	if($(theState).length >0) {
		$("#inner_bb_container").toggleClass(theState);
	}else {
		$("#inner_bb_container").addClass(theState);
	}
	
	$("#styleswitch").toggle(
		function (event) {
			event.preventDefault();
			// when clicked, set the cookie and variable to block
			$.cookie("viewState", "berry");
			theState = "berry";
			$("#inner_bb_container").removeClass('citrus');
			$("#inner_bb_container").addClass(theState);
			$("#clicknsniff").css('background-position','0 0');
		},
		function (event) {
			event.preventDefault();
			// set the cookie and variable to none when clicked again
			$.cookie("viewState", "citrus");
			theState = "citrus";
			$("#inner_bb_container").removeClass('berry');
			$("#inner_bb_container").addClass(theState);
			$("#clicknsniff").css('background-position','0 0');
	});
	
	$("#clicknsniff").click(
		function () {
			// when clicked, set the cookie and variable to block
			$(this).css('background-position','0 -171px');
		});	
});
this.randomq = function(){
	var length = $("#questions li").length;
	var ran = Math.floor(Math.random()*length) + 1;
	$("#questions li:nth-child(" + ran + ")").show();
};
 
$(document).ready(function(){	
	randomq();
});
function initFaq() {
	$('.faq-answer').hide();
	$('.faq-answer').first().show();
	$('.faq-question').click(
	function() {
	  var checkElement = $(this).next();
	  if((checkElement.is('div')) && (checkElement.is(':visible'))) {
	    $('.faq-answer:visible').slideUp('normal');
	    return false;
	    }
	  if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
	    $('.faq-answer:visible').slideUp('normal');
	    checkElement.slideDown('normal');
	    return false;
	    }
	  }
	);
}
$(document).ready(function() {initFaq(); });new function($) {
    $.fn.placeholder = function(settings) {
        settings = settings || {};
        var key = settings.dataKey || "placeholderValue";
        var attr = settings.attr || "placeholder";
        var className = settings.className || "placeholder";
        var values = settings.values || [];
        var block = settings.blockSubmit || false;
        var blank = settings.blankSubmit || false;
        var submit = settings.onSubmit || false;
        var value = settings.value || "";
        var position = settings.cursor_position || 0;

        
        return this.filter(":input").each(function(index) { 
            $.data(this, key, values[index] || $(this).attr(attr)); 
        }).each(function() {
            if ($.trim($(this).val()) === "")
                $(this).addClass(className).val($.data(this, key));
        }).focus(function() {
            if ($.trim($(this).val()) === $.data(this, key)) 
                $(this).removeClass(className).val(value)
                if ($.fn.setCursorPosition) {
                  $(this).setCursorPosition(position);
                }
        }).blur(function() {
            if ($.trim($(this).val()) === value)
                $(this).addClass(className).val($.data(this, key));
        }).each(function(index, elem) {
            if (block)
                new function(e) {
                    $(e.form).submit(function() {
                        return $.trim($(e).val()) != $.data(e, key)
                    });
                }(elem);
            else if (blank)
                new function(e) {
                    $(e.form).submit(function() {
                        if ($.trim($(e).val()) == $.data(e, key)) 
                            $(e).removeClass(className).val("");
                        return true;
                    });
                }(elem);
            else if (submit)
                new function(e) { $(e.form).submit(submit); }(elem);
        });
    };
}(jQuery);
