

/*
alert(navigator.appName);
alert(navigator.appVersion);
alert(navigator.platform);
alert(navigator.userAgent);


function msieversion() {
var ua = window.navigator.userAgent
var msie = ua.indexOf("MSIE ")

if (msie > 0)      // If Internet Explorer, return version number
return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)))
else                 // If another browser, return 0
return 0

}
if (msieversion() < 6) {
alert('stop');
exit;
};
*/

//alert(BrowserDetect.browser)
//alert('Browser version: '+BrowserDetect.version)
//alert('OS name: ' + BrowserDetect.OS)

/*
if (window.opera) {
  alert('i found opera');
  exit;
}
*/

var newsItem = 0;
var thisProd1 = 0;
var thisProd2 = 0;
var thisProd3 = 0;

$(document).ready(
function() {

  //-- check for incompatible browsers
  if (BrowserDetect.browser == 'Opera' && BrowserDetect.version < 9) {
    //alert('dont go');
    return;
  }


  //-- check for existence of prodlist1 ----
  if ($('#prodList1').length > 0) {
    prod1Display();
  }
  //-- check for existence of prodlist2 ----
  if ($('#prodList2').length > 0) {
    prod2Display();
  }
  //-- check for existence of prodlist3 ----
  if ($('#prodList3').length > 0) {
    prod3Display();
  }

  //===== product box 1 ===================
  function prod1Display() {

    //-- check we do have product lists
    if ($('#prodList1 ul').length > 0) {
      //-- set current item and next item array pos
      var lastProd1 = thisProd1;
    }

    //-- reset loop if at last item
    if (thisProd1 == $('#prodList1 ul').length) {
      thisProd1 = 1; //-- start over
    } else {
      thisProd1++;
    }

    $("'#prodList1 ul.hpProd#p1" + lastProd1 + "'").fadeOut("700",
      function() { $("'#prodList1 ul.hpProd#p1" + thisProd1 + "'").fadeIn("1000"); }
    );

    setTimeout(prod1Display, 5000);

  }
  //=======================================
  //===== product box 2 ===================
  function prod2Display() {

    //-- check we do have product lists
    if ($('#prodList2 ul').length > 0) {
      //-- set current item and next item array pos
      var lastProd2 = thisProd2;
    }

    //-- reset loop if at last item
    if (thisProd2 == $('#prodList2 ul').length) {
      thisProd2 = 1; //-- start over
    } else {
      thisProd2++;
    }

    $("'#prodList2 ul.hpProd#p2" + lastProd2 + "'").fadeOut("700",
      function() { $("'#prodList2 ul.hpProd#p2" + thisProd2 + "'").fadeIn("1000"); }
    );

    setTimeout(prod2Display, 5000);

  }
  //=======================================
  //===== product box 3 ===================
  function prod3Display() {

    //-- check we do have product lists
    if ($('#prodList3 ul').length > 0) {
      //-- set current item and next item array pos
      var lastProd3 = thisProd3;
    }

    //-- reset loop if at last item
    if (thisProd3 == $('#prodList3 ul').length) {
      thisProd3 = 1; //-- start over
    } else {
      thisProd3++;
    }

    $("'#prodList3 ul.hpProd#p3" + lastProd3 + "'").fadeOut("700",
      function() { $("'#prodList3 ul.hpProd#p3" + thisProd3 + "'").fadeIn("1000"); }
    );

    setTimeout(prod3Display, 5000);

  }

  //-- check if news articles on page ---------
  //alert($('#newsArticles').length > 0);
  if ($('#newsArticles').length > 0) {
    //alert($('#newsArticles .Article#a1').length);
    newsDisplay();
  }

  //-- function allowing users to select specific news items
  function selectDisplay(n) {
    newsItem = n; //-- get news item number selected

    $('#newsArticles').children().hide(); //-- hide all news items
    $('#newsSelector ul li span').removeClass('sel'); //-- remove the selected button from all news items
    $("'#newsArticles .Article#a" + newsItem + "'").show(); //-- show the selected news item
    $("'#newsSelector ul li span#newsSel" + newsItem + "'").addClass('sel');  //-- set the respective button for the news item

    //-- clear any timer for the news display and reset
    clearTimeout(newsTimer);
    setTimeout(newsDisplay, 30000); //-- delay slightly longer - let them read it!
  }

  $('#newsSelector ul li span').click(function() {
    //alert($(this).attr("n"));
    selectDisplay($(this).attr("n"));
  });

  function newsDisplay() {
    //-- check we do have news articles present
    if ($('#newsArticles .Article').length > 0) {
      //-- set current item and next item array pos
      var lastItem = newsItem;

      if (newsItem == $('#newsArticles .Article').length) {
        newsItem = 1; //-- start over
      } else {
        newsItem++;
      }

      //alert('showing: ' + newsItem);

      $("'#newsArticles .Article#a" + lastItem + "'").fadeOut("700",
        function() {
          $("'#newsArticles .Article#a" + newsItem + "'").fadeIn("1000");
          $("'#newsSelector ul li span#newsSel" + newsItem + "'").addClass('sel');
          $("'#newsSelector ul li span#newsSel" + lastItem + "'").removeClass('sel');
        }
      );

      newsTimer = setTimeout(newsDisplay, 15000);
    }
  }


});

