/*
 * jQuery ifixpng plugin
 * (previously known as pngfix)
 * Version 3.1.2  (2008/09/01)
 * @requires jQuery v1.2.6 or above, or a lower version with the dimensions plugin
 *
 * Based on the plugin by Kush M., http://jquery.khurshid.com
 *
 * Background position Fixed
 * Also fixes non-visible images
 * (c) Copyright Yereth Jansen (yereth@yereth.nl)
 * personal website: http://www.yereth.nl
 * Company website: http://www.wharf.nl
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * For a demonstration of the background-position being fixed:
 * http://www.yereth.nl/bgpos.html
 *
 * Plugin page:
 * http://plugins.jquery.com/project/iFixPng2
 *
 */

/**
 *
 * @example
 *
 * optional if location of pixel.gif if different to default which is images/pixel.gif
 * $.ifixpng('media/pixel.gif');
 *
 * $('img[@src$=.png], #panel').ifixpng();
 *
 * @apply hack to all png images and #panel which icluded png img in its css
 *
 * @name ifixpng
 * @type jQuery
 * @cat Plugins/Image
 * @return jQuery
 * @author jQuery Community
 */
;(function($) {

  /**
   * helper variables and function
   */
  $.ifixpng = function(customPixel) {
    $.ifixpng.pixel = customPixel;
  };
  
  $.ifixpng.regexp = {
    bg: /^url\(["']?(.*\.png([?].*)?)["']?\)$/i,
    img: /.*\.png([?].*)?$/i
  },
  
  $.ifixpng.getPixel = function() {
    return $.ifixpng.pixel || '/images/pixel.gif';
  };
  
  var hack = {
    base  : $('base').attr('href'),
    ltie7  : $.browser.msie && $.browser.version < 7,
    filter  : function(src) {
      return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
    }
  };
  
  /**
   * Applies ie png hack to selected dom elements
   *
   * $('img[@src$=.png]').ifixpng();
   * @desc apply hack to all images with png extensions
   *
   * $('#panel, img[@src$=.png]').ifixpng();
   * @desc apply hack to element #panel and all images with png extensions
   *
   * @name ifixpng
   */
   
  $.fn.ifixpng = hack.ltie7 ? function() {
    function fixImage(image, source, width, height, hidden) {
      image.css({filter:hack.filter(source), width: width, height: height})
        .attr({src:$.ifixpng.getPixel()})
        .positionFix();
    }
    
      return this.each(function() {
      var $$ = $(this);
      if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
        var source, img;
        if (this.src && this.src.match($.ifixpng.regexp.img)) { // make sure it is png image
          // use source tag value if set
          source = (hack.base && this.src.substring(0,1)!='/' && this.src.indexOf(hack.base) === -1) ? hack.base + this.src : this.src;
          // If the width is not set, we have a problem; the image is not probably visible or not loaded
          // and we need a work around.
          if (!this.width || !this.height) {
            $(new Image()).one('load', function() {
              fixImage($$, source, this.width, this.height);
              $(this).remove();
            }).attr('src', source);
          // If the image already has dimensions (it's loaded and visible) we can fix it straight away.
          } else fixImage($$, source, this.width, this.height);
        }
      } else if (this.style) { // hack png css properties present inside css
        var imageSrc = $$.css('backgroundImage');
        // Background repeated images we cannot fix unfortunately
        if (imageSrc && imageSrc.match($.ifixpng.regexp.bg) && this.currentStyle.backgroundRepeat == 'no-repeat') {
          imageSrc = RegExp.$1;
          var x = this.currentStyle.backgroundPositionX || 0, y = this.currentStyle.backgroundPositionY || 0;
          if (x || y) {
            var css = {}, img;
            if (typeof x != 'undefined') {
              if (x == 'left') css.left = 0;
              // if right is 0, we have to check if the parent has an odd width, because of an IE bug
              else if (x == 'right') css.right = $$.width() % 2 === 1 ? -1 : 0;
              else css.left = x;
            }
            if (typeof y != 'undefined') {
              // if bottom is 0, we have to check if the parent has an odd height, because of an IE bug
              if (y == 'bottom') css.bottom = $$.height() % 2 === 1 ? -1 : 0;
              else if (y == 'top') css.top = 0;
              else css.top = y;
            }
            img = new Image();
            $(img).one('load', function() {
              var x,y, expr = {}, prop;
              // Now the image is loaded for sure, we can see if the background position needs fixing with an expression (in case of percentages)
              if (/center|%/.test(css.top)) {
                expr.top = "(this.parentNode.offsetHeight - this.offsetHeight) * " + (css.top == 'center' ? 0.5 : (parseInt(css.top) / 100));
                delete css.top;
              }
              if (/center|%/.test(css.left)) {
                expr.left = "(this.parentNode.offsetWidth - this.offsetWidth) * " + (css.left == 'center' ? 0.5 : (parseInt(css.left) / 100));
                delete css.left;
              }
              // Let's add the helper DIV which will simulate the background image
              $$.positionFix().css({backgroundImage: 'none'}).prepend(
                $('<div></div>').css(css).css({
                  width: this.width,
                  height: this.height,
                  position: 'absolute',
                  filter: hack.filter(imageSrc)
                })
              );
              if (expr.top || expr.left) {
                var elem = $$.children(':first')[0];
                for (prop in expr) elem.style.setExpression(prop, expr[prop], 'JavaScript');
              }
              $(this).remove();
            });
            img.src = imageSrc;
          } else {
            $$.css({backgroundImage: 'none', filter:hack.filter(imageSrc)});
          }
        }
      }
    });
  } : function() { return this; };
  
  /**
   * positions selected item relatively
   */
  $.fn.positionFix = function() {
    return this.each(function() {
      var $$ = $(this);
      if ($$.css('position') != 'absolute') $$.css({position:'relative'});
    });
  };

})(jQuery);


/*--------------------------------------------------------------------
 * JQuery Plugin: "EqualHeights"
 * by:  Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element
     and sets their min-height to the tallest height (or width to widest width). Sets in em units
     by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method  (article:
    http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)                
 * Usage Example: $(element).equalHeights();
      Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

$.fn.equalHeights = function(px) {
  $(this).each(function(){
    var currentTallest = 0;
    $(this).children().each(function(i){
      if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
    });
    if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
    // for ie6, set height since min-height isn't supported
    if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
    $(this).children().css({'min-height': currentTallest});
  });
  return this;
};

/*--------------------------------------------------------------------
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com)
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/     
 *              
 * Options:                     
     scope: string or jQuery selector for font-size scoping
     reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library              
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008
 * Changelog:
 *    08.02.2007 initial Version 1.0
 *    08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------*/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
  //set defaults
  settings = jQuery.extend({
    scope: 'body',
    reverse: false
  }, settings);
  
  var pxVal = (this == '') ? 0 : parseFloat(this);
  var scopeVal;
  var getWindowWidth = function(){
    var de = document.documentElement;
    return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
  };  
  
  /* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size.
    For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size.   
    When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size)
    to get an accurate em value. */
        
  if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
    var calcFontSize = function(){    
      return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
    };
    scopeVal = calcFontSize();
  }
  else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
      
  var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
  return result;
};



