$(document).ready(function(){
	$("div#banner > #slider").easySlider({
				auto: true,
				continuous: true,
				speed:1000,
				pause:5000
	});
	$("#page > #menu > ul > li.submenu > div").css({
		'visibility' : 'hidden',
		'z-index' :'100',
		'height' : '0px'		
	});
	$("#page > #menu > ul > li.submenu").hover(function () {
			// animate opacity to full
			$(this).children("a").css("background-color","#320303")
			$("#page > #menu > ul > li.submenu > div").stop().css("visibility","visible").animate({
				height: "86px",
				opacity: 1
			}, 500 );
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).children("a").css("background-color","white")
			$("#page > #menu > ul > li.submenu > div").stop().animate({
				height: "0px",
				opacity: 0																								  
			}, 500 );
		});
	
	
    $("#contenido > #destacados > a ").css("opacity",0.7);
	$("#contenido > #destacados > a ").hover(function () {
			$(this).stop().animate({
				opacity: 1
			}, "2000");
		},
		function () {
			$(this).stop().animate({
				opacity: 0.7
			}, "2000");
		});
	$("#ampa span").css("opacity","0");
	$("#ampa").hover(function () {
			$(this).children("span").stop().animate({
				opacity: 1
			}, "2000");
		},
		function () {
			$(this).children("span").stop().animate({
				opacity: 0
			}, "2000");
	});
	
	$("div#contenido > div#destacados > a:nth-child(3n)").addClass("nmr");
	$("div#contenido > div#ultimos > a:nth-child(even)").addClass("nmr");
	
		$("div#proplist > div:nth-child(even):not(.clear)").addClass("nmr");

	// $("div#proplist > div").hover(function(){		
		// $("div#proplist > div").not($(this)).children("a").stop().animate({
				// opacity:0.5
				// }, "500");
		// },
		// function () {
			// $("div#proplist > div").not($(this)).children("a").stop().animate({
			// opacity:1
		// }, "500");
	// });
	
	
	(function($){
	
		// We override the animation for all of these color styles
		jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor', 'borderColor' ], function(i,attr){
			jQuery.fx.step[attr] = function(fx){
				if (fx.state == 0 || fx.start.constructor != Array || fx.end.constructor != Array){
					fx.start = getColor( fx.elem, attr );
					fx.end = getRGB( fx.end );
				}
	
				fx.elem.style[attr] = "rgb(" + [
					Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
					Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
					Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
				].join(",") + ")";
			}
		});
	
		// Color Conversion functions from highlightFade
		// By Blair Mitchelmore
		// http://jquery.offput.ca/highlightFade/
	
		// Parse strings looking for color tuples [255,255,255]
		function getRGB(color) {
			var result;
	
			// Check if we're already dealing with an array of colors
			if ( color && color.constructor == Array && color.length == 3 )
				return color;
	
			// Look for rgb(num,num,num)
			if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
				return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
	
			// Look for rgb(num%,num%,num%)
			if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
				return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
	
			// Look for #a0b1c2
			if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
				return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
	
			// Look for #fff
			if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
				return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
	
			// Otherwise, we're most likely dealing with a named color
			return colors[jQuery.trim(color).toLowerCase()];
		}
		
		function getColor(elem, attr) {
			var color;
	
			do {
				color = jQuery.curCSS(elem, attr);
	
				// Keep going until we find an element that has color, or we hit the body
				if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
					break; 
	
				attr = "backgroundColor";
			} while ( elem = elem.parentNode );
	
			return getRGB(color);
		};
		
		// Some named colors to work with
		// From Interface by Stefan Petre
		// http://interface.eyecon.ro/
	
		var colors = {
			blanco:[255,255,255],
			negro:[0,0,0],
			amarillito:[243,230,175],
			rojo:[148,33,25],
			gris:[204,204,204],
			grisoscuro:[51,51,51]
		};
		
	})(jQuery);
	
	
	// GALERIA	
	
		$("ul.gallery li:last-child").css("margin-right","0px");
		$('ul.gallery').galleria({
			history   : false, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			caption   : false,
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);
				}
				caption.css('display','none').fadeIn(500);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.5);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Proxima Foto >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.5';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.5); } // don't fade out if the parent is active
				)
			}
		});
		
	// TOOLTIP
	$("#print").simpletip({
			content: '<span>imprimir la ficha<br />de esta propiedad</span>',
			position: [-70,-80],
			showEffect: 'fade',
			hideEffect: 'fade'
	}); 
	$("#mail").simpletip({
			content: '<span>le puede interesar a un conocido? envia esta ficha por mail</span>',
			position: [50,-80],
			showEffect: 'fade',
			hideEffect: 'fade'
	}); 
	$("#add").simpletip({
			content: '<span>La lista de consulta te permite guardar todas las propiedades que te interesen luego nos las envias por email y nosotros nos contactaremos para informarte m&aacute;s</span>',
			position: [210,-152],
			showEffect: 'fade',
			hideEffect: 'fade'
	});
});
