var ANIMATION_DURATION_OPEN = 1065;
var ANIMATION_DURATION_CLOSE = 565;
var currentMenuLevelOneOpened = "";

/*
$('#down-small-button').click(function() {
	$.smoothScroll({
	  scrollElement: $('#news-wrapper'),
	  offset: 100
	});
	return false;
});

$('#up-small-button').click(function() {
	$.smoothScroll({
	  scrollElement: $('#news-wrapper'),
	  offset: -100
	});
	return false;
});
*/

//MENU - start
//ANIMATE MENUS - HANDLES ONLY ANIMATION (it is not controller)
function animateWhatHow(inMenuLevelOneCodename, inAnimationDirection) {
	switch (inMenuLevelOneCodename)	{
		//*****************************************************
		case "projects":
			if (inAnimationDirection == "open") { //open
				$('#projects-urban_design-div').css('z-index', '30');
				$("#projects-urban_design-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#projects-gardens-div').css('z-index', '30');
				$("#projects-gardens-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#projects-in_progress-div').css('z-index', '30');
				$("#projects-in_progress-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#projects-urban_design-div').css('z-index', '20');
				$("#projects-urban_design-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#projects-gardens-div').css('z-index', '20');
				$("#projects-gardens-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#projects-in_progress-div').css('z-index', '20');
				$("#projects-in_progress-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************
		//*****************************************************
		case "details":
			if (inAnimationDirection == "open") { //open
				$('#details-details-div').css('z-index', '30');
				$("#details-details-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#details-details-div').css('z-index', '20');
				$("#details-details-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************
		//*****************************************************
		case "products":
			if (inAnimationDirection == "open") { //open
				$('#products-furniture-div').css('z-index', '30');
				$("#products-furniture-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#products-accessories-div').css('z-index', '30');
				$("#products-accessories-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#products-furniture-div').css('z-index', '20');
				$("#products-furniture-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#products-accessories-div').css('z-index', '20');
				$("#products-accessories-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************
		//*****************************************************
		case "research":
			if (inAnimationDirection == "open") { //open
				$('#research-closed-div').css('z-index', '30');
				$("#research-closed-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#research-current-div').css('z-index', '30');
				$("#research-current-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#research-closed-div').css('z-index', '20');
				$("#research-closed-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				$('#research-current-div').css('z-index', '20');
				$("#research-current-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************
		//*****************************************************
		case "news":
			if (inAnimationDirection == "open") { //open
				$('#news-news-div').css('z-index', '30');
				$("#news-news-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#news-news-div').css('z-index', '20');
				$("#news-news-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************		
		//*****************************************************
		case "about":
			if (inAnimationDirection == "open") { //open
				$('#about-about-div').css('z-index', '30');
				$("#about-about-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#about-about-div').css('z-index', '20');
				$("#about-about-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************		
		//*****************************************************
		case "contact":
			if (inAnimationDirection == "open") { //open
				$('#bottom-contact-div').css('z-index', '20');
				$("#bottom-contact-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#bottom-contact-div').css('z-index', '30');
				$("#bottom-contact-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************
		//*****************************************************
		case "legal":
			if (inAnimationDirection == "open") { //open
				$('#bottom-legal-div').css('z-index', '20');
				$("#bottom-legal-div").slideDown({
				duration:ANIMATION_DURATION_OPEN,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			} else { //close
				$('#bottom-legal-div').css('z-index', '30');
				$("#bottom-legal-div").slideUp({
				duration:ANIMATION_DURATION_CLOSE,
				easing:"easeOutSine",
				complete:function(){
				//animation complete
				}
				});
				//*********************************************
			}
			break;
		//*****************************************************
		default:
	}
}

function closeContentDiv() {
	//hide stuff in contact
	/*
	try {
		
	} catch (e) {}
	*/
	
	$('#form1').validationEngine('hideAll');
	
	try	{
		$("#gallery-content-div").fadeOut({
		duration:765,
		easing:"easeOutSine",
		complete:function(){
		}});
	} catch(err) { }
	try	{
		$("#news-content-div").fadeOut({
		duration:765,
		easing:"easeOutSine",
		complete:function(){
		}});
	} catch(err) { }
	try	{
		$("#content-content-div").fadeOut({
		duration:765,
		easing:"easeOutSine",
		complete:function(){
		}});
	} catch(err) { }
	try	{
		$("#list-content-div").fadeOut({
		duration:765,
		easing:"easeOutSine",
		complete:function(){
		}});
	} catch(err) { }
}

//CONTROLLER (what do when it is clicked)
function processMenuLevelOneClick(inMenuLevelOneCodename) {	
	//close the content on click if we are on some content page
	closeContentDiv();		
		
	//on start the clicked one is empty
	if (currentMenuLevelOneOpened == "") {
		animateWhatHow(inMenuLevelOneCodename, "open");
		$("#menu-" + inMenuLevelOneCodename).addClass("opened");	
		currentMenuLevelOneOpened = inMenuLevelOneCodename;
	//if the same on was clicked
	} else if (currentMenuLevelOneOpened == inMenuLevelOneCodename) {
		animateWhatHow(inMenuLevelOneCodename, "close");
		$("#menu-" + inMenuLevelOneCodename).removeClass("opened");
		currentMenuLevelOneOpened = "";
	//if one is already opened
	} else {
		animateWhatHow(currentMenuLevelOneOpened, "close");
		$("#menu-" + currentMenuLevelOneOpened).removeClass("opened");
				
		//setTimeout(function(){animateWhatHow(inMenuLevelOneCodename, "open")},myTimeout);
		
		animateWhatHow(inMenuLevelOneCodename, "open"); //:TODO delay
		$("#menu-" + inMenuLevelOneCodename).addClass("opened");
		currentMenuLevelOneOpened = inMenuLevelOneCodename;
	}			
}
//MENU - over

$(document).ready(function() {
	//LOGO
	//done this way for Google Images indexing
	$('#landscape-logo').hover(function () {
        this.src = '/frontend/images/interface/landscape_logo-hover.png';
    }, function () {
        this.src = '/frontend/images/interface/landscape_logo.png';
    });
	
	
	//CONTACT FORM - TODO
	$("#form1").validationEngine({
	ajaxSubmit: true,
	ajaxSubmitFile: "ajaxSubmit.php",
	ajaxSubmitMessage: "Thank you / Hvala!",
	success :  function() { callSuccessFunction() },
	failure : function() {}
	})
	
	function callSuccessFunction() {
		alert("success");
	}

	//MENU - start	
	//*********************************
	//PROJECTS
	$("#menu-projects").click(function () {
		processMenuLevelOneClick("projects");
	});
	
	//*********************************
	//DETAILS
	$("#menu-details").click(function () {
		processMenuLevelOneClick("details");
	});
	
	//*********************************
	//PRODUCTS
	$("#menu-products").click(function () {
		processMenuLevelOneClick("products");
	});

	//*********************************
	//RESEARCH
	$("#menu-research").click(function () {
		processMenuLevelOneClick("research");
	});
	
	//*********************************
	//NEWS
	$("#menu-news").click(function () {
		processMenuLevelOneClick("news");
	});
	
	//*********************************
	//NEWS
	$("#menu-about").click(function () {
		processMenuLevelOneClick("about");
	});
	
	//*********************************************
	// FOOTER
	//*********************************************
	
	//LEGAL
	$("#menu-legal").click(function () {
		processMenuLevelOneClick("legal");
	});
	
	//CONTACT
	$("#menu-contact").click(function () {
		/* GOOGLE MAPS FIX */
		$("#bottom-contact-div").addClass("bottom-contact-div-reposition");
		processMenuLevelOneClick("contact");
	});
	//MENU - end
	
});
