$(document).ready(function(){
		var now = new Date();
		var hour = now.getHours();
		if(hour>20||hour<7){
			$("body").addClass("noche");
			$(".pasto").addClass("noche");
		}
		else if(hour>17){
			$("body").addClass("tarde");
			$(".pasto").addClass("tarde");
		}
		else {
			$("body").addClass("dia");
			$(".pasto").addClass("dia");
		}
		
		var animator = function(travelTime, ltr, width, imgFactory) {
			var img = imgFactory();
			$("#casa").append(img);
			img.fadeIn(1500, 'linear');
			var distance = parseInt($(window).width()) - width - parseInt(ltr ? img.css("left") : img.css("right"));
			var toPosition = ltr ? {left: "+=" + distance} : {right: "+=" + distance};
			img.animate(toPosition, travelTime, 'linear', function() {
				img.fadeOut(1500, function() {
					img.detach();
				});
			}).dequeue();
		}
	 
		var loop = function(start, interval, func) {
		  setTimeout(func, start);
		  setInterval(func, interval);
		}
		
		loop(1000, 20000, function() {
			animator(15000, false, 0, function(){
				var mitad = $(window).width()/2;
				mitad=250;
				mitad+="px;";
				return $('<img src="' + "sites/all/themes/alitas/images/granjero.png" + '" class="animated" style="z-index:1;position:absolute; bottom: 33px; right: '+mitad+'" />');
			});
		});
		
		$("#contenedor").height($(window).height());
		
		
		$(window).resize(function(e) {
            if(($(window).height()-449)<203){
				$("#header").height(203);
			}
			else{
				$("#header").height($(window).height()-449);
			}
			$("#birdsCanvas #bg canvas").width($(window).width());
			$("#birdsCanvas #bg canvas").height($(window).height()/2);
        });
		if(($(window).height()-449)<203){
			$("#header").height(203);
		}
		else{
			$("#header").height($(window).height()-449);
		}
		
		$('.slideshow').cycle({fx: 'growY'});
		
		$("#puerta").mouseover(function(){
			$(".flechaHome").everyTime( 10, function (){
				$(".flechaHome").animate({"margin-left":"+=10px","margin-top":"-=10px"}, 500);
				$(".flechaHome").animate({"margin-left":"-=10px","margin-top":"+=10px"}, 500);
			});
		});
		
		$("#puerta").mouseout(function(){
			$(".flechaHome").stop(true).stopTime();
			$(".flechaHome").removeAttr("style");
		});
		
		
		$(".cambiarVeleta").mouseover(function(){
			var src = $(this).attr("src");
			var path = src.split(".png")[0];
			$(this).attr("src", path+".gif");

		});
		$(".cambiarVeleta").mouseout(function(){
			var src = $(this).attr("src");
			var path = src.split(".gif")[0];
			$(this).attr("src", path+".png");
		});
		
		
		
		$(".letItem").mouseover(function(){
			var src = $(this).children("img").attr("src");
			var path = src.split("_normal.png")[0];
			$(this).children("img").attr("src", path+"_hover.png");

		});
		$(".letItem").mouseout(function(){
			var src = $(this).children("img").attr("src");
			var path = src.split("_hover.png")[0];
			$(this).children("img").attr("src", path+"_normal.png");
		});	
		
		
	});

