/*
 * Project: Rae Wallace Mining Company
 * Author: Rudy Affandi
 * Created: 02/23/2011
 * File name: functions.js
 */

// Initialize all other javascript functions

// jQuery initialization and CSS settings, waiting for DOM tree to initialize
$(document).ready(function(){
   // Main navigation, please use #nav for your main UL
   sfHover = function() {
      var sfEls = document.getElementById("nav").getElementsByTagName("LI");
      for (var i=0; i<sfEls.length; i++) {
         sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
         }
         sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
         }
      }
   }
   if (window.attachEvent) window.attachEvent("onload", sfHover);
   
   // Button
   $('button').button();

   // Activate "class='active'" on current URL
   var path = location.pathname.substring(1).toLowerCase();
   var filename = path.match(/.*\/([^/]+)\.([^?]+)/i)[1];

   if ( path )
   {
     $('#nav li a[href$="' + path + '"]').addClass('active');
     $('.footer_nav ul li a[href$="' + path + '"]').addClass('active');
     $('.content_side ul li a[href$="' + path + '"]').addClass('active');
   };

   // For URL with parameters
   var path2 = location.search.substring(1).toLowerCase();
   if ( path2 )
   {
     $('#nav li a[href$="' + path2 + '"]').addClass('active');
     $('.footer_nav ul li a[href$="' + path2 + '"]').addClass('active');
     $('.content_side ul li a[href$="' + path2 + '"]').addClass('active');
   };
   
   // Style default RFI form (Experimental)
   // First we clean up the mess from original table formatting
   $('div.form_wrapper table').addClass('ui-helper-reset');
   $('div.form_wrapper table').removeAttr("background");
   $('div.form_wrapper table').removeAttr("border");
   // and then we apply modifier to form elements
   $('div.form_wrapper table input[type=text], div.form_wrapper table td').addClass("ui-corner-all");
   $('div.form_wrapper table input[type=submit], div.form_wrapper table input[type=reset]').button();
   $('div.form_wrapper table textarea').addClass("ui-corner-all");
   $('select, input:checkbox, input:radio, input:file').uniform();

});

// External link warning dialog
function extLink(link) {
   var answer = confirm('You are leaving Rae-Wallace Mining Website')
   if (answer){
      window.location = link;
   }
   else {
      return false;
   }
};

// Fix jQuery rounded corners in IE
$.uicornerfix = function(r){
  DD_roundies.addRule('.ui-corner-all', r);
  DD_roundies.addRule('.ui-corner-top', r+' '+r+' 0 0');
  DD_roundies.addRule('.ui-corner-bottom', '0 0 '+r+' '+r);
  DD_roundies.addRule('.ui-corner-right', '0 '+r+' '+r+' 0');
  DD_roundies.addRule('.ui-corner-left', r+' 0 0 '+r);
  DD_roundies.addRule('.ui-corner-tl', r+' 0 0 0');
  DD_roundies.addRule('.ui-corner-tr', '0 '+r+' 0 0');
  DD_roundies.addRule('.ui-corner-br', '0 0 '+r+' 0');
  DD_roundies.addRule('.ui-corner-bl', '0 0 0 '+r);
};
// Initiate IE rounded corners
$.uicornerfix('4px');
