﻿// JavaScript Document

$(function() {
		   
		   
	  // Settings
    var viewportTop   = 80,
          scrollTime      = 600,
          openTime      = 600,
          completeTime  = 1200,
		  scrollElement = "html,body";
    // Initialize waypoints
    $("#wrapper > div").waypoint({ offset: viewportTop });
    // Detect iOS and Android*/
    if((!navigator.userAgent.match(/iPhone/i)) && (!navigator.userAgent.match(/iPod/i)) && (!navigator.userAgent.match(/iPad/i)) && (!navigator.userAgent.match(/Android/i))) {
        // Sticky nav for desktop
        $("#nav").stickyPanel();
        // Do stuff when waypoints are reached
      $("body").delegate("#wrapper > div", "waypoint.reached", function (event, direction) {
      var $active = $(this);
      if (direction === 'up') {
        $active = $active.prev();
      }
      if (!$active.length) { $active.end(); }
      $(".section-active").removeClass("section-active");
      $active.addClass("section-active");
      $(".selected").removeClass("selected");
      $("a[href=#"+$active.attr("id")+"]").addClass("selected");
    });
  }

  
$('#slider').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:5000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:true, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0, // Universal caption opacity
        prevText: 'Anterior', // Prev directionNav text
        nextText: 'Siguiente', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });

$("a[rel='gallery1']").colorbox({width:"80%"});
$("a[rel='gallery2']").colorbox({width:"80%"});
$("a[rel='gallery3']").colorbox({width:"80%"});
$("a[rel='gallery4']").colorbox({width:"80%"});


$(".scrollable").scrollable();

$(".items img").click(function() {

	// see if same thumb is being clicked
	if ($(this).hasClass("active")) { return; }

	// calclulate large image's URL based on the thumbnail URL (flickr specific)
	var url = $(this).attr("src").replace("_mini", "");

	// get handle to element that wraps the image and make it semi-transparent
	var wrap = $("#image_wrap").fadeTo("medium", 0.5);

	// the large image from www.flickr.com
	var img = new Image();


	// call this function after it's loaded
	img.onload = function() {

		// make wrapper fully visible
		wrap.fadeTo("fast", 1);

		// change the image
		wrap.find("img").attr("src", url);

	};

	// begin loading the image from www.flickr.com
	img.src = url;

	// activate item
	$(".items img").removeClass("active");
	$(this).addClass("active");

// when page loads simulate a "click" on the first image
}).filter(":first").click();

$('input:text[name=name]').focus(function() {
		var namevar=$(this).val();
		if(namevar=='Name*'){
    		$(this).val('');
		}
	});

$('input:text[name=name]').focusout(function() {
		var namevar=$(this).val();
		if(namevar==''){
	    	$(this).val('Name*');
		}
	});

$('input:text[name=tel]').focus(function() {
		var telvar=$(this).val();
		if(telvar=='Phone'){
    		$(this).val('');
		}
	});

$('input:text[name=tel]').focusout(function() {
		var telvar=$(this).val();
		if(telvar==''){
	    	$(this).val('Phone');
		}
	});

$('input:text[name=email]').focus(function() {
		var emailvar=$(this).val();
		if(emailvar=='Email*'){
    		$(this).val('');
		}
	});

$('input:text[name=email]').focusout(function() {
		var emailvar=$(this).val();
		if(emailvar==''){
	    	$(this).val('Email*');
		}
	});



$('#message').focus(function() {
		var messagevar=$(this).val();
		if(messagevar=='Write Your Text'){
    		$(this).val('');
		}
	});

$('#message').focusout(function() {
		var mensajevar=$(this).val();
		if(mensajevar==''){
	    	$(this).val('Write Your Text');
		}
	});




   // Smooth scrolling for internal links
	$("a[href^='#']").click(function (event) {
		event.preventDefault();
		var $this   = $(this),
		    target  = this.hash,
		    $target = $(target);
		$(scrollElement).stop().animate({
			"scrollTop": $target.offset().top
		}, scrollTime, "swing", function () {
			window.location.hash = target;
		});
	});

  
});

