
document.observe("dom:loaded", function() {
  menu_hover();
  if ( $('cleaning_products') ) { cat_icons_hover() }
});


var menu_hover = function() {
  $('menu').immediateDescendants().each(function(i) {
    i.observe('mouseover', function() { i.addClassName('sfhover') })
    i.observe('mouseout', function() { i.removeClassName('sfhover') })
  });
}


var cat_icons_hover = function() {

  var c = -1;
  var arr_cats = $$('div#cleaning_products ul li')

  arr_cats.each(function(i) {
    c++; i.id = 'c_' + c;
    i.observe('mouseover', toggle_cat_icon.bindAsEventListener( null, c, 1 ) )
    i.observe('mouseout', toggle_cat_icon.bindAsEventListener( null, c, 0 ) )
  });

}

function toggle_cat_icon( evt, cat, state ) {

  var img = $$('li#c_' + cat + ' img ');

  if ( state == 1 ) { img[0].src = img[0].src.replace('_color.gif', '.gif') }
  else { img[0].src = img[0].src.replace('.gif', '_color.gif') }

  //alert('cat: ' + cat + '\nstate: ' + state + '\nsrc: ' + img[0].src);

}






function sbStatsTrack(pagetype, pageid, cookiename, sessionid, urlhardcoded) {
  var imgStats = sbMakeStatsImg(pagetype, pageid, cookiename, sessionid, urlhardcoded, false);
  document.write(imgStats);
}

function sbMakeStatsImg(pagetype, pageid, cookiename, sessionid, urlhardcoded, ajaxcaller) {

  // detect cookie
  var cookieID   = ''
  if(document.cookie) {
  	var cookieName = cookiename;
  	var theCookie = document.cookie;
  	theCookie = unescape(theCookie);
  	var firstChar = theCookie.indexOf(cookieName);
  	if(firstChar != -1) {
  		firstChar += cookieName.length + 1;
  		var lastChar = theCookie.indexOf(';', firstChar);
  		if(lastChar == -1) lastChar = theCookie.length;
  		cookieID = unescape(theCookie.substring(firstChar, lastChar) );
  	}
  }

  // detect language user
  taalUser = navigator.userLanguage;
  taalBrowser = navigator.browserLanguage;
  taalSystem = navigator.systemLanguage;
  if (taalUser != 'en-us') {taal = taalUser;}
  else if (taalSystem != 'en-us') {taal = taalSystem;}
  else if (taalBrowser != 'en-us') {taal = taalBrowser;}
  else {taal = taalUser;}
  if (taal == undefined) {taal = '-';}
  var userlang = taal ;

  // detect screen properties
  var w=screen.width;
  var h=screen.height;
  var c;
  if (screen.colorDepth) {c=screen.colorDepth} else {c=screen.pixelDepth}

  // detect refering page
  if ( ajaxcaller == true ) {
    var refererpage = '...';
  }
  else {
    var refererpage='' + escape(document.referrer);
  }


  // detect url this page (can be hardcoded)
  var urlpage_hc = urlhardcoded;
  if (urlpage_hc != '') { urlpage=escape(urlpage_hc) }
  else { urlpage='' + escape(document.URL) }

  var file  = '/_admin/sitetools/stats/count_sql.asp';
  var info;
  var str_return;

  var randomnumber = Math.floor(Math.random()*100000);

  info =
  '?w=' + w
  + '&h=' + h
  + '&c=' + c
  + '&r=' + refererpage
  + '&u='+ urlpage
  + '&cID=' + cookieID
  + '&p=' + pagetype
  + '&pID=' + pageid
  + '&sID=' + sessionid
  + '&l=' + userlang
  + '&rnd=' + randomnumber;

  str_return = '<img src="' + file + info + '" width="1" height="1" border="0" alt="" />';
  return str_return;

}