﻿var contact = {
	
	init : function() {
		$("table.contact td").hover(contact.rollContact, contact.unRollContact);
		$("table.contact td").click(contact.clickContact);
	},
	
	rollContact : function(e) {
		$(e.target).parent().css("background-color", "#d7d5c6");
	},
	
	unRollContact : function(e) { 
		var col = $(e.target).parent().hasClass("bg1") ? "#f6f4ec" : "#edebe1";
		$(e.target).parent().css("background-color", col);
	},
	
	clickContact : function(e) {
		var goodTag = contact.chooseGoodTag("tr", e.target);
		window.location = $(goodTag).attr("rel");
	},
	
	chooseGoodTag : function(tagName, ctx) {
		i = 0;
		while(ctx.tagName != tagName.toUpperCase()) {
			ctx = ctx.parentNode;
			i++;
			if(i > 5) break;
		}
		return ctx;
	}
	
}



var home = {
	
	currentId:null,
	oldId:null,
	slideTimer:null,
	
	init : function(){
		currentId = 0;
		
		$(".contgall img:eq("+currentId+")").css("display", "block");
		
		oldId = currentId;
		if($(".contgall img").length < 2) return;
		slideTimer = setInterval(home.increaseSlideShow, 5000);
		
		$(".Map3").each(function(i) {
			$(this).bind("click", i, home.stopTimer);
		});
		
		$(".Map4").each(function(i) {
			$(this).bind("click", i, home.restartTimer);
		});
	},
	
	
	increaseSlideShow : function() {
		currentId++;
		if(currentId == $(".contgall img").length) currentId = 0;
		home.changeSlideShow(currentId);
	},
	
	changeSlideShow : function(id) {
		currentId = id;
		$(".contgall img:eq("+oldId+")").fadeOut("slow", home.showNewImage);
	},
	
	showNewImage : function() {
		$(".contgall img:eq("+currentId+")").fadeIn("slow");
		oldId = currentId;
	},
	
	stopTimer : function(e) {
		clearInterval(slideTimer);
	},
	
	restartTimer : function(e) {
		clearInterval(slideTimer);
		slideTimer = setInterval(home.increaseSlideShow, 5000);
	}
	
	
}


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