var homepageLoader = {
	itemArr : null,
	imageArr: null,
	current_img: 0,
	total_imgs: null,
	interval: null,
	timeOut: 3000,
	autoplay: true,
	
	init: function() {
		$('#banner .banner_item').hide();
		$('#banner .banner_item:first-child').show();
		$('#three_features .single_img_col img, #three_features .single_img_col .nkp_txtblock, #three_features .text_col, #three_features .text_col h1, #three_features .text_col .copy_wrap').hide();
		//$('#three_features .single_img_col img, #three_features .single_img_col .nkp_txtblock').hide();
		$('#three_features').addClass('loader');
		this.imageArr = $("#banner .banner_item");
		this.total_imgs = this.imageArr.length - 1;
		this.setIndexes();
		//this.showCount();
		var _this = this;
		if(this.autoplay == true && this.total_imgs > 0){
			this.interval = setInterval(function() { _this.showNext(); }, _this.timeOut);
		}
	},
	setIndexes: function() {
		for(var i=0; i < this.imageArr.length; i++) {
			$(this.imageArr[i]).css("z-index", this.imageArr.length - i).css('opacity', 0).filter(":first").css('opacity', 1.0);
		}
	},
	showNext: function() {
		if(this.current_img < this.total_imgs) {
			// show next image behind
			$(this.imageArr[this.current_img + 1]).css('opacity', 1.0).css('display', 'block');
			// fade out current image
			$(this.imageArr[this.current_img]).fadeOut(1000);
			// increment counter
			this.current_img++;
		} else {
			// load next step of sequence
			this.stepTwo();
			clearInterval(this.interval);
		}
	},
	stepTwo : function(){
		
		$('#three_features .single_img_col').css('opacity', 0);
		this.itemArr = $('#three_features.loader .single_img_col');
		this.hideBanners();
	},
	
	hideBanners : function(){
		var _this = this;
		$("#banner").fadeOut(1000);
		this.showContent();
	},
	showContent : function(){
		var _this = this;
		$(this.itemArr[0]).animate({ opacity: 1.0, height: "358px", left : "0", top : "0" }, 1000, "easeInOutBack", 
		function(){
			$(this).animate({ width: "460px" }, "easeOutBack", function(){
				$('img', this).fadeIn(500, function(){
					$('.text_col').fadeIn(200, function(){ 
						$('.text_col h1').fadeIn(500, function(){
							$('.text_col .copy_wrap').fadeIn(500, function(){
								$('#three_features .single_img_col .nkp_txtblock').fadeIn(1200, function(){
									$(this).fadeOut(1300);
								});
								nkpInteractive.singleTextBlock();
							});
							
						});
					});
					$('#three_features').removeClass('loader');
					$('#three_features .single_img_col').attr('style','');
					$('#page').addClass('projects');
				});
			});
		});
	},
	homepageViewed : function(){
		nkpInteractive.singleTextBlock();
		$('#page').addClass('projects');
		$("#banner").hide();
	}
};

//DOM ready Events
$(function() {
	
	var c1 = readCookie("nkp_visited");
	
	if(!c1){
		homepageLoader.init();
		createCookie("nkp_visited", "true", 30);
	} else if(c1) {
		homepageLoader.homepageViewed();
		eraseCookie("nkp_visited");
	}
	
});
