// javascript for indexical



// initalize tags drop-down.
/*
// used for hover effect, but not necessary.
jQuery(document).ready(function($){
 $(".post-menus li").hover(
  function() { $('ul', this).css('display', 'block'); },
  function() { $('ul', this).css('display', 'none'); });
});
*/



// begin jQuery functions
jQuery(document).ready(function($){



 // these functions are called when each page loads.
 loaddropboxes();
 if (document.getElementById('s')) { loadsearch(); }
 loadcomments();
 checkanchor(); // this was originally called from include-foot.php


 // index of first lines hover
 $(".iofl-line").hover(
  function() {
   $(this).attr({src: $(this).attr("title")});
   $(this).css("height", "520px");
  },
  function() { $(this).css("height", "1px"); });
  
 

});



// initalize drop-down navigation boxes.
function loaddropboxes() {
 var dropboxes = []; // declare array.
 var dropboxestags = document.getElementsByTagName('select'); // check all selects...
 for (var i=0; i<dropboxestags.length; i++) {
  var dropboxestag = dropboxestags[i];
  var classes = dropboxestag.className.split(" "); // ...check for multiple classes...
  for (var j=0; j<classes.length; j++) {
   thisclass = classes[j];
   if (thisclass == "dropbox") { // ...and put any with a class "dropbox" in the array.
    dropboxes.push(dropboxestag);
   }
  }
 }
 // 'numberofdropboxes' is a global variable and is used in other functions.
 numberofdropboxes = dropboxes.length;

 // assign thumb ids and mouse events.
 for(var i=0; i<numberofdropboxes; i++) {
  dropboxes[i].onchange = function() {
   if (this.options[this.selectedIndex].value != '') {
    document.location.href=this.options[this.selectedIndex].value;
   }
  };
 }
}



// initialize search box
function loadsearch() {
 var searchbox = document.getElementById('s');
 searchbox.onclick = function() {
  searchbox.value = '';
  searchbox.style.color = '#222';
 };
 
 searchbox.onblur = function() {
  searchbox.value = 'search';
  searchbox.style.color = '#bbb';
 };
}



// initalize comments.
function loadcomments() {
 var commentareas = []; // declare array.
 var commentareastags = document.getElementsByTagName('div'); // check all divs...
 for (var i=0; i<commentareastags.length; i++) {
  var commentareastag = commentareastags[i];
  var classes = commentareastag.className.split(" "); // ...check for multiple classes...
  for (var j=0; j<classes.length; j++) {
   thisclass = classes[j];
   if (thisclass == "post-comments") { // ...and put any with a class "post-comments" in the array.
    commentareas.push(commentareastag);
   }
  }
 }
 // 'numberofcommentareas' is a global variable and is used in other functions.
 numberofcommentareas = commentareas.length;

 // assign mouse events.
 for(var i=0; i<numberofcommentareas; i++) {
  postid = commentareas[i].id.split("-")[2]; // extract id# from id="post-comments-id#"
  document.getElementById('post-comments-control-'+postid).onclick = function() {
   togglecomments(this.id);
  };
 }
}



// check url anchor; if it points at a comment, toggle the comments area for that comment.
function checkanchor() {
 var url = window.location.href;
 var urlanchor = url.split("#")[1];
 
 if ((typeof(urlanchor) != 'undefined') && (document.getElementById(urlanchor))) {
  postcommentsid = document.getElementById(urlanchor).parentNode.parentNode.id.split("-")[3];
  postcommentscontrolid = 'post-comments-control-' + postcommentsid;
  //alert(postcommentscontrolid);
  togglecomments(postcommentscontrolid);
 }
}



// show or hide a comments area.
function togglecomments(postcommentscontrolid) {
 thispostid = postcommentscontrolid.split("-")[3];
 postcomments = document.getElementById('post-comments-content-'+thispostid);
 postcommentscontrol = document.getElementById('post-comments-control-'+thispostid);
 postcommentscontroltext = document.getElementById('post-comments-control-text-'+thispostid);
 postcomments.style.display = (postcomments.style.display == 'none' || postcomments.style.display == '') ? 'block' : 'none';
 postcommentscontrol.className = (postcommentscontrol.className == 'post-comments-control expand-plus' || postcommentscontrol.className == '') ? 'post-comments-control expand-minus' : 'post-comments-control expand-plus';
 postcommentscontroltext.innerHTML = (postcommentscontroltext.innerHTML == 'hide' || postcommentscontroltext.innerHTML == '') ? 'show' : 'hide';
}



// generates e-mail link, hides address from spammers; linktext is optional.
// <script type="text/javascript">mailto('user','domain.com');</script>
function mailto(user,domain,linktext){
 address = user + '@' + domain;
 if (linktext == undefined) linktext = address;
 document.write('<a href="mailto:' + address + '">' + linktext + '</a>');
}

