	
	Corpory = function(){
		
		var sliders = $("div.slider");
		var items = sliders.find("a.item");
		
		var winW = $(window).width();
		var winH = $(window).height();
		var pageBlocks = $("div.page-block");

		if($("body#page-home").length){

			pageBlocks.eq(0).css({
				left: - winW + "px",
				width: winW + "px"
			});
			pageBlocks.eq(1).css({
				left: "0",
				width: winW + "px"
			});
			pageBlocks.eq(2).css({
				left: winW + "px",
				width: winW + "px"
			});
			
			$("div.sidebar").css("margin-top", "60px");
			
			if (document.all) 
				$("html, body").css("overflow", "hidden");
			
			var choose = $("#home div.choose");
			choose.hover(function(){
				//choose.addClass("choose-no-line");	
			}, function(){
				//choose.removeClass("choose-no-line");
			}).find("a").click(function(){
				var a = this;
				if($(this).parents("div.below-the-line").length){
					pageBlocks.filter(":eq(0),:eq(1)").animate({
						marginLeft: winW
					}, 1000, function(){
						$("body").addClass("preload1");
						setTimeout(function(){
							window.location = a.href;
						}, 1000);
					});
				}else{
					pageBlocks.filter(":eq(1),:eq(2)").animate({
						marginLeft: - winW
					}, 1000, function(){
						$("body").addClass("preload2");
						setTimeout(function(){
							window.location = a.href;
						}, 1000);
					});
				}
				return false;
			});
		
		}
		
		$("div.page-block-inner").css({
			//width: winW + "px",
			height: winH + "px"
		});
		
		var links = $("div.menu div.links");

		if(window.location.toString().match(/below/)){
			$("#inner div.sidebar").css({
				height: (winH - $("div.top").height() - 15 - parseInt($("div.top").css("margin-bottom"))) + "px"
			})
			$("#sidebar a").click(function(){
				var a = this;
				$("#wraper div.footer").css({
					position: "absolute"
				});
				$("#inner").css({
					width: winW + "px",
					height: winH + "px"
				})
				$("#wraper,#social").animate({
					marginLeft: - winW + 215
				}, 1000, function(){
					window.location = a.href;
				});
				$("#top-date a").animate({
					right: $(window).width() - 208
				}, 700, function(){});
				setTimeout(function(){
					$("#top-date div.date").animate({
						right: $(window).width() - 91
					}, 700, function(){});
				}, 200);
				return false;
			});
			$("#social").css({
				left: winW + "px"
			});
			links.css();
			//Utils.loadVideo("http://dev-warmup.sytes.net/~jplozano/corpory.es/beta2/below.php");
		}
		
		if(window.location.toString().match(/social/)){
			$("#inner div.sidebar").css({
				height: (winH - $("div.top").height() - 15 - parseInt($("div.top").css("margin-bottom"))) + "px"
			})
			$("#sidebar a").click(function(){
				var a = this;
				$("#wraper div.footer").css({
					position: "absolute"
				});
				$("#inner").css({
					width: winW + "px",
					height: winH + "px"
				})
				$("#wraper,#below").animate({
					marginLeft: winW - 218
				}, 1000, function(){
					window.location = a.href;
				});
				$("div.search").fadeOut();
				$("#top-date a").animate({
					left: $(window).width() - 208
				}, 700, function(){});
				setTimeout(function(){
					$("#top-date div.date").animate({
						left: $(window).width() - 91
					}, 700, function(){});
				}, 200);
				return false;
			});
			$("#below").css({
				left: - winW + "px"
			});
			//$("div.content div.content-left").height($("div.content div.content-right").height());
			var homeStoryDiv = $("#home-story");
			var homeStories = homeStoryDiv.find("div.story-extended");
				homeStories.eq(0).show().addClass("active");
			var count = homeStories.length;
			homeStoryDiv.find("a.arrow").click(function(){
					var current = homeStories.filter(".active");
					var index = homeStories.index(current);
					var isLeft = $(this).hasClass("arrow-left");
					if(isLeft){
						if(index == 0) return false;
						current.hide().removeClass("active").prev().fadeIn().addClass("active");
					}else{
						if(index == count - 1) return false;
						current.hide().removeClass("active").next().fadeIn().addClass("active");
					}
					return false;
				});
			links.css({marginLeft: - ((links.width() / 2) - 40) + "px"});
			$("div.search").fadeIn(1000);
		}

		//$("#social div.content-inner").height($(window).height() - 210);
		//$("#below div.content-inner").height($(window).height() - 240);
		//$("#social div.content-inner").height($(window).height() - $("div.links").height() - $("div.top").height() - parseInt($("div.top").css("margin-bottom")) - parseInt($("div.links").css("margin-bottom")));
		//$("#below div.content-inner").height($(window).height() - $("div.links").height() - $("div.top").height() - parseInt($("div.top").css("margin-bottom")) - parseInt($("div.links").css("margin-bottom")));
		
		/*setTimeout(function(){
			$('div.content-inner').jScrollPane({
				bottomCapHeight: 60
			})
		}, 200);*/
		
		//if($("div.contacto").length){
			$("form#contactform").validate({
				errorElement: "div",
				errorClass: "f-error",
				messages:{
					required: "Este campo es requerido",
					email: "Escriba un email valido"
				},
				debug: false,
				submitHandler: function(form){
					$(form).find("button").hide().after("Enviando...")
					$.ajax({
						type: "POST",
						dataType: "text",
						url: "x.php?do=contacto",
						data: $(form).serialize(),
						success: function(data){
							$("form#contactform").hide().prev().html(data).fadeIn();
						}
					});
					return false;
				}
			})
		//}
		
		$("div.story").each(function(){
			var t = $(this).find("img:first");
			var img = t.clone();
			img.attr("src", base + "libs/image.php?w=450&h=180&name=" + img.attr("src").replace(base, ""));
			var divimg = $(this).find("div.img").append(img)
			var html = divimg.html().replace(/(width\=\"[0-9]+\")/g, "");
				html = html.replace(/(height\=\"[0-9]+\")/g, "");
			divimg.html(html);
		});
		$("div.story-extended").each(function(){
			var img = $(this).find("img:first");
			$(this).find("div.img").append(img.clone());
		});
		
		$("#top-date a").click(function(){
			var obj = this;
			var pos = $(this).findPos();
			var div = $("#suscribe-popup");
			var posIt = function(){
				$("#suscribe-popup").css({
					left: pos.x + "px",
					top: pos.y + ($.browser.msie ? 28 : 30) + "px"
				});
			}
			var hit = function(){		
				Utils.hitTest(obj, "#suscribe-popup", function(){
					$("#suscribe-popup").slideUp("fast");
				}, function(){});
			}
			if(div.length){
				div.slideDown("fast").find("input").trigger("focus");
				posIt();
				return false;
			}
			var html = $("<div id='suscribe-popup'><div><span></span><form><label>Escribe tu email:<input type='text' name='email' /><button type='submit'>Enviar</button></label></form></div></div>");
			html.appendTo("body").find("form").submit(function(){
				var form = this;
				var input = $(form).find("input");
				var msg = $("#suscribe-popup").find("span");
				if(!input.val()){		
					input.trigger("focus");
					return false;
				}
				$(form).hide();
				msg.html("Enviando...");
				$.ajax({
					type: "POST",
					dataType: "text",
					url: "x.php?do=suscribe",
					data: $(this).serialize(),
					success: function(data){
						msg.html(data);
					}
				});
				return false;
			});
			posIt();
			hit();
			html.slideDown("fast", function(){
				$(this).find("input").trigger("focus")
			});
			return false;
		});
		
	}
	
	var Utils = {
		
		Filestyle: function(){
			$("input[type=file]").filestyle({
				image: "images/browse.gif",
				imageheight: 22,
				imagewidth: 20,
				width: 200
			});
		},
	
		get: function(action, response){
			$.ajax({
				url: action.match(/^http\:\/\//) ? action : "core/controller.php?do=" + action, type: "GET",
				data: "",
				success: function(data){
					if(data.charAt(0) == "{"){
						data = $.evalJSON(data);
					}
					response(data);
				}
			});
		},
		
		post: function(action, pars, response){
			$.ajax({
				url: action.match(/^http\:\/\//) ? action : "core/controller.php?do=" + action, type: "POST",
				data: pars,
				success: function(data){
					if(data.charAt(0) == "{")
						data = $.evalJSON(data);
					response(data);
				}
			});
		},
		
		escapeContent: function(string){
			return encodeURIComponent(string)
       		.replace(/\+/g, '%2B')
          	.replace(/\"/g,'%22')
            .replace(/\'/g, '%27');
		},
		
		loadImg: function(string){
			var _ = this;
			//var bigUrl = _.url.replace("resize2/", "").replace(".jpg", ".JPG");
			var a = $("<a href='"+_.url+"' title='"+_.obj.attr("title")+"' rel='gal'></a>").appendTo(_.content).fancybox({
				'overlayShow'	:	true,
				'hideOnContentClick': true,
				'transitionIn'	:	'elastic'
			});
			
			$("<img src='"+THUMB+"/"+_.url+"' />").prependTo(a).hide().load(function(){
				_.obj.removeClass("loading");
				$(this).fadeIn("slow", function(){
					Corpory.ieFix();
					_.showCaption();
				});
			});
		},
		
		loadVideo: function(url){
			var flashvars = {
				autostart: "true",
				backcolor: "ffffff",
				frontcolor: "333333",
				file: url,
				stretching: "fill"
			};
			var params = {
				allowfullscreen: "true", 
				allowscriptaccess: "always",
				wmode: "opaque"
			};
			var attributes = {};
			swfobject.embedSWF('libs/mediaplayer-viral/player-viral.swf', 'video', '100%', '400', '9', "js/swfobject/expressInstall.swf", flashvars, params, attributes);
		},
		
		hitTest: function(z, c, a, b) {
		    $("body").bind("click", function (f) {
		        var d = $(f.target);
		        if (!(d.is(c) || d.parents().is(c) || d.parent()[0] == $(z).parent()[0])) {
		            a(c)
		        } else {
		            b(c)
		        }
		    })
		}
		
	}
	
	var Corpory;
	$(document).ready(function(){
		Corpory = new Corpory;
	});

