/*
 * This file is for adding the Image Slide Show on the home page.
 * This SlideShow is of size 690 X 258 
 */ 

function image_slideshow() {
    var $active = $('#home-slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#home-slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#home-slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "image_slideshow()", 5000 );
});


/*
 * This file is for adding the Image Slide Show on all general pages.
 * This SlideShow is of size 428 X 224 
 */ 
function small_slideshow() {
    var $active = $('#small-image-slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#small-image-slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#small-image-slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "small_slideshow()", 5000 );
});


/*
 * This file is for adding the fast facts scroller on the home page.
 */ 
function slideSwitch() {
    var $active = $('#ff-home-text DIV.active');

    if ( $active.length == 0 ) $active = $('#ff-home-text DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#ff-home-text DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({left: 560})
        .addClass('active')
        .animate({left: 18}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 7000 );
});


/*
 * This function is used in the Team page template to
 * highlight the selected member. 
 */
function highlight_this($divid,$total){
  var $i = 0;
  var $div = '';

  for($i=1;$i <= $total;$i++){
    $div = 'm'+$i;
    var obj = document.getElementById($div);
    if (obj){
      if($i == $divid){
        document.getElementById($div).className='blue';
      } else {
        document.getElementById($div).className='grey team';
      }
    }
  }
}

	//javascript for bookmark page

  function bookmarksite(title,url){
    if (window.sidebar) // firefox
      window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
      var elem = document.createElement('a');
      elem.setAttribute('href',url);
      elem.setAttribute('title',title);
      //elem.setAttribute('rel','sidebar');
      elem.click();
    } else if(document.all)// ie
      window.external.AddFavorite(url, title);
    else {
      alert("Sorry! Your browser doesn't support this function. Please bookmark this page manually.");
    }
  }


 /*
  *   Function to set and clear values for any element
  */
  function set_unset_element_value(elem_id, def_text, set_unset){
    // 0 - Set Value
    // 1 - Unset Value
    var existing_value = document.getElementById(elem_id).value;
    if(set_unset == '0'){
      if(existing_value == ''){
        document.getElementById(elem_id).value = def_text;
      }
    } else {
      if(existing_value == def_text) {
        document.getElementById(elem_id).value = '';
      }
    }
  }
  
  /*
  *   Function to validate inputs in a form
  */
  function validate_inputs(inputs){

    var input_list =  inputs.split(',');

    for(i=0;i<input_list.length;i++){
      single_input = input_list[i].split(':');
      //alert(single_input[0]+'-'+single_input[1]);
      elem_value = document.getElementById(single_input[0]).value;
      if (elem_value == single_input[1]){
        alert('Please input a valid value for '+single_input[1]);
        return false;
      }
    }
    return true;
  }

  /*
  *   Function to validate inputs in a form
  */
  function contact_us_validate_inputs(inputs){

    var input_list =  inputs.split(',');

    for(i=0;i<input_list.length;i++){
      single_input = input_list[i].split(':');
      //alert(single_input[0]+'-'+single_input[1]);
      elem_value = document.getElementById(single_input[0]).value;
      if (elem_value == single_input[1]){
        alert('Please provide a valid input for all Required Fields. Thank You.');
        return false;
      }
    }
    return true;
  }
