﻿/// <reference path="jquery-vsdoc.js" />

var flipperIntervalId;
var flipperSpeed;
var flipperCurrentNdx;

function DoRoundedCorners()
{
   // round all the "solid" containers
   Nifty("div.roundable", "normal");

   // round the "outline" containers
   Outline("div.outline");
}

function Outline(selector)
{
   // Don't apply outline for IE6
   if ($.browser.msie && $.browser.version.substr(0, 1) == "6")
      return;
   
   $(selector).each(function()
   {
      OutlineMe(this);
   });
}

function OutlineMe(elem)
{
   var className;
   if ((className = getColorClass(elem)) == null)
      return;

   elem.appendChild(createCorner(className, "tl"));
   elem.appendChild(createCorner(className, "tr"));
   elem.appendChild(createCorner(className, "bl"));
   elem.appendChild(createCorner(className, "br"));
}

function createCorner(className, position)
{
   var c = document.createElement("DIV");
   c.className = className + "_" + position;

   return (c);
}

function getColorClass(elem)
{
   var classNames = elem.className.split(" ");
   for (var i = 0; i < classNames.length; i++)
   {
      if (classNames[i].indexOf("cl_") == 0)
         return (classNames[i]);
   }

   return (null);
}

function buildMenus()
{
}

function startFlipper()
{
   flipperCurrentNdx = 1;
   flipperSpeed = 12000;
   flipperIntervalId = setInterval("flipCMA()", flipperSpeed);
}

function flipCMA(ndx, reset)
{
   if (!ndx)
   {
      if ((++flipperCurrentNdx) == 4)
      {
         flipperCurrentNdx = 3;
         reset = true;
      }

      ndx = flipperCurrentNdx;
   }

   if (!reset) reset = false;
   
   // Get the current "on" image, remove the "on" class and add the "off" class
   var jq;
   if ((jq = $(".flipper_button.on")).length > 0)
      jq.toggleClass("on");

   // Now add the "on" class to the selected button and updated the image
   if ((jq = $("#flipperCmd" + ndx)).length == 1)
   {
      jq.toggleClass("on");
      $("#flipperImg").attr("src", "images/home_flipper_" + ndx + ".gif");
   }

   if (reset)
      clearInterval(flipperIntervalId);
}

function flipQuote(imgSize, imgNdx)
{
   // Get the current "on" image, remove the "on" class and add the "off" class
   var jq;
   if ((jq = $(".quote_button.on")).length > 0)
      jq.toggleClass("on");

   // Now add the "on" class to the selected button and updated the image
   if ((jq = $("#quoteCmd" + imgNdx)).length == 1)
   {
      jq.toggleClass("on");
      $("#quotesImg").attr("src", "images/quotes/" + imgSize + "_" + imgNdx + ".png");
   }
}

function requiredFieldsComplete()
{
   var formValid = true;
   $(".required").each(function()
   {
      var jq = $(this);
      jq.removeClass("value_required");

      if (jq.val() == "")
      {
         jq.addClass("value_required");
         formValid = false;
      }
   });

   if (!formValid)
      $("#validationMsg").css("visibility", "visible");

   return (formValid);
}

function InitContactPage()
{
   $(function()
   {
      $(".required").change(function()
      {
         var jq = $(this);
         if (jq.val() != "")
            jq.removeClass("value_required");
      });
   });
}
