

!function(context) {
  var doc = context.document,
    $ = context.jQuery,
    loc = context.location,
    oServices = {
      'bookmark': '<a href="#" title="Bookmark and Save to Favorites" class="sbookmark shareicon"></a>',
      'email': '<a onclick="window.open(\'mailto:email@email.com?subject=%url%\');return false;" href="#" title="Email" class="semail shareicon"></a>',
      'print': '<a onclick="window.print();return false;" href="#" title="Print" class="sprint shareicon"></a>',
      'pdf': '<a href="http://www.web2pdfconvert.com/convert" title="Create PDF" class="spdf shareicon"></a>',
      'google': '<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=%url%" title="Send to Google" class="sgoogle shareicon"></a>',
      'twitter': '<a href="http://twitter.com/share?url=%url%&amp;via=focalpress" title="Tweet This" class="stwitter shareicon"></a>',
      'facebook': '<a href="http://www.facebook.com/sharer.php?u=%url%" title="Share on Facebook" class="sfacebook shareicon"></a>',
      'digg': '<a href="http://digg.com/submit?url=%url%" title="Digg This" class="sdigg shareicon"></a>',
      'delicious': '<a href="http://www.delicious.com/save?url=%url%" title="Bookmark on Delicious" class="sdelicious shareicon"></a>',
      'stumbleupon': '<a href="http://www.stumbleupon.com/submit?url=%url%" title="Send to StumbleUpon" class="sstumbleupon shareicon"></a>',
      //'brainify': '<a href="http://www.brainify.com/Bookmark.aspx?url=%url%" title="Send to Brainify" class="sbrainify shareicon"></a>',
      'googletranslate': '<a href="http://translate.google.com/translate?u=%url%" title="Send to Google Translate" class="stranslate shareicon"></a>'
    };

  var tmpl = function(tmpl, obj) {
    // for each property
    for (var k in obj) {
      // run regexp function replacing marker props with corresponding values
      tmpl = tmpl.replace(new RegExp('%' + k + '%','g'), obj[k]);
    } 
    return tmpl;
  };

  var updateServices = function(oEdits) {
    var aRemove = oEdits && oEdits.remove || false,
      oAdd = oEdits && oEdits.add || false,
      oReturn = oServices,
      sService;

    if ( oAdd ) {
      oReturn = $.extend({}, oReturn, oAdd);
    }

    if ( aRemove ) {
      for ( sService in aRemove ) {
        sServiceName = aRemove[sService]
        if ( oReturn[sServiceName] ) {
          delete oReturn[sServiceName];
        }
      }
    }

    return oReturn;
  };

  var ShareTools = function(sID, oEdits) {
    var aServices = [];

    if ( oEdits ) {
      oServices = updateServices(oEdits);
    }

    for ( var s in oServices ) {
      if ( oServices.hasOwnProperty(s) ) {aServices.push(oServices[s]);}     
    }

    $('#'+sID).html(tmpl(aServices.join(''), {'url':loc}));
  };

  return context['cw_sharetools'] = ShareTools;
}(this);

var $fdbkForm = $('#cw_feedback_form');
if ($fdbkForm.length) {
  $fdbkForm.validate({
    rules: {
      name: 'required',
      message: 'required',
      email: {
        required: true,
        email: true
      }
    },
    messages: {
      name: 'Please enter your name',
      message: 'Please enter a message',
      email: 'Please enter a valid email address'
    }
  });
  $('#scrwidth').val($(window).width());
  $('#scrheight').val($(window).height());
}

$(function() {
  //$('#nav').hide();
  $("div.productimg a.imgload").each(function(){
    $(this).load("/_components/product_img/"+this.id+"/fullimage/150/", function(){
      $("img.reflect").reflect({height:0.15, opacity:0.25});
    });
  });
});


