/******************** TEST ************************/
jQuery.fn.supersleight = function(settings) {
  settings = jQuery.extend({ imgs: true, backgrounds: true, input_src: true, shim: '/images/blank.gif', apply_positioning: true }, settings);
  return this.each(function(){ if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) { jQuery(this).find('*').andSelf().each(function(i,obj) { var self = jQuery(obj); if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) { var bg = self.css('background-image'); var src = bg.substring(5,bg.length-2); var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale'); var styles = { 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')", 'background-image': 'url('+settings.shim+')' }; self.css(styles); }; if (settings.imgs && self.is('img[src$=png]')){ var styles = { 'width': self.getSupersleightWidth({margin:false}) + 'px', 'height': self.getSupersleightHeight({margin:false}) + 'px', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')" }; self.css(styles).attr('src', settings.shim); }; if (settings.input_src && self.is('input[src$=png]')){ var styles = { 'width': self.getSupersleightWidth({margin:false}) + 'px', 'height': self.getSupersleightHeight({margin:false}) + 'px', 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')" }; self.css(styles).attr('src', settings.shim); }; if (settings.apply_positioning && self.is('a, input, label') && (self.css('position') === '' || self.css('position') == 'static')){ self.css('position', 'relative'); }; }); }; }); 
};

$.fn.getSupersleightHeight = function(arguments) {
  arguments = $.extend({ border: true, margin: true, padding: true }, arguments);
  if (!$(this).exists()) { return 0; } var totalHeight = ($(this).height()>0)?$(this).height():$(this).css("height").replace(/px/g,""); var borderHeight = parseInt($(this).css("borderTopWidth")) + parseInt($(this).css("borderBottomWidth")); var marginHeight = parseInt($(this).css("margin-top")) + parseInt($(this).css("margin-bottom")); var paddingHeight = parseInt($(this).css("padding-top")) + parseInt($(this).css("padding-bottom")); if (arguments.border && borderHeight > 0) { totalHeight -= borderHeight; } if (arguments.margin && marginHeight > 0) { totalHeight -= marginHeight; } if (arguments.padding && paddingHeight > 0) { totalHeight -= paddingHeight; } return totalHeight; 
}

$.fn.getSupersleightWidth = function(arguments) {
  arguments = $.extend({ border: true, margin: true, padding: true }, arguments);
  if (!$(this).exists()) { return 0; } var totalWidth = ($(this).width()>0)?$(this).width():$(this).css("width").replace(/px/g,""); var borderWidth = parseInt($(this).css("borderLeftWidth")) + parseInt($(this).css("borderRightWidth")); var marginWidth = parseInt($(this).css("margin-left")) + parseInt($(this).css("margin-right")); var paddingWidth = parseInt($(this).css("padding-left")) + parseInt($(this).css("padding-right")); if (arguments.border && borderWidth > 0) { totalWidth -= borderWidth; } if (arguments.margin && marginWidth > 0) { totalWidth -= marginWidth; } if (arguments.padding && paddingWidth > 0) { totalWidth -= paddingWidth; } return totalWidth; 
}
/********************** End Test *********************/





//-------- Global Vars --------//
if(typeof($jq) == "undefined") {
  var $jq = jQuery.noConflict();
}

// In case we forget to take out console statements. IE becomes very unhappy when we forget. Let's not make IE unhappy
if(typeof(console) === 'undefined') {
  var console = {};
  console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}

// Suppress CurvyCorners alerts
var curvyCornersVerbose = false;


//-------- Functions --------//
function SwapImage(imagesrcstring) {
  thumbimages = document.getElementById("thumbcol").childNodes;
  for (var nodecount in thumbimages)
  {
    if(thumbimages[nodecount].nodeName == "A") 
    {
      if (thumbimages[nodecount].href == "javascript:SwapImage('" + imagesrcstring + "');")
        thumbimages[nodecount].className="currentselection";  
      else
        thumbimages[nodecount].className="";
    }
  }
  document["ProdImage"].src = imagesrcstring;
}

function ViewJump(view_selected) {
  // hide all Views
  $jq("div[id^=view]").css("display", "none");
  $jq("div[id=view_" + view_selected + "]").css("display", "block");
}

function highlightoval(ovalName) {
  var api = $jq("#hl_" + ovalName).overlay({oneInstance: false, api: true, expose: '#000', effect: 'apple'}); 
  api.load();   
}

function HideProductDetail() {
  if (OpenHighlightArea) {
    var c = document.getElementById(OpenHighlightArea);
    c.style.visibility = "hidden";
    OpenHighlightArea = null;
  }
}
  
function ProductDetail(containName) {
  var c = document.getElementById(containName);
  var s = c.style;
  s.visibility = "inherit";
  OpenHighlightArea = "" + containName;
}


//-------- Execution --------//

function runOnPageLoad(context) {

// jQuery Cycle plugin
  if (typeof($jq().cycle) == "function") {
    $jq("#articles", context).cycle({ timeout: 6000, speed: 500, pause: 1, fx: "scrollDown" });
    $jq("ul.slideshow", context).cycle({ timeout: 8000, speed: 1000, pause: 1, fx: "fade" });
  }

// jQuery Tools
  if (typeof($jq.tools) == "object") {
    // setup ul.tabs to work as tabs for each div directly under div.panes
    $jq("ul.tabs", context).tabs("div.panes > div");
    // jqt tabs as accordion
    $jq("#why-bars", context).tabs("div", { tabs: "a", effect: "slide", initialIndex: 0 });


    // Overlay init/params (iframe)
    var theframe = $jq('<iframe frameborder="0" scrolling="auto"></iframe>');
    $jq("[rel='#overlay']", context).overlay({
      mask: "#ff7800",
      onBeforeLoad: function() {
        var link = this.getTrigger().attr("href") + "?lightbox=y&amp;c=y";
        $jq(theframe).attr({ src: link, style: 'border:none;' });
        this.getOverlay().find(".contentWrap").html(theframe);
      },
      onClose: function() {
        this.getOverlay().find(".contentWrap").empty();
      }
    });
  }

// jQuery UI
  if (typeof($jq().accordion) == "function") {
    // jq-ui accordion
    $jq("#accordion", context).accordion({ header: "h3", autoHeight: false });
  }

  $jq("#View_Select", context).change(function() {
    ViewJump($jq(this).val());
  });

  //hover states on the static widgets
  $jq("#dialog_link, ul#icons li", context).hover(
    function() { $jq(this).addClass("ui-state-hover"); }, 
    function() { $jq(this).removeClass("ui-state-hover"); }
  );

  $jq('#marquee-tab, .close, .demotip, .demotip_down', context).supersleight({shim: "http://media.shoretel.com/designimages/shim.gif"});
  
}

// perform JavaScript after the document is scriptable.
$jq(document).ready(function($) {

  runOnPageLoad($(document));

// General jQuery & JS

  //ViewJump($("#View_Select").val());
  var filterState = $("#View_Select").val();
  ViewJump(filterState);


  if (typeof(init) == "function") {
    init();
  }

/*
  //tracking
  var adsrc = 'http://ad.advertise.com';
  if (!getCookie('__utmv') || getCookie('__utmv') == "") {
    var tag = '/pixel?id=1061926&t=1';
  } else if (getCookie('__utmv').toLowerCase().indexOf('registered') != -1) {
    var tag = '/pixel?id=1061927&id=1061928&t=1';
  } else {
    var tag = '/unpixel?id=1061926';
  }
  if (tag.indexOf('unpixel') == -1) {
    $.getScript(adsrc + tag, function() { $('body').append('<!-- advertise.com source loaded using this tag: ' + tag + ' -->\n\n'); });
  } else {
    $('body').append('<img src="' + adsrc + tag + '" width="1" height="1" alt="" />');
  }
*/

});



