// Devil Mountain JavaScript
// Author: www.ihurd.com
// Copyright 2010, Design by Hurd and Associates
// Last Modified: 1/12/2010

var imgpath = "images/";
var emailcommon = "@DevilMountainNursery.com";
var readmore = 0;
var curperson = get_curperson();

var salespeople_names = ["sergio", 
                         "mark", 
                         "tina", 
                         "bill", 
                         "dan", 
                         "larry", 
                         "ed"
    ];

var salespeople_phone = ["(925) 829-6006, x17",
                         "(925) 829-6006, x18",
                         "(925) 829-6006, x19",
                         "(925) 829-6006, x20",
                         "(925) 829-6006, x21",
                         "(925) 829-6006, x22",
                         "(925) 829-6006, x23"
    ];

var salespeople_bio_short = [
  "Sergio is an original employee of Devil Mountain Nursery and has worked his way up through the ranks.",
  "Mark worked for his family's business, Mayfair Wholesale Nursery in San Jose from 1978 until its closing in 1999.",
  "Tina's attention to plant detail is unique and inspiring. With 33 years of experience in the nursery industry, it " +
    "is not hard to understand why.",
  "Bill has devoted substantial time to hone his skills as a professional Horticulturist.",
  "The most experienced of the Devil Mountain team, Dan's 40 years of landscaping and nursery experience is a real asset " +
    "to Devil Mountain Nursery.",
  "A life-long East Bay resident with 17 years of professional landscaping, Larry has as in-depth a knowledge of the Bay " + 
    "Area as you will find anywhere.",
  "Ed has 33 years of diverse experience in landscaping, nursery production and retail and wholesale sales " +
    "and marketing."
    ];

var salespeople_bio_long = [
  "Since joining the " +
    "sales team in 1995 he has been a key representative. He understands the needs of Devil Mountain Customers because he " +
    "helped design the company's commitment to them. Sergio understands how to go from working the design plan to job " +
    "completion with minimal problems. He is proud of the work he does which is evident by the number of customers who " +
    "depend on him.<br /><br />Sergio is a big soccer fan; his favorite team is Cruz Azul.",
  "For 21 years Mark's focus for Mayfair was purchasing as well as catering to the needs of the retail nursery trade. In 1999 " +
    "Mark joined the Devil Mountain team adding his years of unique experience in finding the finest quality plant materials " +
    "and providing the highest level of service with his high energy style. Mark is an expert in general nursery stock and " +
    "a detail person, which are valuable qualities when organizing large landscape jobs.<br /><br />Mark has a great passion " +
    "for singing and has made a number of \"Karaoke\" style CDs.",
  "Graduating from North Carolina State University with a degree in horticulture, Tina's vast " +
    "experience includes Greenhouse culture, Estate Gardening and owning a wholesale nursery growing general nursery stock. " +
    "Tina was part of the original Devil Mountain team in 1995 leaving in 1998 only to return in 2005 to rejoin and " +
    "complement the team. Tina's expert understanding of perennials and drought tolerant natives are among the best in the " +
    "industry.<br /><br />Tina's other interests include travel, fine wines and micro beers as well as photography.",
  "His many years of experience " +
    "as a manager and buyer for a busy retail nursery have contributed to Bill's high level of service skills. Bill's plant " +
    "focus and extensive world travel has added an understanding of plants afforded to very few.  On the Devil Mountain " +
    "team his general plant knowledge is of the highest caliper, his expertise in xerophyte plants is unsurpassed. Bill " +
    "is leading the development of the succulent and cactus section of Devil Mountain Nursery.<br /><br />Bill enjoys travel " +
    "and has visited many diverse destinations around the world.",
  "Having been the owner of a landscape company as well as a highly successful San Leandro " +
    "retail nursery, his years of recommending plants for Bay Area landscapes are evident in his expert advice. That, combined " +
    "with his attention to detail provides his customers with a wealth of experience that they have come to rely on. " +
    "<br /><br />Dan enjoys fishing and golf.",
  "His rich plant knowledge as well as a special interest in California native plants " +
    "makes Larry a valued member of the Devil Mountain team. Sharing his whit, dynamic personality, and sincere appreciation " +
    "with the landscapers that work with him, Larry adds value to service with style.<br /><br />Larry enjoys hiking, " +
    "visiting streams and mountains or anywhere he can find fresh air.",
  "His special areas of interests include sustainable and edible landscapes, market development and Fruit trees. " +
    "After 17 years with the Dave Wilson Nursery, Ed comes to Devil Mountain ready to help carry on the tradition of top " +
    "service using expert help. Ed is known throughout the industry for his high energy and straight talk. " +
    "<br /><br />Ed is a lover of gardening, classic cars, fine music, and fine wine."
   ];

