$().ready(function(){

/*
 *		Project:	Is It Free Now
 *		Componant:	General Functionality
 *		Purpose:	Generic functionality to be used throughout the website
 *		
 *		Created:	16/10/2009
 *		Author(s):	Ricky Stevens
 *
 *		Modified:	16/07/2009
*/

	$('#searchService').each(function() {
		if($(this).val() == '' || $(this).val() == 'e.g. Plumber') $(this).css('color', '#ccc').val('e.g. Plumber');
	});

	$('#searchService').click(function() {
		if($(this).val() == 'e.g. Plumber') $(this).css('color', '#000').val('');
	});

	$('#searchService').blur(function() {
		if($(this).val() == '') $(this).css('color', '#ccc').val('e.g. Plumber');
	});

	$('#searchLocation').each(function() {
		if($(this).val() == '' || $(this).val() == 'e.g. Hertford or SG13') $(this).css('color', '#ccc').val('e.g. Hertford or SG13');
	});

	$('#searchLocation').click(function() {
		if($(this).val() == 'e.g. Hertford or SG13') $(this).css('color', '#000').val('');
	});

	$('#searchLocation').blur(function() {
		if($(this).val() == '') $(this).css('color', '#ccc').val('e.g. Hertford or SG13');
	});

	$('#siteSearch').click(function() {
		if(($('#searchLocation').val() == 'e.g. Hertford or SG13') || ($('#searchService').val() == 'e.g. Plumber')) {
                    alert('Please fill in both text boxes to search IsItFreeNow');
                    return false;
                }
                return true;
	});

	$('#searchService').autocomplete('/ajax/search.php?id=services');

	$('#searchLocation').autocomplete('/ajax/search.php?id=location');

	$('#strInputTown').autocomplete('/ajax/search.php?id=city');

	$('#strInputPostcode').autocomplete('/ajax/search.php?id=postcode');

	$('#strTown').autocomplete('/ajax/search.php?id=city');

	$('#strPostcode').autocomplete('/ajax/search.php?id=postcode');

        $('.categoryDrop').click(function() {
            
            var thisInstance = $(this);

            $('.categoryDrop').each(function() {
                if($(this).parent().hasClass('on') && thisInstance.attr('href') != $(this).attr('href'))
                    $(this).parent().removeClass('on').children('ul').slideUp(200);
            });

            (thisInstance.parent().hasClass('on'))
                ? thisInstance.parent().removeClass('on').children('ul').slideUp(200)
                : thisInstance.parent().addClass('on').children('ul').slideDown(300);
            
            return false;

        });

});
