if (typeof console === "undefined" || typeof console.log === "undefined") {
	console = { log: function () {} };
}
var $j = jQuery.noConflict();
var bg_classes = 'body, .wrapper, .pager, .sorter, .block .block-title, .cms-index-index .subtitle';
var negpos = (parseInt(Math.random() * 2) < 1) ? 1 : -1;

$j(function() {
  console.log('Test');
  // Handler for .ready() called.
//  bg_classes = 'body, .wrapper, .pager, .sorter, .block .block-title, .cms-index-index .subtitle';
  updateBG();
  setInterval("animateBG()",100+Math.round(250*Math.random()));
  $j("#home_link").hover(function() {
    $j(this).find("div").stop()
    .animate({float: "right", opacity:1}, "fast")
    .css("display","block")

  }, function() {
    $j(this).find("div").stop()
    .animate({float: "left", opacity: 0}, "fast")
  });
  $j('.category-description').expander({slicePoint: 200});
  hpSS();
  dropEmptyLeftColumn();
});

function dropEmptyLeftColumn() {
//  console.log($j('.col-left').text());
  if ($j('.col-left').html() == "") {
    $j('.col-main').css('margin-right','125px');
//    console.log('no html there either');
  }
}

function updateBG() {
//  img_pre = '<?php echo $jthis->getSkinUrl("images/vapor-pattern-1.jpg"); ?>';
//  img_pre = 'http://www.aromazap.com/shop/skin/frontend/default/aromazap/images/vapor-pattern-';
  //img_pre = $j('.wrapper').css('background-image');
  //img_pre = img_pre.substring(4,img_pre.length-6);
  img_pre = '/skin/frontend/default/aromazap/images/vapor-pattern-';
  rwn = Math.round(4 * Math.random())+1;
  newbgurl = img_pre + rwn + '.jpg';
  preload = new Image();
  preload.src = newbgurl;
  pos = Math.round(800*Math.random());
  $j(bg_classes).css('background-image','url("'+newbgurl+'")'); // repeat-x fixed '+pos+'px 0 #B7D1F2' );
  
}

function animateBG() {
  var bg = $j(bg_classes);
  var pos = bg.css('background-position');
  if (! pos) pos = '0';
  var npos = parseFloat(pos.match(/-?\d+/));
  npos += (1 * negpos);
  bg.css('background-position', npos+'px 0' );
}

function prepareSS() {
  $j('li.item').each(function() {
    $li = $j(this);
    $img = $li.find('img');
    oIsrc = $img.attr('src');
    nIsrc = oIsrc.replace('small_image/135x','image');
    console.log(oIsrc);
    console.log(nIsrc);
    console.log(this);
  });
}

function hpSS() {
  console.log(window.location);
  if (window.location.search == '?hpss') {
    prepareSS();
  }
}