var myImg = [];


preload_salespeople();  //Preload images for salespeople

function init_page() {
  swap_salesperson(curperson);  //Load current salesperson
  salescolumn_bottom();
}

function preload() {
  for (var i=0; i<preload.arguments.length; i++) {
    myImg[i] = new Image();
    var src = imgpath + preload.arguments[i] + '.jpg';
    myImg[i].src = src;
  }
}

function preload_salespeople() {
  for (var i=0; i<salespeople_names.length; i++) {
    var thumb = salespeople_names[i] + "_thumb";
    var over = thumb + "_over";
    preload(salespeople_names[i], thumb, over);
  }
}

function swap_salesperson(id) {

  curperson = id;
  var right_div = document.getElementById('salescolumn-top');
  var data = '';

  if (id == -1) {
    data = "<h2>Contact a<br />Sales Person...</h2>";
  } else { 
    var myimg = imgpath + salespeople_names[id] + ".jpg";
    var myname = upper_first(salespeople_names[id]);
    var myemail = myname + emailcommon;
    var myphone = salespeople_phone[id];
    var myshortbio = salespeople_bio_short[id];
    var mybio = salespeople_bio_long[id];

    data  = "<img src='" + myimg + "' alt='" + myname + "' width='190' height='146' />\n";
    data += "<h3 id='salesname'>" + myname + "</h3><h3 id='salesphone'>" + myphone + "</h3>\n";
    data += "<p class='salesemail'><a href='mailto:" + myemail + "'>" + myemail + "</a></p>\n";
    data += "<p class='salesbio'>" + myshortbio + "<br />\n";
    data += "<p class='salesbiolink' id='readmore' onclick='toggle_bio()'>Read More</a></p>\n";
    data += "<div id='bio'></div>\n";
  }

  document.cookie="curperson="+curperson;
  right_div.innerHTML = data;
}

function upper_first(mystr) {
  return mystr.substr(0, 1).toUpperCase() + mystr.substr(1);
}


function toggle_bio() {

  var biodiv = document.getElementById('bio');
  var readmoretext = document.getElementById('readmore');
  if (readmore == 0) {
    biodiv.innerHTML = "<p class='salesbio'>" + salespeople_bio_long[curperson] + "</p>";
    readmoretext.innerHTML = "Close Bio";
    readmore = 1;
  } else {
    biodiv.innerHTML = '';
    readmoretext.innerHTML = "Read More";
    readmore = 0;
  }
}

function salescolumn_bottom() {

  var columnbottom = document.getElementById('salescolumn-bottom');

  var data = "<table width='100%' style='margin-top: 15px; padding-left: 19px; padding-right: 13px'>\n";

  var count = 0;
  for (var i=0; i<salespeople_names.length; i++) {
    var thumb = imgpath + salespeople_names[i] + "_thumb.jpg"; 
    var myname = upper_first(salespeople_names[i]);
    var colsp = '';
    if (count % 2 == 0) { data += "<tr>\n"; }
    if (salespeople_names.length % 2 != 0 && count == salespeople_names.length-1) { colsp = " colspan='2' "; }
    data += "<td align='center'" + colsp + "><img src='" + thumb + "' width='74' height='96' alt='" + myname + "' " +
            "onmouseover='make_active(this, "+i+")' onmouseout='make_inactive(this, "+i+")' " +
            "onclick='swap_salesperson("+i+")' class='salescolumn-thumb''/></td>\n";
    count++;
    if (count % 2 == 0) { data += "</tr>\n"; }
  }

  data += "</table>\n";

  columnbottom.innerHTML = data;
}

function make_active(ref, id) {
  var thumb = imgpath + salespeople_names[id] + "_thumb_over.jpg";
  ref.src = thumb;
}

function make_inactive(ref, id) {
  var thumb = imgpath + salespeople_names[id] + "_thumb.jpg";
  ref.src = thumb;
}

function get_curperson() {
  var cur = get_cookie("curperson");
  if (cur == '') { cur = -1; }
  return cur;
}

function get_cookie(val) {
  var str = val + '='
  var ret = '';
  if (document.cookie.length > 0) {
    os = document.cookie.indexOf(str)
    if (os != -1) { 
      os += str.length
      end = document.cookie.indexOf(";", os);
      if (end == -1) end = document.cookie.length;
      ret = unescape(document.cookie.substring(os, end))
      }
   }
  return ret;
}
