var propsWithoutAgeFacet = ['138','139','140','8','9','10','14','15','20','21','26','22','36'];
var barriosCerrados = 	['138','139','140'];

function onChangeLogic(){
	
	$j('#locationCombo').change(function(){
			$j('#optionValue').text('Selecciona'); 
			$j('#labelName').text('Partido / Localidad');
			$j('#option').attr('disabled', false);		
			
			var tipoProp = $j('#dynamic :selected').val();
			if ($j.inArray(tipoProp,barriosCerrados)>=0) {				
			 	if ($j('#locationCombo :selected').val() == '3642') {
			 		$j('#labelName').text('Barrio');
			 		$j('#locationTitle').text('Barrio');
			 	}
			 	else if ($j('#locationCombo :selected').val() == '4314'){
			 		$j('#labelName').text('Localidad');
			 		$j('#locationTitle').text('Localidad');
			 	}
			 	else if ($j('#locationCombo :selected').val() == '5540'){
			 		$j('#labelName').html('Pa&iacute;s / Barrio Cerrado');
			 		$j('#locationTitle').html('Pa&iacute;s / Barrio Cerrado');
			 	}
			 	else if ($j('#locationCombo :selected').val() == '5055' || $j('#locationCombo :selected').val() == '2277' || $j('#locationCombo :selected').val() == '3979' || $j('#locationCombo :selected').val() == '587'){
			 		$j('#labelName').text('Partido / Barrio Cerrado');
			 		$j('#locationTitle').text('Partido / Barrio Cerrado');
			 	}
				else if ($j('#locationCombo :selected').val() == ''){
			 		$j('#labelName').text('Partido / Barrio Cerrado');
			 		$j('#locationTitle').text('Partido / Barrio Cerrado');
			 	}
			 	else {
			 		$j('#labelName').text('Localidad');
			 		$j('#locationTitle').text('Localidad');
			 	}	
			 	
			}
			else {				
				
			 	if ($j('#locationCombo :selected').val() == '3642') {
			 		$j('#labelName').text('Barrio');
			 		$j('#locationTitle').text('Barrio');
			 	}
			 	else if ($j('#locationCombo :selected').val() == '4314'){
			 		$j('#labelName').text('Localidad');
			 		$j('#locationTitle').text('Localidad');
			 	}
			 	else if ($j('#locationCombo :selected').val() == '5540'){
			 		$j('#labelName').html('Pa&iacute;s / Ciudad');
			 		$j('#locationTitle').html('Pa&iacute;s / Ciudad');
			 	}
			 	else if ($j('#locationCombo :selected').val() == '5055' || $j('#locationCombo :selected').val() == '2277' || $j('#locationCombo :selected').val() == '3979' || $j('#locationCombo :selected').val() == '587'){
			 		$j('#labelName').text('Partido / Localidad');
			 		$j('#locationTitle').text('Partido / Localidad');
			 	}
			 	else {
			 		$j('#labelName').text('Localidad');
			 		$j('#locationTitle').text('Localidad');
			 	} 	
			
			} 
		 });	 	 
		 
	$j('#dynamic').change(function(){
		
		$j('#firstOption').text('Selecciona');
		$j('#firstOption').attr('selected', true); 
		$j('#optionValue').text('Selecciona');
		
		updateAgeFacet();
		$j('#locationCombo').change();	
	 	
	 });
}

function updateAgeFacet(){
	var tipoProp = $j('#dynamic :selected').val();
 	if ($j.inArray(tipoProp,propsWithoutAgeFacet) >= 0) {	 	
 		$j("#ageCode").val("");
 		$j("#ageCode").hide();
 		$j("#ageCodeLabel").hide();
 	}
 	else {	 		
 		$j("#ageCode").show();
 		$j("#ageCodeLabel").show();
 	}	 	
 	
}

//Nav Dropdown
$j('li.dropdown span').hover(function() {
	
	$j(this).addClass('hover').parent().find('div').stop(false, true).slideDown('fast');
	
	$j(this).parent().hover($j.noop(), function(){	
		$j(this).parent().find('div').stop(false, true).slideUp('fast',function() {
				$j(this).parent().find('span').removeClass('hover');				
				});
		});
});
	
