// called when the document is fully loaded
var js_prodarray;


function pop_common(url) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=580,height=300,left = 10,top = 10');");
}


// on ready handler
$(function() {

	// Top 15 categories - show all cat. or limit to top 15
	$('#view_all_categories').toggle(
    			function(event) {
    				$('div.t2').css('display', 'none');
    				$('#view_all_categories').html('View All');
    			},
    			function(event) {
    				$('div.t2').css('display', 'block');
    				$('#view_all_categories').html('View Top Categories');
    			}
    			);


	// function to show and hide the community discussion blog
	$("#read_more").click(function() {
		$("#discussion").slideToggle("slow");
	});

	$('.moredescription').click(function(event) {
		window.location = "product.php?prod=" + event.target.id;
	}).css('cursor', 'pointer'); ;


	// don't show the discussion blog when loading the page
	$("#discussion").css('display', 'none');

	// This will initialize the categories display 
	$('#view_all_categories').trigger('click');

	// Set the autocomplete for both search boxes
	if ($('#startsearchinginput'))
		$('#startsearchinginput').autocomplete(js_prodarray);
	if ($('#getstartedinput'))
		$('#getstartedinput').autocomplete(js_prodarray);
	if ($('#alltextsearch'))
		$('#alltextsearch').autocomplete(js_prodarray);

	// Chat click event
	$('#chatsupport, #chatsupport_right').bind('click',
        function(event) {
        	pop_common('https://messenger.providesupport.com/messenger/healthsol.html');
        });

	// GetStarted
	$('#getstarted_guide h2').click(
			function(event) {
				// hide all
				$('#getstarted_guide h2').next('div').hide();
				// show current
				$(this).next('div').show('normal');
			});

	// hide content of all h2 divs
	$('#getstarted_guide h2').next('div').hide();

	$("p.hda").click(function() {
		$(this).next('div.answer').slideToggle('normal');
	});
	// hide content of all h2 divs
	$('div.answer').hide();

	// FAQ
	$('#faq_physicians, #faq_physicians+p, #faq_medications, #faq_medications+p, #faq_shipping, #faq_shipping+p, #nextdaydelivery, #nodoctor, #freesupport, #welcome_to_content_more, #painmanagement, #nextdaydeliveryOnleft, #prescriptionmedications ').click(function(event) {
		window.location = "faq.php";
	}).css('cursor', 'pointer');

	// Special Offer
	$('#specialoffer').click(function(event) {
		window.location = "freereports.php";
	});


	// Categories Menu that acts like an accordian
	$('ul.categoryitems').hide();
	$('h3.expandable').click(function() {
		$(this).next('ul.categoryitems').slideToggle('normal');
	});

	// Keep "Search Medications" as the text if empty
	$("#startsearchinginput, #getstartedinput").bind("blur focus", function(event) {
		if (this.value == '') {
			this.value = 'Search Medications';
		} else if (this.value.indexOf("Search Medications") >= 0) {
			this.value = '';
		}
	});

	$('#getstartedinput').attr({ size: "25", maxlength: "60" }); 


});
