/*@ main.js
-------------*/

$(document).ready(function(){

	if ( $("#form-contact").length ){
		// Referencia al textarea
		var labelArea	=	$("#form-contact").find("textarea");

		// Valor por defecto
		labelArea.append(please);

		// Acciones al hacer focus o out focus
		labelArea
			.focus( function(){ $(this).text('') })
			.blur( function(){	$(this).append(please) });
	}

	// Instancia a Cufon
	Cufon.replace('#entity');

	// Centrado de la web, respecto de
	// las dimensiones de la ventana.
	$(window).resize(function(){

		// Reubicamos el wrapper.
		if( $(window).height() > 610 ){
			//alert('outer contenido:' + $('#wrapper').outerHeight() + ' height ventana:' + $(window).height() );
			$('#wrapper').css({
			   position:'absolute',
			   left: ($(window).width() - $('#wrapper').outerWidth())/2,
			   top: ($(window).height() - $('#wrapper').outerHeight())/2
			});
		}
    });
	$(window).resize();

	/* @ Paginación para:
	//	Otras propiedades, galería de fotos.
	-------------------------*/

	var	structure;
	var blockOpacity;
	if( $('#other-properties').length ){

		structure	=	$('#other-properties ul');
		blockOpacity=	structure.find("li");
	}
	if( $('#gallery-property').length ){
		structure	=	$('#gallery-property > a');
		blockOpacity=	structure;
	}
	if( structure && blockOpacity ){
		structure.easyPaginate({
			step:8,
			delay: 100,
			numeric: false,
			nextprev: true,
			auto:false,
			pause:4000,
			clickstop:true,
			controls: 'pagination'
		});

		//settings
		var opacity = 0.7, toOpacity = 1, duration = 250;

		//set opacity ASAP and events
		blockOpacity.css('opacity',opacity).hover(
			function() {
				$(this).stop(true,true).fadeTo(duration,toOpacity);
			}, function() {
				$(this).stop(true,true).fadeTo(duration,opacity);
			}
		);
		if( $('#gallery-property').length ){

			$("#gallery-property a").click(function(e){

				e.preventDefault();
				var $clicked			=	$(this).attr('href');
				var $ref				=	$("#photo-property");
				var	$imageCurrent	=	$("#photo-property").attr('src');

				if ( $clicked != $imageCurrent ){
					$ref.animate({opacity:"0"},200).attr("src", $clicked).load( function(){
						$(this).animate({opacity:"1"},200);
					});
				}
			});

		}
	}


	/* @ Animate main menu
	----------------------*/
	$(function() {
		if( $(".current-page").length ){
			var $el, leftPos, newWidth,
				//$mainNav = $("#example-one");
			$mainNav	= $("#main-nav");
			$mainNav.append("<li id='magic-line'></li>");
			var $magicLine = $("#magic-line");

			$magicLine
				.width($(".current-page").width())
				.css("left", $(".current-page a").position().left)
				.data("origLeft", $magicLine.position().left)
				.data("origWidth", $magicLine.width());

			$("#main-nav li a").hover(function() {
				$el = $(this);
				leftPos = $el.position().left;
				newWidth = $el.parent().width();
				$magicLine.stop().animate({
					left: leftPos,
					width: newWidth
				});
			}, function() {
				$magicLine.stop().animate({
					left: $magicLine.data("origLeft"),
					width: $magicLine.data("origWidth")
				});
			});
		}
	});

	if( $('#properties').length ){
		var opacity = 0.7, toOpacity = 1, duration = 250;
		//set opacity ASAP and events
		$('#properties li').css('opacity',opacity).hover(
			function() {
				$(this).stop(true, true).fadeTo(duration,toOpacity);
			}, function() {
			$(this).stop(true, true).fadeTo(duration,opacity);
			}
		);
	}
	/* @ Google maps
	----------------*/
	/*
	if ( $("#map").length ){

		var latitud	=	38.932565;
		var longitud=	1.497778;

		function initialize() {
			var myLatlng = new google.maps.LatLng(latitud, longitud);
			var myOptions = {
			  zoom: 13,
			  center: myLatlng,
			  mapTypeId: google.maps.MapTypeId.HYBRID
			}

			var map = new google.maps.Map( $("#map")[0], myOptions);

			var contentString = '<div id="map-information">'+
				'<h2>Ibiza Roca llisa</h2>'+
				'<p>Heritage Site.</p>'+
				'</div>';

			var infowindow = new google.maps.InfoWindow({
				content: contentString
			});

			var marker = new google.maps.Marker({
				position: myLatlng,
				map: map,
				title: 'Roca Llisa Ibiza'
			});
			google.maps.event.addListener(marker, 'click', function() {
			  infowindow.open(map,marker);
			});
		}
		window.ready = initialize();
	}
	*/
});
