var Slideshow = {
	
	numberOfSlides: 4,
	currentSlide: 0,
	slideWidth: 0,
	slideHeight: 0,
	textVisible: true,
	
	initialize: function() {
		$("#loading").fadeOut(250);
		$("#slider").fadeIn(250);
	},
	
	resize: function() {
		var windowWidth = $(window).width();
		var windowHeight = $(window).height();
		var slideHeight = this.slideHeight = windowHeight - 252;
		var slideWidth = this.slideWidth = slideHeight * 1.5;
		var leftContHeight = this.leftContHeight = windowHeight - 952;
		var leftContWidth =  this.leftContWidth = leftContHeight * 1.5;
		var slideshowWidth = this.numberOfSlides * slideWidth;
		var buttonHeight = this.slideHeight - 8;
		$("#slider").css("width", windowWidth +"px");				
		if (windowHeight>834) {
			$(".slide").css("width", 900+"px").css("height",672+"px");
			$("#leftCont").css("width", 220+"px").css("height",432+"px");
			$(".slide img").css("width", 900+"px").css("height",600+"px");
			$(".descStrip").css("width", 900+"px");
			//$("#interesadoStrip").css("top",141+600+72+"px");
			//$("#footer").css("top",141+600+72+"px");
			$("#siguienteBtn").css("top",141+600+18-15+"px");
			$("#atrasBtn").css("top",141+600+18-10+"px");
		}
		if (windowHeight<834) {		
			$("#slider").css("height", slideHeight+72+"px");
			$(".slide").css("width", slideWidth+"px").css("height",slideHeight+72+"px");
			$("#leftCont").css("width", leftContWidth+"px").css("height",leftContHeight+32+"px");
			$(".slide img").css("width", slideWidth+"px").css("height",slideHeight+"px");
			$(".descStrip").css("width",slideWidth+"px");
			//$("#interesadoStrip").css("top",141+slideHeight+72+"px");
			//$("#footer").css("top",141+slideHeight+72+"px");
			$("#siguienteBtn").css("top",141+slideHeight+18-15+"px");
			$("#atrasBtn").css("top",141+slideHeight+18-10+"px");
		}
		/*$("#slideshow-items").css("width", slideshowWidth+"px");
		$("#slideshow-items h2, #slideshow-items p.subtitle").each(function(){
			$(this).css("width", (slideWidth-8)+"px");
		});
		$("#slideshow-items img, #slideshow-items object").each(function(){
			$(this).css("height", slideHeight+"px").css("width", slideWidth+"px");
		});
		$("#slideshow-items ul").css("left", this.calculatePosition());
		$("#slideshow-navigation li a").each(function(){
			$(this).css("height", buttonHeight+"px");
		});
		
		// text max height = windowHeight - 32
		var originalHeight = $("#text").attr("original-height");
		// if (windowHeight - 32 < originalHeight) {
		// 	$("#text").css("height", (windowHeight - 32)+"px");
		// } else {
		// 	$("#text").css("height", "auto");
		// }
		if (windowHeight - 56 < originalHeight) {
			$("#text").css("height", (windowHeight - 56)+"px");
		} else {
			$("#text").css("height", "auto");
		}*/
		
	},
	
	next: function() {
//		this.show(this.currentSlide + 1);		
	},
	
	prev: function() {
//		this.show(this.currentSlide - 1);
	},
	
	calculatePosition: function() {
		var windowWidth = $(window).width();
		if (windowWidth > this.numberOfSlides * this.slideWidth) {
			return 0;
		} else {
			var newPosition = this.currentSlide * this.slideWidth + 20;
			return -newPosition;
			/*var newPosition = this.currentSlide * this.slideWidth;
			var itemsLeft = this.numberOfSlides - this.currentSlide - 1;
			var whiteSpace = windowWidth - this.slideWidth - (itemsLeft * this.slideWidth);
			if (whiteSpace > 0) {
				return -(newPosition - whiteSpace);
			} else {
				return -newPosition;
			}*/
		}
	},
	
	show: function(num) {
		if (num >= this.numberOfSlides) num = this.numberOfSlides - 1;
		if (num < 0) num = 0;
		if (num != this.currentSlide) {
			this.currentSlide = num;
			//this.currentSlide > 0 ? $("#slideshow-navigation .left").show() : $("#slideshow-navigation .left").hide();
			//this.currentSlide < this.numberOfSlides - 1 ? $("#slideshow-navigation .right").show() : $("#slideshow-navigation .right").hide();
			var newPosition = this.calculatePosition();
			//$("#slider").animate({left:newPosition+50},250);
			
		}
	},
	
	toggleText: function() {
		if (this.textVisible) {
			// $("#text").slideUp(250);
			$("#text").animate({height:'hide', opacity:0.3}, 250);
			this.textVisible = false;
			$("#text-nav").attr("class", "open");
		} else {
			$("#text").animate({height:'show', opacity:1}, 250);
			// $("#text").slideDown(250);
			this.textVisible = true;
			$("#text-nav").attr("class", "close");
		}
	}
	
};

$(window).resize(function(){
	Slideshow.resize();
});
$(window).load(function(){
	Slideshow.resize();
	Slideshow.initialize();
});
