$(function() 

{

	/* Starts script for browse-form */

    $('.category_link').click(function()

        {

            var link_id     = this.id;

            var link_arr    = link_id.split('_');

            var category_id = link_arr[1];

            var domain      = $('#domain').val();

            $('#browse-form').attr('action', domain+'business/show/'+category_id); 

            $('#link_selected').val('yes');              

        });

        

    $('#go_button').click(function()

        {

            if( $('#link_selected').val() == 'yes' )

                {

                    $('#browse-form').submit();

                }    

            else

                {

                    alert('Please select a Category');

                }

        });

	

	/* Ends script for browse-form */

    

    

    /* Starts script for search-form */

    $('#search_button').click(function()

        {

            if( $('#search').val() == '' )

                {

                    alert('Please type something to search');

                }    

            else

                {

                   var domain = $('#domain').val();

                   $('#search-form').attr('action', domain+'business/search_businesses');

                   $('#search-form').submit();

                }

        });

	

	$('#search').keypress(function(e) 

		{

        	if(e.which == 13) 

				{

            		$(this).blur();

             		var domain = $('#domain').val();

             		$('#search-form').attr('action', domain+'business/search_businesses');

					$('#search-form').focus().click();

        		}

    	});



    /* Ends script for search-form */

    

    

    /* Starts weather integration */

	$.simpleWeather(

		{

			zipcode	: 'ASXX0047',

			unit	: 'c',

			success	: function(weather) 

			{

                                var image = weather.code+ '-' + weather.timeOfDay+'.gif';

                                image = 'webroot/images/front/weather/sniffer_classic/'+image;

                                //alert(image);

                                $("#weather_image").attr("src",image);

                                

				$("#weather_forecast").html(weather.forecast);

				$("#weather_wind").html(weather.wind.direction+' '+weather.wind.speed+' '+weather.units.speed);

				$("#weather_humidity").html(weather.humidity);

				$("#weather_low_temp").html(weather.low+'&deg; '+weather.units.temp);

				$("#weather_high_temp").html(weather.high+'&deg; '+weather.units.temp);

			}

		});

	/* Ends weather integration */

	

});
