$(document).ready(function(){
  if ($("span.main_nav_item").parent().is('.active')){
    $(".active").children("ul").css("visibility", "visible")
  }
  $("ul#navigation_ul li").hover(function(){
    $(this).children("ul").css("visibility", "visible")
  }, function(){
    if (!$(this).is('.active')) {
      $(this).children("ul").css("visibility", "hidden")
    }
  });
	$("#dropdown").animate({
    top: '-350px'
  }, 1500);
	$("#dropdown").animate({
    top: '-390px'
  }, 1500);
	var dropdown_state = 'closed';
	var dropdown_page = null;
	$(".dropdown_localisation").removeAttr("href");
	$(".dropdown_localisation").css("cursor", "pointer");
  $("#dropdown_el").click(function(){
    lang = "el"
  $("div#dropdown_content").load("pages/" + lang + "/" + dropdown_page + ".php")
  })
  $("#dropdown_en").click(function(){
    lang = "en"
    $("div#dropdown_content").load("pages/" + lang + "/" + dropdown_page + ".php")
  })
	$("#atrium").click(function(){
		if (dropdown_page == 'atrium') {
			$("#dropdown_close").click();
			dropdown_page = null;
			dropdown_state = 'closed'
		}	else {
			dropdown_page = 'atrium'
			if (dropdown_state == 'closed') {
				$("#dropdown").animate({
					top: 0
				}, 1000);
				dropdown_state = 'open'
			}
			$("#dropdown_content").load("pages/" + lang + "/atrium.php");
    }
  });
	$("span#bioclimatics").click(function(){
    if (dropdown_page == 'bioclimatic') {
      $("#dropdown_close").click();
      dropdown_page = null;
      dropdown_state = 'closed'
    } else {
      dropdown_page = 'bioclimatic'
      if (dropdown_state == 'closed') {
        $("#dropdown").animate({
          top: 0
        }, 1000);
        dropdown_state = 'open'
      }
      $("#dropdown_content").load("pages/" + lang + "/bioclimatic.php");
    }
  });
	$("#dropdown_close").click(function(){
		$("#dropdown").animate({
        top: '-390px'
      }, 1000, function(){$("#dropdown_content").html('');});
      dropdown_state = 'closed'
	})
	$("body").click(function(){
    $("#dropdown_close").click();
    dropdown_page = null;
    dropdown_state = 'closed';
  })
  $('#dropdown').click(function(event){
    event.stopPropagation();
  });
	$("li.active").css("background", "#00aa00")
	$('li.active').append('<img id="nav_flip" src="img/assets/nav_flip.png" />');
	if (loc == 'gallery') {
  	$("a[rel^='prettyPhoto']").prettyPhoto({
  		theme: 'dark_rounded',
  		slideshow: 5000,
  		autoplay_slideshow: false
  	});
  };
	if (loc == "contact"){
		initialize();
  }
  $('a[rel*=external]').click( function() {
    window.open(this.href);
    return false;
  });
  if (loc == 'atrium'){
    $("span#atrium").click()
    loc == 'index'
  }
  if (loc == 'bioclimatics'){
    $("span#bioclimatics").click()
    loc == 'index'
  }
  $("#bioclimatics-button").click(function(event){
    event.stopPropagation();
    $("span#bioclimatics").click()
  })
  $("#atriums-button").click(function(event){
    event.stopPropagation();
    $("span#atrium").click()
  })
});
