/******************************
* Cliente: Lolita Colita
* Author: Franklin Salcedo
* Date: 01-06-2011
******************************/

/*** Inyección de elementos HTML5 en IE ***/
document.createElement("article");
document.createElement("footer");
document.createElement("header");
document.createElement("hgroup");
document.createElement("nav");
document.createElement("section");

$(document).ready(function(e) {
	/* Menu */
	if($("#menu").length > 0){
		centerMenu();
	}
	if($("#content").length > 0){
		centerContent();	
	}
	
	/* Menu Big */
	$("#menu li, nav li:not('.btn_home')").click(function(){
		if(parseInt($("#menu").css("right")) > -455){
			$("#menu").animate({ 
				right : '-=455' },
				1000,
				function(){
					$("#btn_show_menu").fadeIn("fast");
				}
			);
		}
		$("#back_gallery:visible").fadeOut();
		$(".flowers").fadeIn();
	});
	
	$("#btn_show_menu").click(function(){
		$(this).fadeOut("fast",function(){
			$("#menu").animate({
				right : '0'},
				1000
			);
		});
	});
	
	
	/*** Carga de páginas ***/
	
	/* Home */
	$(".btn_home").click(function(){
		$("body").attr("id","home");
		$("h2:visible").fadeOut();
		$("#content").html("");
		$("#menu").animate({
			right : '0'},
			1000
		);
	});
	
	/* Bio */
	$(".big_bio, .btn_bio").click(function(){
		$("body").attr("id","bio");
		$("h2:visible").fadeOut();
		$(".tit_bio").fadeIn();
		$.ajax({
			url: 'bio.php',
			success: function(data) {
				$("#content").html(data);
				$("#cont_bio").corner("30px");
			}
		});
	});
	
	$("#cont_bio .btndown").live("click",function(){
		hscroll = $(".scroll").height() - 40;
		if(parseInt($("#cont_bio .scroll").css("margin-top")) > "-"+hscroll)
			$("#cont_bio .scroll").animate({"margin-top":"-=40"},300);
	});
	
	$("#cont_bio .btnup").live("click",function(){
		if(parseInt($("#cont_bio .scroll").css("margin-top")) < 0)
			$("#cont_bio .scroll").animate({"margin-top":"+=40"},300);
			
	});
	
	
	/* Contacto */
	$(".big_contactos, .btn_contactos").click(function(){
		$("body").attr("id","contacto");
		$("h2:visible").fadeOut();
		$(".tit_contacto").fadeIn();
		$.ajax({
			url: 'contacto.php',
			success: function(data) {
				$("#content").html(data);
			}
		});
	});
	
	/* Tienda */
	$(".big_tienda, .btn_tienda").click(function(){
		$("body").attr("id","tienda");
		$("h2:visible").fadeOut();
		$(".tit_tienda").fadeIn();
		$.ajax({
			url: 'tienda.php',
			success: function(data) {
				$("#content").html(data);
			}
		});
	});
	
	/* Colección */
	$(".big_coleccion, .btn_coleccion").click(function(){
		$("body").attr("id","coleccion");
		$("h2:visible").fadeOut();
		$(".tit_coleccion").fadeIn();
		$.ajax({
			url: 'coleccion.php',
			success: function(data) {
				$("#content").html(data);
				$("#cont_coleccion").corner("30px");
			}
		});
	});
	
	$("#cont_coleccion .btndown").live("click",function(){
		hscroll = $(".scroll").height() - 40;
		if(parseInt($("#cont_coleccion .scroll").css("margin-top")) > "-"+hscroll)
			$("#cont_coleccion .scroll").animate({"margin-top":"-=40"},300);
	});
	
	$("#cont_coleccion .btnup").live("click",function(){
		if(parseInt($("#cont_coleccion .scroll").css("margin-top")) < 0)
			$("#cont_coleccion .scroll").animate({"margin-top":"+=40"},300);
			
	});
	
	/* Galeria */
	$("#back_gallery").css("height",(hwin-80)+"px");
	
	/* Footer */
    $("nav li:last").css("border","none");
	
	if($("#wrap_welcome").length){
		centerWelcome();
	}
});

$(window).resize(function(){
	if($("#wrap_welcome").length){
		centerWelcome();
	}
	
	if($("#menu").length > 0){
		centerMenu();
	}
	if($("#content").length > 0){
		centerContent();	
	}
	$("#back_gallery").css("height",(hwin-80)+"px");
});

/* Funciones */
var hwin = 0;
var mtop = 0;
var wwin = 0;
var mleft = 0;
function centerWelcome(){
	hwin = $(window).height();
	mtop = (hwin/2) - (392/2);
	$("#wrap_welcome h1").css("margin-top",mtop);
}

function centerMenu(){
	hwin = $(window).height();
	mtop = ((hwin-190)/2) - (270/2);
	$("#menu").css("top",mtop);
}

function centerContent(){
	hwin = $(window).height();
	mtop = ((hwin-100)/2) - (570/2);
	wwin = $(window).width();
	mleft = (wwin/2) - (800/2);
	$("#content").css({"top":mtop,"left":mleft});
}

function gotoGaleria(){
	$("h2:visible").fadeOut();
	$("#content").html("");
	$("#back_gallery").fadeIn("slow",function(){
		$("#back_gallery").css("height",(hwin-80)+"px");
	});
	$(".flowers").fadeOut();
}

