var vw = 0; var vh = 0;
$(document).ready(function() {
	/*correct background according to screen resolution*/
	var sw = screen.width; var bgide = "big";
	if (sw <= 1440) { bgide = "medium"; }
	if (sw <= 1020) { bgide = "small"; }
	if (sw <= 800) { bgide = "tiny"; }
	$("body").css({ "background-image" : "url(" + rel + "assets/items/bg/bg_" + bgide + ".jpg)" });
	/*transluscent background for content*/
	$("#contenido>*").css({ "position" : "relative", "z-index" : "1" });
	$("#contenido").css({ "background-color" : "transparent", "position" : "relative" }).prepend("<div id='bg'></div>");
	$("#bg").css({
		"width" : "100%",
		"height" : "100%",
		"background-color" : "#FFFFFF",
		"opacity" : ".8",
		"position" : "absolute",
		"top" : "0",
		"right" : "0",
		"bottom" : "0",
		"left" : "0",
		"z-index" : "0"
	});
	/*contacto*/
	$("#menu>menu").append("<li><a id='botoncontacto'>Contacto</a></li>");
	$("#contacto>form").hide();
	$("#botoncontacto").css({ "cursor" : "pointer" }).toggle(function() {
		$("#contacto>form").slideDown(800, "easeOutCubic");
	}, function() {
		$("#contacto>form").slideUp(800, "easeOutSine");
	});	
	/*layout*/
	$("#contenido").css({
		"width" : "16%",
		"float" : "left"
	});
	$("#main").append("<div id='subcontenido'><div class='bg'></div><div class='content'></div></div>");
	$("#subcontenido").css({
		"width" : "40%",
		"height" : "auto",
		"margin-right" : "4%",
		"padding" : "0 2%",
		"float" : "left",
		"position" : "relative"
	});
	$("#subcontenido>.content").css({ "position" : "relative", "z-index" : "1" });
	$(".bg").css({
		"width" : "100%",
		"height" : "100%",
		"background-color" : "#FFFFFF",
		"opacity" : ".8",
		"position" : "absolute",
		"top" : "0",
		"right" : "0",
		"bottom" : "0",
		"left" : "0",
		"z-index" : "0"
	});
	$(".subcontent>*:not(h2)").hide();
	$("#contenido .subcontent>h2").css({
		"width" : "90%",
		"margin-left" : "10%",
		"font-size" : "17px",
		"font-weight" : "normal",
		"cursor" : "pointer"
	}).prepend("<span>+&nbsp;</span>").click(function() {
		var $this = $(this);
		var ide = $(".subcontent>h2").index($this);
		if ($this.attr("rel") == "notselected") {
			$("#contenido .subcontent>h2").css({ "color" : "#00599D", "font-weight" : "normal" }).attr("rel", "notselected").find("span").html("+&nbsp;");
			$("#subcontenido>.content>*").remove();
			$this.css({ "color" : "#000000", "font-weight" : "bold" }).attr("rel", "selected").find("span").html("-&nbsp;");
			$(".subcontent:eq(" + ide + ")>*:not(h2)").clone().appendTo($("#subcontenido>.content"));
			$("#subcontenido>.content").css({ "padding" : "25px 0" });
			$("#subcontenido>.content>*").hide().fadeIn("fast");
		} else {
			$this.css({ "color" : "#00599D", "font-weight" : "normal" }).attr("rel", "notselected").find("span").html("+&nbsp;");
			$("#subcontenido>.content>*").fadeOut("fast", function() {
				$("#subcontenido>.content").css({ "padding" : "0" });
				$("#subcontenido>.content>*").remove();
			});	
		}
	}).attr("rel", "notselected");
	/*direcciones*/
	$("#direcciones").prepend("<h2>Nuestras Ubicaciones</h2>");
	$("#direcciones>h2").css({
		"margin-bottom" : "10px",
		"color" : "#E6E7E8",
		"font-size" : "15px"
	});
	$("address>ul").hide();
	$("address>h2").prepend("<span>+ </span>").css({ "cursor" : "pointer" }).toggle(function() {
		$(this).parent().find("ul").slideDown(400, "easeOutCubic");
		$(this).find("span").html("- ");
	}, function() {
		$(this).parent().find("ul").slideUp(400, "easeOutSine");
		$(this).find("span").html("+ ");
	});
	/*var mh = $("#menu").height();
	var ch = $("#content").height();
	if (mh > ch) {
		$("#content").css({ "height" : ((mh - 48) + "px") });
	} else {
		$("#menu").css({ "height" : (ch + "px") });
		//alert($("#menu").height());
	}*/
	/*Menú principal expandible*/
	$("#menu").css({ "position" : "relative" }).append("<img id='menucontrol' src='" + rel + "assets/items/botones/boton_menu_adentro.gif' />");
	$("#menucontrol").css({
		"width" : "8%",
		"height" : "auto",
		"position" : "absolute",
		"top" : "0",
		"right" : "0",
		"cursor" : "pointer"
	}).toggle(function() {
		/*hacia adentro*/	
		$(this).attr("src", rel + "assets/items/botones/boton_menu_afuera.gif");
		$("#menu").animate({ 
			"left" : "-22%"
		}, 400, "easeOutCubic");
	}, function() {
		/*hacia afuera*/	
		$(this).attr("src", rel + "assets/items/botones/boton_menu_adentro.gif");
		$("#menu").animate({ 
			"left" : "0"
		}, 400, "easeOutCubic");
	});
	/*video background*/
	switch (bgide) {
		case "tiny" : vw = 800; vh = 458; break;
		case "small" : vw = 1020; vh = 584; break;
		case "medium" : vw = 1440; vh = 825; break;
		case "big" : vw = 1920; vh = 1100; break;
	}
	$("#wrapper").css({
		"position" : "relative", 
		"z-index" : "1",
		"overflow" : "hidden"
	});
	$("body").prepend("<div id='bgvideo'></div>");
	var ow = ($("body").width() - vw) * .5;
	$("#bgvideo").css({
		"width" : (vw + "px"),
		"height" : (vh + "px"),
		"position" : "fixed",
		"left" : (ow + "px"),
		"bottom" : "0",
		"z-index" : "0"
	});
	$(window).resize(function() {
		ow = ($("body").width() - vw) * .5;
		$("#bgvideo").css({ "left" : (ow + "px") });
	});
	if ($.browser.msie && (($.browser.version.slice(0,3)) * 1) < 10) { /*Si es internet explorer <= 8.0*/
		var ievideosrc = rel + "assets/items/videos/bg_flash.swf";
		var ievideo = "<object id='flavideo' name='flavideo' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='" + vw + "' height='" + vh + "'><param name='movie' value='" + ievideosrc + "' /><param name='wmode' value='transparent' /><param name='allowScriptAccess' value='always' /><param name='quality' value='high' /><param name='swfversion' value='9.0.45.0' /></object>";
		$("#bgvideo").append(ievideo);	
	} else { /*NO IE*/
		$("#bgvideo").append("<video id='bgvideo_movie' autoplay loop></video>");
		$("#bgvideo_movie").attr("width", vw);
		$("#bgvideo_movie").attr("height", vh);
		var videosrc = rel + "assets/items/videos/bg_" + bgide;
		var type = "";
		if ($.browser.mozilla || $.browser.opera) { /*Si es Firefox u Opera*/
			videosrc += ".ogv"; type = 'video/ogg';
			$("#bgvideo_movie").append("<source src='" + videosrc + "' type='" + type + "' />");
		} else { /*Todos los demás*/
			videosrc += ".mp4";
			$("#bgvideo_movie").append("<source src='" + videosrc + "' type='video/mp4' />");
		}
	}	
});
function sendToActionScript(value) { document["flavideo"].sendToActionScript(value); }
function fromActionScript() { sendToActionScript(vw + "_" + vh); }