(function($) {
// It takes a simple transparent image with 4 rounded corners and makes it simple to add them to any image or div.
$.fn.rcorner = function(options) {
  var opts = $.extend({}, $.fn.rcorner.defaults, options);

  return this.each(function(i) {
    var $this = $(this);

    // Support for the Metadata Plugin.
    var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
    
    //$this.wrap('<div class="rcorner_wrapper writer'+i+'"></div>');
    //$('.writer'+i).append('<div class="top_left"></div><div class="top_right"></div><div class="bottom_left"></div><div class="bottom_right"></div>');
    $this.append('<div class="top_left"></div><div class="top_right"></div><div class="bottom_left"></div><div class="bottom_right"></div>');
  });

  // private function for debugging
  function debug($obj) {
    if (window.console && window.console.log) {
      window.console.log($obj);
    }
  }
};

// default options
$.fn.rcorner.defaults = {
  defaultOne:true,
  defaultTwo:false,
  defaultThree:'yay!'
};

})(jQuery);


/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
  $.fn.superfish = function(op){

    var sf = $.fn.superfish,
      c = sf.c,
      $arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
      over = function(){
        var $$ = $(this), menu = getMenu($$);
        clearTimeout(menu.sfTimer);
        $$.showSuperfishUl().siblings().hideSuperfishUl();
      },
      out = function(){
        var $$ = $(this), menu = getMenu($$), o = sf.op;
        clearTimeout(menu.sfTimer);
        menu.sfTimer=setTimeout(function(){
          o.retainPath=($.inArray($$[0],o.$path)>-1);
          $$.hideSuperfishUl();
          if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
        },o.delay);  
      },
      getMenu = function($menu){
        var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
        sf.op = sf.o[menu.serial];
        return menu;
      },
      addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
      
    return this.each(function() {
      var s = this.serial = sf.o.length;
      var o = $.extend({},sf.defaults,op);
      o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
        $(this).addClass([o.hoverClass,c.bcClass].join(' '))
          .filter('li:has(ul)').removeClass(o.pathClass);
      });
      sf.o[s] = sf.op = o;
      
      $('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
        if (o.autoArrows) addArrow( $('>a:first-child',this) );
      })
      .not('.'+c.bcClass)
        .hideSuperfishUl();
      
      var $a = $('a',this);
      $a.each(function(i){
        var $li = $a.eq(i).parents('li');
        $a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
      });
      o.onInit.call(this);
      
    }).each(function() {
      var menuClasses = [c.menuClass];
      if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
      $(this).addClass(menuClasses.join(' '));
    });
  };

  var sf = $.fn.superfish;
  sf.o = [];
  sf.op = {};
  sf.IE7fix = function(){
    var o = sf.op;
    if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
      this.toggleClass(sf.c.shadowClass+'-off');
    };
  sf.c = {
    bcClass     : 'sf-breadcrumb',
    menuClass   : 'sf-js-enabled',
    anchorClass : 'sf-with-ul',
    arrowClass  : 'sf-sub-indicator',
    shadowClass : 'sf-shadow'
  };
  sf.defaults = {
    hoverClass  : 'sfHover',
    pathClass  : 'overideThisToUse',
    pathLevels  : 1,
    delay    : 800,
    animation  : {opacity:'show'},
    speed    : 'normal',
    autoArrows  : true,
    dropShadows : true,
    disableHI  : false,    // true disables hoverIntent detection
    onInit    : function(){}, // callback functions
    onBeforeShow: function(){},
    onShow    : function(){},
    onHide    : function(){}
  };
  $.fn.extend({
    hideSuperfishUl : function(){
      var o = sf.op,
        not = (o.retainPath===true) ? o.$path : '';
      o.retainPath = false;
      var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
          .find('>ul').hide().css('visibility','hidden');
      o.onHide.call($ul);
      return this;
    },
    showSuperfishUl : function(){
      var o = sf.op,
        sh = sf.c.shadowClass+'-off',
        $ul = this.addClass(o.hoverClass)
          .find('>ul:hidden').css('visibility','visible');
      sf.IE7fix.call($ul);
      o.onBeforeShow.call($ul);
      $ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
      return this;
    }
  });

})(jQuery);


