function initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};
function highlight(carousel, obejctli,liindex,listate){
	jQuery('.jcarousel-control a:nth-child('+ liindex +')').attr("class","selected");
};
function removehighlight(carousel, obejctli,liindex,listate){
     jQuery('.jcarousel-control a:nth-child('+ liindex +')').removeAttr("class","selected");
};

jQuery(document).ready(function() {
	$('#simple').css("background-image","url(skins/basic/customers/imgs/searchtab.png)");
	$("#header-content-search-inteligent").hide();
	$("#header-content-search-free").hide();
	$("#sold-price").hide();
	$("#simple").click(function(){
		$("#header-content-search-inteligent").hide();
		$("#header-content-search-free").hide();
		$("#header-content-search-simple").show();
		$('#simple').css("background-image","url(skins/basic/customers/imgs/searchtab.png)");
		$('#free').css("background-image","");
		$('#inteligent').css("background-image","");
	});
	$("#free").click(function(){
		$("#header-content-search-free").show();
		$("#header-content-search-inteligent").hide();
		$("#header-content-search-simple").hide();
		$('#free').css("background-image","url(skins/basic/customers/imgs/searchtab.png)");
		$('#simple').css("background-image","");
		$('#inteligent').css("background-image","");
	});
	$("#inteligent").click(function(){
		$("#header-content-search-inteligent").show();
		$("#header-content-search-free").hide();
		$("#header-content-search-simple").hide();
		$('#inteligent').css("background-image","url(skins/basic/customers/imgs/searchtab.png)");
		$('#free').css("background-image","");
		$('#simple').css("background-image","");
	});
	$("#inteligent-state").change(function(){
		$.post('classes/control/site/searchCTRL.php', 
				{ 
					act : "city",
					state : this.value 
				}, 
				function(answer){
					$("#inteligent-city").html(answer);
					$("#inteligent-neighborhood").html("<option value=''>------------------</option>");
				}
			);
	});
	$(".imprimir").click(function(){
		window.print();
	});
	$("#inteligent-city").change(function(){
		$.post('classes/control/site/searchCTRL.php', 
				{ 
					act : "neighborhood",
					city : this.value 
				}, 
				function(answer){
					$("#inteligent-neighborhood").html(answer);
				}
			);
	});
	$("#simple-btn").click(function(){
		if($(".ref").val() == "0"){
			window.location.href ="index.php?location=search_property&type=simple-type"+"&typeData="+$("#simple-purpose").val()+"|"+$("#simple-type-select").val();
		} else {
			window.location.href ="index.php?location=search_property&type=simple-profile"+"&typeData="+$("#simple-purpose").val()+"|"+$("#simple-profile-select").val();
		}
			
		
	});
	$("#inteligent-btn").click(function(){
		if($("#inteligent-purpose").val() == "2"){
			window.location.href ="index.php?location=search_property&type=inteligent"+"&typeData="+$("#inteligent-purpose").val()+"|"+$("#inteligent-state").val()+"|"+$("#inteligent-city").val()+"|"+$("#inteligent-neighborhood").val()+"|"+$("#inteligent-type").val()+"|"+$("#sold-price").val();
		} else {
			window.location.href ="index.php?location=search_property&type=inteligent"+"&typeData="+$("#inteligent-purpose").val()+"|"+$("#inteligent-state").val()+"|"+$("#inteligent-city").val()+"|"+$("#inteligent-neighborhood").val()+"|"+$("#inteligent-type").val()+"|"+$("#rent-price").val();
		}
			
		
	});
	$("#inteligent-purpose").change(function(){
		switch(this.value){
			case "2": {
				$("#sold-price").show();
				$("#rent-price").hide();
				break;
			}
			case "3": {
				$("#sold-price").hide();
				$("#rent-price").show();
				break;
			}
		}
		
	});
	$("#simple-profile-select").css("display","none");
	$(".ref").click(function(){
		if(this.value == 0){
			$("#title").html("Tipo");
			$("#simple-type-select").css("display","block");
			$("#simple-profile-select").css("display","none");
		} else {
			$("#title").html("Perfil");
			$("#simple-type-select").css("display","none");
			$("#simple-profile-select").css("display","block");
		}
	});
    jQuery("#header-content-banner").jcarousel({
        scroll: 1,
        initCallback: initCallback,
        auto: 5,
        wrap: "both",
        animation : 1000,
        buttonNextHTML: null,
        buttonPrevHTML: null,
        itemVisibleInCallback:  highlight,
        itemVisibleOutCallback: removehighlight
    });
});