﻿var home = {
	
	currentId:null,
	oldId:null,
	slideTimer:null,
	currentLogId:null,
	logInterval:null,
	
	init : function(){
		currentId = 0;
		$("#home_column_two img.rollLogo").css("display", "none");
		$("#home_column_two img.logo").css("display", "none");
		
		currentLogId = 0;
		$("#home_column_two img.logo:eq("+currentLogId+")").css("display", "block");
		$("#home_column_two img.logo:eq("+currentLogId+")").css("top", 0);
		
		$("#home_column_two a.logos").hover(home.rollLogoAppear, home.rollLogoDisappear);
		
		$(".text img:eq("+currentId+")").css("display", "block");
		$(".images img:eq("+currentId+")").css("display", "block");
		$(".slideNavigation a:eq("+currentId+")").css("color", "#efede3");
		$(".slideNavigation a").each(function(i) {
			$(this).bind("click", i, home.clickSlideShow);
			$(this).hover(home.stopTimer, home.restartTimer);
		});
		oldId = currentId;
		slideTimer = setInterval(home.increaseSlideShow, 8000);
		
		logInterval = setInterval(home.logSlideShow, 8000);
	},
	
	clickSlideShow : function(e) {
		e.preventDefault();
		clearInterval(slideTimer);
		home.changeSlideShow(e.data);
	},
	
	increaseSlideShow : function() {
		currentId++;
		if(currentId == $(".slideNavigation a").length) currentId = 0;
		home.changeSlideShow(currentId);
	},
	
	changeSlideShow : function(id) {
		currentId = id;
		$(".images img:eq("+oldId+")").fadeOut("slow");
		$(".text img:eq("+oldId+")").animate({opacity : 1}, 300).fadeOut("slow", home.showNewImage);
	},
	
	showNewImage : function() {
		$(".images img:eq("+currentId+")").fadeIn("slow");
		$(".text img:eq("+currentId+")").animate({opacity : 1}, 300).fadeIn("slow");
		$(".slideNavigation a:eq("+oldId+")").css("color", "#805751");
		$(".slideNavigation a:eq("+currentId+")").css("color", "#efede3");		
		oldId = currentId;
	},
	
	stopTimer : function(e) {
		clearInterval(slideTimer);
	},
	
	restartTimer : function(e) {
		slideTimer = setInterval(home.increaseSlideShow, 8000);
	},
	
	rollLogoAppear : function(e) {
		$("#home_column_two img.rollLogo").fadeIn("fast");
		$("#home_column_two p").fadeTo("fast", .5);
	},
	
	rollLogoDisappear : function(e) {
		$("#home_column_two img.rollLogo").fadeOut("fast");
		$("#home_column_two p").fadeTo("fast", 1);
	},
	
	logSlideShow : function() {
		$("#home_column_two p img:eq("+currentLogId+")").fadeOut("slow", home.showNextLogos);
	},
	
	showNextLogos : function() {
		currentLogId++;
		
		if(currentLogId >= $("#home_column_two p img").length) currentLogId = 0;
		
		var currLogo = $("#home_column_two p img:eq("+currentLogId+")");
		$(currLogo).fadeIn("slow");
	}
	
}

jQuery(document).ready(function() { home.init(); })