$(document).ready(function(){
	$(".featured_div").mouseover(function(){
		$(this).css("background-image","url()");
	});
	$(".featured_div").mouseout(function(){
		$(this).css("background-image","url(images/featured_news_bg.jpg)");
	});
	
	$(".news_weather").mouseover(function(){
		$("#news_weather_sub").stop(true,true).animate({"height":"toggle"});
	});
	$(".news_weather").mouseout(function(){
		alert($(event.target));
		$("#news_weather_sub").stop(true,true).animate({"height":"toggle"});
	
	});
	
	$("#on_air_button").mouseover(function(){
		$("#on_air").stop(true,true).animate({"height":"toggle"});
	});
	$("#on_air_button").mouseout(function(){
		$("#on_air").stop(true,true).animate({"height":"toggle"});
	});
});

function google_search(){
	if($("#search").val() == ''){
		alert("Please enter a search term.");
		return false;	
	}
	$search_type = '';
	$search = '';
}

function search_zip_codes(){
	var search_zip = $("#search_zip").val();
	if(search_zip == ''){
		alert("Please enter your zip code to use this feature.");
		return false;
	}
	if(search_zip.length != 5){
		alert("Your zip code must only contain five characters.");
		return false;
	}
	if(isNaN(search_zip)){
		alert("Please enter a valid five digit zip code.");
		return false;	
	}
window.location="search_zip.php?zip="+search_zip;
}

function change_order(){
	city = $("#event_city").val();
	
	if(city != 'all'){
		location="calendar.php?city="+city+"";
	}else{
		location="calendar.php";
	}
}

function record_hit(banner_id){
	$.post("follow_ad.php?id="+banner_id+"", {  },
	   function(data){
		// alert("Data Loaded: " + data);
	 });
}


function load_results(city,cat_id){
	
	if(cat_id == 'all'){
		$("#content_overlay").height($("#show_listings").height()).show();
			$.post("get_companies.php", { city: ""+city+"", cat_id: "" },
			   function(data){
				 $("#show_listings").html(data);
				 $("#content_overlay").hide();
		   });		
	}else{
		$("#content_overlay").height($("#show_listings").height()).show();
			$.post("get_companies.php", { city: ""+city+"", cat_id: ""+cat_id+"" },
			   function(data){
				 $("#show_listings").html(data);
				 $("#content_overlay").hide();
		   });	
	}
	
	
}

function cat_change(){
	
	var category = $("#cat_name").val();
	
	if(category == 'featured'){
		window.location.reload();
		return false;	
	}
	
	if(category == 'all'){
		//hide the results
		$("#show_listings").html('');
		//load in all results
		show_results('');
		//show arrow
		$("#arrow_div").fadeIn('slow');
		//display loader on city dropdown
		$("#category_div").html('<div style="padding-right:140px;"><img src="images/ajax-loader_small.gif" /></div>');
		//show the loader
		$("#category_div").show();
		//get and display all cities based on search
		$.post("get_categories.php", { cat_id: ""+category+"" },
   		function(data){
     		$("#category_div").html(data);
   		});
		return false;	
	}
	
	$("#content_overlay").height($("#show_listings").height()).show();
	
	$("#arrow_div").fadeIn('slow');
	
	$("#category_div").html('<div style="padding-right:140px;"><img src="images/ajax-loader_small.gif" /></div>');
	$("#category_div").show();
	$.post("get_categories.php", { cat_id: ""+category+"" },
   		function(data){
     	$("#category_div").html(data);
   	});
	
	show_results('');
	
}

function show_results(city_name){
	$("#content_overlay").height($("#show_listings").height()).show();
	load_results(city_name,$("#cat_name").val());
}
