$(document).ready(function(){	
	
	
	$(".movie-btn").click(function() {
		$("#movie-container iframe").attr("src", "https://www.youtube.com/embed/agS9PEHHYAs?rel=0&autoplay=1");
		$("#movie-container, #movie-container-bg").show();
	});
	
	$("#movie-container-close a, #movie-container-bg").click(function() {
		$("#movie-container, #movie-container-bg").hide();
		$("#movie-container iframe").attr("src", "");
	});
	
	$(".fancybox").fancybox({
		'width'				: 710,
		'height'			: 700,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	
	jQuery.fn.anchorAnimate = function(settings) {
	
		settings = jQuery.extend({
			speed : 1100
		}, settings);	
		
		return this.each(function(){
			var caller = this
			$(caller).click(function (event) {
				$("#anchor-nav ul li").removeClass("active");
				$(this).parent().addClass("active");
				event.preventDefault()
				var locationHref = window.location.href
				var elementClick = $(caller).attr("href")
				
				var destination = $(elementClick).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
					window.location.hash = elementClick
				});
				return false;
			})
		})
	}

	
	$(".type-post.status-publish").each(function() {
		$(this).find(".facebook-share-con").prependTo($(this).find(".mr_social_sharing_wrapper"));
		
	});
	
	
	/*$(".course").each(function() {
		var src = $(this).find("img").attr("src");
		if(src) {
			src = src.toLowerCase();
			
			if(src.search(/kmh/i) > 1) {
				$(this).hide();
			}
		}
		
	});
	*/
	
	var html = $(".hab-planer-nav").html();
	$(".hab-planer-nav").remove();
	
	$("#add-hab-planer-nav").append('<div class="hab-planer-nav">'+html+'</div>');
	
	$(".hab-planer-nav a").live("click", function() {
		
		
		$("#movie-container-bg").show();
		$("body").append('<div id="hab-planer-loading"></div>');
		
		$.ajax({
			method: "get", url: $(this).attr("href"), data: "",
			beforeSend: function(){ },
			complete: function(){ },
			success: function(html) {
				$("#hab-planer-container, #hab-planer-loading").remove();
				var scrollTopIs = $(window).scrollTop() + 400;
				$("body").append('<div id="hab-planer-container" style="top: '+scrollTopIs+'px;"><a id="hab-planer-close" href="#"></a>'+html+'</div>');
			
				
				
			}
		});
		
		$("#hab-planer-close, #movie-container-bg").live("click", function() {
			$("#movie-container-bg").hide();
			$("#hab-planer-container").remove();
			return false;
		});
		
		return false;
	});

	
	var animates = "slide";
	var speed = 600;
	var timer = 4000;
	var ClickStopInterval = true;
	var totWidth = 0;
	var positions = new Array();
	$('#animate-content .animate').each(function(i){
		positions[i]= totWidth;
		totWidth += $(this).width();
		if(!$(this).width()) {
			alert("Please, fill in width & height for all your images!");
			return false;
		}
	});
	
	$('#animate-content').width(totWidth);
	$('#menu-animate ul li a').click(function(e,keepScroll) {
		
		$('li.menuItem').removeClass('act').addClass('inact');
		$(this).parent().addClass('act');
		
		var pos = $(this).parent().prevAll('.menuItem').length;
		
		if(animates == "fade") {
			$(".animate").fadeOut(speed, function() {
				$('#animate-content').stop().animate({marginLeft:-positions[pos]+'px'},0);
				$(".animate").fadeIn(speed);
			});
		} else if(animates == "slide") {
			$(".animate-title").fadeOut(speed, function() {
				$('#animate-content').stop().animate({marginLeft:-positions[pos]+'px'}, speed, function() {
					$(".animate-title").fadeIn(speed);
				});
			});
			
		}
		
		e.preventDefault();
		// Stopping the auto-advance if an icon has been clicked:
		if(!keepScroll && ClickStopInterval == true) { 
			clearInterval(itvl);
		
		}
	});
	
	$('#menu-animate ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* Enabling auto-advance. */
	var current=1;
	function autoAdvance() {
		if(current==-1) return false;
		$('#menu-animate ul li a').eq(current%$('#menu-animate ul li a').length).trigger('click',[true]);
		current++;
	}
	
	var itvl = setInterval(function(){autoAdvance()}, timer);
	
	var offset = $("#anchor-nav").offset();
	var topPadding = 62;
	
	$(window).scroll(function() {
		if ($(window).scrollTop() > offset.top) {
			$("#anchor-nav").stop().animate({
				marginTop: $(window).scrollTop() - offset.top + topPadding
			});
		} else {
			$("#anchor-nav").stop().animate({
				marginTop: 62
			});
		};
	});
	
	if ($(window).scrollTop() > offset.top) {
		$("#anchor-nav").stop().animate({
			marginTop: $(window).scrollTop() - offset.top + topPadding
		});
	}
	
		   
	
	$("a.anchorLink").anchorAnimate();
	
	

});
