/home/coolpkct/www/websites/cake3.cool.rocks/admin/scripts/jcustomize.js
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2012, SimpleViewer Inc.
 */
 
var global_target;
var global_browseWin;
/**
 * Image browse
 */
 $(function(){
   $('button.imagesrc').on('click', function(event){
     if(!global_browseWin || global_browseWin.closed)
     {
       global_browseWin = window.open('index.php?cmd=librarybrowseimages', this.name, 'width=980, height=768, scrollbars=yes');
     }
     else global_browseWin.focus();
   });
 });
/**
 * Initialise the color picker
 */
$(function(){
  // load the slider
  loadSV();
  // set the hue
  updateH('F1FFCC');
  $('input, select, textarea').not('input.colorpicker')
    .on('focus', function(event) {
    $('#plugin').css({display: 'none'}); 
    });
  $('input.colorpicker')
    .on("focus", function(event){
      global_target = $(this);
      updateH($(this).val());
      $('#plugHEX').html($(this).val());
      var position = $(this).position();
      $('#plugin:visible').animate({top: position.top}, 'slow', 'swing');
      $('#plugin:hidden').css({top: position.top, display: 'block'});
    })
    .on("keyup", setColors)
    .each(setColors);
});
/**
 * Set input element color and background from value
 */
function setColors()
{
  var thisValue = $(this).val();
  var thisColor = thisValue;
  if (thisValue.charAt(0) == '#') thisColor = thisValue.slice(1);
  if (thisValue.toLowerCase().substring(0,2) == '0x') thisColor = thisValue.slice(2);
  if (!(thisColor.match('^([0-9a-fA-F]{6})$')))
  {
    $(this).css({background: '#FFFFFF', color: '#FF0000'});
    return;
  }
  updateH(thisColor);
  $('#plugHEX').html(thisColor);
  var hsv = hex2hsv(thisColor);
  var foreground = (hsv[2] < 70) ?  '#FFFFFF' : '#000000';
  $(this).css({background: '#' + thisColor, color: foreground});
}
/**
 * Called by colorjack plugin
 * v is hex color string with no leading #
 * hex2hsv function is provided by plugin
 */
function mkColor(v)
{
  var hsv = hex2hsv(v);
  var foreground = (hsv[2] < 70) ?  '#FFFFFF' : '#000000';
  global_target.val(v).css({background: '#'+v, color: foreground});
}