$(document).ready(function(){ 
	
	if ($.cookie("il_def_loc") != null) {
		$("#wherebox").css('color', '#666');
		$("#wherebox").css('font-style', 'italic');
		$("#wherebox").val($.cookie("il_def_loc"));
		$("#wherebox").focus(function() {
			if ($("#wherebox").val() == $.cookie("il_def_loc")) {
				$("#wherebox").val("");
			}
			$("#wherebox").css('color', '#333');
			$("#wherebox").css('font-style', 'normal');
		});
	}
	
	$(".mainsearchtermcloud").click(function() {
		
		dcsMultiTrack(
				'DCSext._hit_type','click',
				'WT.dl','99', 
				'DCSext.linkplace', 'popular now',
				'DCSext.linktype', 'what suggestion');
		$("#whatbox").val($(this).html()).css({"font-style":"normal","font-weight":"bold"}).removeClass("noFocus");
	});
	
	$(".mainsearchlocationcloud").click(function() {
		
		dcsMultiTrack(
				'DCSext._hit_type','click',
				'WT.dl','99', 
				'DCSext.linkplace', 'popular now',
				'DCSext.linktype', 'where suggestion');
		$("#wherebox").val($(this).html()).css({"font-style":"normal","font-weight":"bold"}).removeClass("noFocus");
	});	
	
	$("#whatbox").focus(function(){
		if($(this).attr("value") == $("#whatboxvalue").val()){
			$(this).attr("value", "");
			$(this).css("font-style","normal");
			$(this).css("font-weight","bold");
			$(this).removeClass("noFocus");
		}
	});
	
	$("#whatbox").val($("#whatboxvalue").val());

	$("#wherebox").focus(function(){
		if($(this).attr("value") == $("#whereboxvalue").val() || $(this).css("font-style") == "italic"){
			$(this).attr("value", "");
		}
		$(this).css("font-style","normal");
		$(this).css("font-weight","bold");
		$(this).removeClass("noFocus");
	});

	if ($("#wherebox").val() == "") {
		$("#wherebox").val($("#whereboxvalue").val());
	}
	
	$(".selectcity").click(function() {
		loadPopupBox($(".selectcity").attr("title"));
		$("#popupWindow .top-middle").append("<div class='arrow-up'>&nbsp;</div>");
		$("#popupWindow .top-middle .arrow-up").css("left","340px");
		$("#popupWindow .top-middle .arrow-up").css("top","8px");
		$("#popupWindow").css("width","430px");
		$("#popupWindow").css("left", "535px");
		$("#popupWindow").css("top", ($(this).parent().parent().position().top + 43)+"px");
		$('.container').append($("#popupWindow"));
		$("#popupWindow").show();
		showPopupBoxLoading();
		var offset = $(this).offset();
		var xss = $(this).attr("href"); 
		$.ajax({
			url:  xss,
			type: "POST",			
			success: function(html){
				 $("#reviewContainer").html(html);
				 $(document).click(removeCityPopup);
			}
		});
		return false;
	});
	
	function removeCityPopup(event){
		if ($(event.target).parents("#popupWindow").length < 1) {
			$("#popupWindow").remove();
			$(document).unbind("click", removeCityPopup);
		}
	};
	
	
});
