// JavaScript Document
$(function(){
		
  // Bind the event.
  $(window).bind( 'hashchange', function(){
    updateContent();
  })
  
});

function heartbeat(){
	if($('#content-left-right').height() > $('#content-right').height()){
		var contentright = $('#content-left-right').height() + 40;
	}
	else{
		var contentright = $('#content-right').height();
	}
	
	if(!$.browser.msie){
	  
	  if(contentright<578){
		$('#content-left-left').height(578);
		$('.wrapper').height(578);
	  }
	  else{
		$('#content-left-left').height(contentright-26);
		$('.wrapper').height(contentright-26);
	  }
	}
	else{
	  if(contentright>$('#content-left-left').height()){
		$('#content-left-left').height(contentright+50);
		$('.wrapper').height(contentright+50);
	  }
	}
	if(window.location.hash=="#about-mission"){
	  $('#submenu-mission').html("");
	}
	setTimeout("heartbeat()",1000);	
}

function updateContent(){
	$("#content-left-left").load('menu.php');//load menu first
	
	var pagename = window.location.hash.substr(1).replace('?','.php?');
	var pagename2 = pagename.split('-');
	
	if(pagename.search('.php')==-1){
		pagename = pagename + '.php';
	}
	
	if(window.location.hash == ""){
		$("#content-right-content").load("home.php");
	}
	else{
		$("#content-right-content").load(pagename);
	}
		
	if(pagename2[0] == "about"){
		
		submenu = "about-menu.php";
		$("#about-enderun-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "academics"){
		
		submenu = "academics-menu.php";
		$("#academics-enderun-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "student_engagement"){
		
		submenu = "student_engagement-menu.php";
		$("#student_engagement-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "our_campus"){
		
		submenu = "our_campus-menu.php";
		$("#our_campus-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "admission"){
		
		submenu = "admission-menu.php";
		$("#our_campus-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "international_students"){
		
		submenu = "international_students-menu.php";
		$("#our_campus-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "lifelong_learning"){
		
		submenu = "lifelong_learning-menu.php";
		$("#lifelong_learning-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "application_restaurant"){
		
		submenu = "application_restaurant-menu.php";
		$("#application_restaurant-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "alumni"){
		
		submenu = "alumni-menu.php";
		$("#alumni-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "our_faculty"){
		
		submenu = "our_faculty-menu.php";
		$("#our_faculty-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "news"){
		
		submenu = "news-menu.php";
		$("#news-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "multimedia"){
		
		submenu = "multimedia-menu.php";
		$("#multimedia-btn").css('color','#888');
		
	}
	
	else if(pagename2[0] == "careers"){
		
		submenu = "careers-menu.php";
		$("#careers-btn").css('color','#888');
		
	}
	
	else{
		submenu = "news-events.php";
	}
	$('#content-left-right').load(submenu);
	
}

$(window).ready(function(){
	updateContent();
});

$(document).ready(function(){
	
  heartbeat();

  $("#logo").click(function () {
	  window.location.hash = "home";
	  return false;
  });
  
  $("#language1").click(function () {
	  $.ajax({
		url: 'changelang.php?lang=1',
		async: false
	  })
	  var html = $.ajax({
		url: "header-right.php",
		async: false
	  }).responseText;
	  $('#header-right').html(html);
	  var html = $.ajax({
		url: "menu.php",
		async: false
	  }).responseText;
	  $('#content-left-left').html(html);
	  updateContent();
	  return false;
  });
  $("#language2").click(function () {
	  $.ajax({
		url: 'changelang.php?lang=2',
		async: false
	  })
	  var html = $.ajax({
		url: "header-right.php",
		async: false
	  }).responseText;
	  $('#header-right').html(html);
	  var html = $.ajax({
		url: "menu.php",
		async: false
	  }).responseText;
	  $('#content-left-left').html(html);
	  updateContent();
	  return false;
  });
  $("#language3").click(function () {
	$.ajax({
		url: 'changelang.php?lang=3',
		async: false
	  })
	  var html = $.ajax({
		url: "header-right.php",
		async: false
	  }).responseText;
	  $('#header-right').html(html);
	  var html = $.ajax({
		url: "menu.php",
		async: false
	  }).responseText;
	  $('#content-left-left').html(html);
	  updateContent();
	  return false;
  });
});
