var lastH;
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
}
function overHome() { thisMovie("home").mOver(); }
function outHome() { thisMovie("home").mOut(); }

function scrollFlash(px, animated) {
	if (animated == undefined) animated = 0;
	$('html, body').animate({
		scrollTop: px
	}, animated);
}

function resizeFlash(h) {
	lastH = h;
	if (h < $('body').outerHeight()) h = '100%';
	if (h != '100%') {
		h += $('.footer-padrao-natura').outerHeight()
	}
	$('.master').css('height', h);
}

$(function () {
	$(window).resize(function () {
		resizeFlash(lastH);
	});
	$('.envie-historia a').hover(function () {
		overHome();
	}, function () {
		outHome();
	});

	$(".barra-top ul > li").hover(function () {
		//$(this).find("ul").show();
	}, function () {
		$(this).find("ul").hide();
	});

	$(".barra-top ul > li").click(function () {
		$(this).find("ul").stop(true, true).show();
	}, function () {
		$(this).find("ul").hide();
	});

	$(".bt-mapa-site").click(
		function () {
			$(this).toggleClass("aberto");
		}
	);

	$(".bt-mapa-site").toggle(
		function () {
			$(".mapa-site").height('160px');
		},
		function () {
			$(".mapa-site").height('27px');
		}
	);

	// Efeitos LAYER EBOOK 
	$('.bt-veja-ebook').click(function () {
		$('#layer').show();
		$(".overflow").animate({
			left: '0'
		}, { duration: 1500, easing: 'easeOutBounce' });

		setTimeout(function () {
			$(".bt-inicio").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 800);

		setTimeout(function () {
			$(".bt-historia-01").animate({
				marginTop: '10px'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 1000);

		setTimeout(function () {
			$(".bt-historia-02").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 1200);

		setTimeout(function () {
			$(".bt-historia-03").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 1400);

		setTimeout(function () {
			$(".bt-historia-04").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 1600);

		setTimeout(function () {
			$(".bt-historia-05").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 1800);

		setTimeout(function () {
			$(".bt-historia-06").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 2000);

		setTimeout(function () {
			$(".bt-historia-07").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 2200);

		setTimeout(function () {
			$(".bt-historia-08").animate({
				marginTop: '0'
			}, { duration: 600, easing: 'easeOutBounce' });
		}, 2400);
	});

	$('.ebook .bt-voltar').click(function () {
		setTimeout(function () {
			$('#layer').hide();
		}, 800);

		$(".overflow").animate({
			left: '-1920px'
		}, { duration: 1500, easing: 'easeOutBounce' });

		$(".nav ul li").animate({
			marginTop: '-70px'
		}, 100);

	});

	$('.lista-produtos li').hover(function () {
		var _this = this;
		$(_this).find('.mais').stop(true, false).animate({
			width: '98px'
		}, 300, function () {
			$(_this).find('.mais .txt-det').stop(true, false).animate({
				right: '10px'
			}, 200);
		});
	}, function () {
		var _this = this;
		$(_this).find('.txt-det').stop(true, true).animate({
			right: '-67px'
		}, 0, function () {
			$(_this).find('.mais').stop(true, false).animate({
				width: '21px'
			}, 200);
		});
	});

	// Controle layer vídeo
	$('.bt-veja-video').click(function () {
		$('#layer').show();
		$("#layer .video").animate({
			top: '30px'
		}, { duration: 1000, easing: 'easeOutBounce' });
	});

	$('#layer .video .bt-fechar').click(function () {
		$(this).parent().animate({
			top: '-561px'
		}, 500, function () {
			$('#layer').hide();
		});
	});

	// Controle layer O que é e-book
	$('.bt-oquee-ebook').click(function () {
		$('#layer').show();
		$("#layer .oquee-ebook").animate({
			top: '70px'
		}, { duration: 1000, easing: 'easeOutBounce' });
	});

	$('#layer .oquee-ebook .bt-fechar').click(function () {
		$(this).parent().animate({
			top: '-500px'
		}, 500, function () {
			$('#layer').hide();
		});
	});

	// Controle layer news
	$('.bt-baixe-ebook').click(function () {
		$('#layer').show();
		$("#layer #box_news").animate({
			top: '70px'
		}, { duration: 1000, easing: 'easeOutBounce' });
	});

	$('#layer #box_news .bt-fechar').click(function () {
		$(this).parent().animate({
			top: '-500px'
		}, 500, function () {
			$('#layer').hide();
		});
	});

	// Controle layer Form
	$('.bt-envie-historia').click(function () {
		$('#layer, .form-parte-01, .form-parte-02, .termos-uso').hide();
		$('#layer, .form-parte-01').show();
		$("#layer .form-historia").animate({
			top: '70px'
		}, { duration: 1000, easing: 'easeOutBounce' });
	});

	$('#layer .form-historia .bt-fechar').click(function () {
		_gaq.push(['_trackPageview', location.pathname]);
		$(this).parent().animate({
			top: '-500px'

		}, 500, function () {
			limpaForm();
			$('#layer, .form-parte-01').hide();
		});
	});

	$('#layer .bt-enviar-nova').click(function () {
		limpaForm();
		$('.box-tipo-02').hide();
		$('.form-parte-02').hide();
		$('.form-parte-01').show();
		$('.form-historia').animate({
			top: '70px'

		});
	});

	$('#layer .bt-voltar-ebook').click(function () {
		limpaForm();
		$('.box-tipo-02').hide();
		$('#layer').hide();

	});

	$('.embalagens-especiais').click(function () {
		document.getElementById('embalagens').setAttribute("class", "");
		$('.caixas').show();
	});

	$('.layer-presentes .bt-fechar').click(function () {
		document.getElementById('embalagens').setAttribute("class", "embalagens-especiais");
		$(this).parent().hide();
	});
});

function ShowSelection(textComponent) {
	var selectedText;
	// IE version
	if (document.selection != undefined) {
		textComponent.focus();
		var sel = document.selection.createRange();
		selectedText = sel.text;
	}
	// Mozilla version
	else if (textComponent.selectionStart != undefined) {
		var startPos = textComponent.selectionStart;
		var endPos = textComponent.selectionEnd;
		selectedText = textComponent.value.substring(startPos, endPos)
	}
	return selectedText;
}


