var TagCloudTimer = new Map();

TagCloudTimer.init = function () {
   TagCloudTimer.interval = setInterval(TagCloudTimer.load, 10000);
}
TagCloudTimer.load = function () {
   $('#'+ Globals.cloudparent).load('/templates/snippets/ajax_tagcloud.asp?classname='+ Globals.cloudclass);
}
$(TagCloudTimer.init);

$(document).ready(fixIE6);
$(setupTopNavHover);
$(setupDoelgroepLinkHovers);

function setupTopNavHover() {
   $('.topnavlist li').hover(
      function () {
         $(this).addClass('hover');
         $('a', this).addClass('hover');
      },
      function () {
         $(this).removeClass('hover');
         $('a', this).removeClass('hover');
      }
   );
}
function setupDoelgroepLinkHovers() {
   $('.doelgroep_link').hover(
      function () {
         $(this).parent().addClass('doelgroep_item_hover');
      },
      function () {
         $(this).parent().removeClass('doelgroep_item_hover');
      }
   );
}

/////////

/* proc fixIE6
   does: performs various adustments for layout bugs in IE6, such as position-confirming and png loading.
*/
function fixIE6() {
   //Guard: exit if version > IE6
   if ( !/MSIE\s(5\.5|6\.)/.test(navigator.userAgent) ) return;

   $('.doelgroep_link').each(function () {
      this.style.width = this.parentNode.offsetWidth + 'px';
      this.style.height = this.parentNode.offsetHeight + 'px';
   });

   /// PNG Fix.
   // For image elements only. Doing backgrounds automatically as well is unpredictable, because
   // the sizingMethods of the PNG filter do not match the possibilities of CSS backgrounds.
   // In some cases, a css background-repeat can be simulated with filter method "scale",
   // and a single no-repeat can sometimes be simulated with the filter method "image". These must be applied on
   // a case-by-case basis.

   //generic image fix.
   $('img').each(function () {
      if (/\.png$/.test(this.src)) {
         var originalPath = this.src;
         this.style.width = this.width + 'px';
         this.style.height = this.height + 'px';
         this.src = '../gfx/pngfix_pixel.gif';
         this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ originalPath +"',sizingMethod='scale')";
      }
   });

   // background elements no-repeat 0,0
   $('#logoframe, #telnummer, #contenttop_bottom, #textcloud, #denkwolk').each(function () {
      var backgroundPath = getStyleValue(this, 'background-image');
      backgroundPath = backgroundPath.replace(/(url\(['"]?|['"]?\))/gi,'');

      this.style.backgroundImage = 'none';
      this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ backgroundPath +"',sizingMethod='image')";
   });
   $('#textpage_rightcolumn').each(function () {
      var backgroundPath = getStyleValue(this, 'background-image');
      backgroundPath = backgroundPath.replace(/(url\(['"]?|['"]?\))/gi,'');

      this.style.backgroundImage = 'none';
      this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ backgroundPath +"',sizingMethod='scale')";
   });

}