// Solapas de comunidad
$j(function(){

	var communityTabs = $j('#communityContent .middle');

	$j('#communityNav').find('a').click(function(){
		
		communityTabs.hide().filter(this.hash).show();
		
		$j('#communityNav').find('li').removeClass('current');
		$j(this).parent('li').addClass('current');
		
		return false;
	}).filter(':first').click();

});

function searchById(){
	var idPost = $j("#codeSearch").val();
	if(isNaN(idPost) || idPost==""){
		$j("#warningInvalidCode").overlay({
			onBeforeLoad: function() { 
				this.getOverlay().appendTo('body');
			},
			closeOnClick: true,
			closeOnEsc: true,
			mask: {
				color: '#333',
				loadSpeed: 200,
				opacity: 0.9
				},
			top:'center',
			left: 'center',
			load: true			
		}).load();			
	}else{
		var url = "" + document.location;
		if(url.indexOf('yahoo.zonaprop.com.ar') >= 0){
			window.location.href= "http://yahoo-propiedades.zonaprop.com.ar/idZ" + idPost;			
		}
		else {
			window.location.href= "http://propiedades.zonaprop.com.ar/idZ" + idPost;
		}
	}
	
}

//------ News y Guides --------
google.load("feeds", "1");

function displayNews(result) {
	  var content = "";
	  var thumburl = "";
	  var container = "";
	  var markup = "";
			
	  if (!result.error) {
		for (var i = 0; i < result.feed.entries.length; i++) {
			thumburl = '<img src="http://static.zonaprop.com.ar/static/images/logo_news.jpg">';
			content = result.feed.entries[i].content;              
		    container = $j('<div/>').html(content);
	
		  	$j(container).find('img').each(function() {
		  		thumburl = '<img src="' + $j(container).find('img').attr('src') + '">'
			});
			
			markup += '<div class="news-item">' + thumburl + '<a target="_blank" href="' + result.feed.entries[i].link + '" class="title">' + result.feed.entries[i].title + '</a><p>' + result.feed.entries[i].contentSnippet + '</p><a taget="_blank" href="' + result.feed.entries[i].link + '">Leer completo &raquo;</a></div>';
		}       
		
		document.getElementById('newsFeed').innerHTML = markup;
	  }
	}

function initializeNews() {
  var feed = new google.feeds.Feed('http://noticias.zonaprop.com.ar/category/inmuebles/feed/');
  //var feed = new google.feeds.Feed('http://www.zonaprop.com.ar/contenido/syndicate/feed.rss');
  feed.setNumEntries(3);
  feed.load(displayNews);
}

google.setOnLoadCallback(initializeNews);

function displayGuides(result) {
	  var content = "";
	  var thumburl = "";
	  var container = "";
	  var markup = "";
			
	  if (!result.error) {
		for (var i = 0; i < result.feed.entries.length; i++) {
			thumburl = '<img src="http://static.zonaprop.com.ar/static/images/logo_news.jpg">';
			content = result.feed.entries[i].content;              
		    container = $j('<div/>').html(content);
	
		  	$j(container).find('img').each(function() {
	  			thumburl = '<img src="' + $j(container).find('img').attr('src') + '">'
			});
		  	
		  	markup += '<div class="news-item">' + thumburl + '<a target="_blank" href="' + result.feed.entries[i].link + '" class="title">' + result.feed.entries[i].title + '</a><p>' + result.feed.entries[i].contentSnippet + '</p><a target="_blank" href="' + result.feed.entries[i].link + '">Leer completo &raquo;</a></div>';
		}
		
		document.getElementById('guidesFeed').innerHTML = markup;
	  }
	}
		
function initializeGuides() {
var feed = new google.feeds.Feed('http://noticias.zonaprop.com.ar/category/guias-de-hogar/feed/');
feed.setNumEntries(3);
feed.load(displayGuides);
}
		
google.setOnLoadCallback(initializeGuides);

