if(typeof calendars == 'undefined')
  calendars = [];


// *****************
// * Tracking clicks within the page
// *****************
$(document).ready(function() {
  $('a').live('click', function () { // track events (external link click, mailto click, pdf click)
    if(typeof settings_google_analytics_code != 'undefined' && typeof _gat != 'undefined'){
      //_gaq.push(['_trackPageview'], $(this).attr('href'));
      var filetypes_track = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
      var pageTracker = _gat._getTracker(settings_google_analytics_code);
      var href = $(this).attr('href');
      if(typeof href != 'undefined') {
        if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
          var extLink = href.replace(/^https?\:\/\//i, '');
          pageTracker._trackEvent('External', 'Click - external link', extLink);
        }else if (href.match(/^mailto\:/i)){
          var mailLink = href.replace(/^mailto\:/i, '');
          pageTracker._trackEvent('Email', 'Click - mailto', mailLink);
        }else if (href.match(filetypes_track)){
          var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
          filePath = href.replace(new RegExp('^https?\:\/\/'+document.domain+'\/', "i"), '/');
          pageTracker._trackEvent('Download', 'Click - ' + extension, href);
        }
      }
    }
  });
});


// ***********************
// * Universal functions *
// ***********************
/**
  * parseClassToObject(): parses element's class and returns known elements as array
  * @param String prefix: class prefix
  * example:
  *  elements class = 'blah--name--value blah--name2--val'
  *  out = $(element).parseClassToObject('blah')
  *  output: object:{name: 'value', name2: 'val'};
*/
(function(cash) {$.extend($.fn, {
  parseClassToObject: function (prefix) {
    out = {};
    cl = $(this).attr('class');
    if(typeof cl == 'undefined')
        $(this).attr('className');
    if(typeof cl != 'undefined' && cl.length > 0) {
      classes = cl.split(' ');
      reg=/^\-\-(.*)$/;
      for(i=0;i<classes.length;i++) {
        cl = $.trim(classes[i]);
        if(cl.indexOf(prefix) == 0){
          cl = cl.substr(prefix.length);
          if((preg = reg.exec(cl)) && preg[1].length > 0) {
            pos = preg[1].indexOf('--');
            if(pos > 0) {
              out[unescape((''+preg[1]).substr(0, pos))] = unescape((''+preg[1]).substr(pos+2));
            } else {
              out[out.length] = unescape(preg[1]);
            }
          }
        }
      }
    }
    return out;
  },
  parseClassToArray: function (prefix) {
    out = {};
    cl = $(this).attr('class');
    if(typeof cl == 'undefined')
      cl = $(this).attr('className');
    if(typeof cl != 'undefined' && cl.length > 0) {
      classes = cl.split(' ');
      reg=/^\-\-(.*)$/;
      for(i=0;i<classes.length;i++) {
        cl = $.trim(classes[i]);
        if(cl.indexOf(prefix) == 0){
          cl = cl.substr(prefix.length);
          if((preg = reg.exec(cl)) && preg[1].length > 0) {
            pos = preg[1].indexOf('--');
            if(pos > 0) {
              out[unescape((''+preg[1]).substr(0, pos))] = unescape((''+preg[1]).substr(pos+2));
            } else {
              out[out.length] = unescape(preg[1]);
            }
          }
        }
      }
    }
    return out;
  },
  changeBanner: function (speed, where) {
    if(typeof where == 'undefined' || where == null)
      where = 1;
    cur_i = 0;
    cont = $(this).find('.bannerItem.item-shown').parent();
    children = cont.children();
    n = $('.bannerItem.item-shown');
    if(where > 0) {
      n = $(this).find('.bannerItem.item-shown').next('.bannerItem');
      if(n.length == 0 && $(this).find('.bannerItem.item-shown').length > 0) {
        for(i=$.inArray($(this).find('.bannerItem.item-shown').get(0), children)+1;i<children.length;i++) {
          if($(children[i]).hasClass('bannerItem') && ++cur_i == where){
            n = $(children[i]);
            break;
          }
        }
      }
      if(typeof n == 'undefined' || n == null || n.length == 0) {
        n = $(this).children('.bannerItem').filter(':eq(0)');
      }
    } else if (where < 0) {
      n = $(this).find('.bannerItem.item-shown').prev('.bannerItem');
      if(n.length == 0 && $(this).find('.bannerItem.item-shown').length > 0) {
        for(i=$.inArray($(this).find('.bannerItem.item-shown').get(0), children)-1;i>=0;i--) {
          if($(children[i]).hasClass('bannerItem') && --cur_i == where){
            n = $(children[i]);
            break;
          }
        }
      }
      if(typeof n == 'undefined' || n == null || n.length == 0) {
        n = $(this).children('.bannerItem').filter(':last');
      }
    }
    sibl=$(this).find('.bannerItem.item-shown')
    if ($(this).find('.bannerItem').length > 1 || $('.bannerItem.item-shown').length == 0) {
      sibl.fadeOut(speed).removeClass('item-shown');
      n.stop(true, true).addClass('item-shown').fadeIn(speed);
      items = $(this).children('.bannerItem');
      change_function = $(this).data('change_function');
      if(typeof change_function == 'function') {
        change_function(this, n);
      }
      //$(this).find('.page_number').html(($.inArray(n.get(0), items)+1) + '/' + items.length);
    }
    return this;
  },
  getChildrenWidth: function () {
    children = $(this).children();
    total = 0;
    for(i=0;i<children.length;i++) {
      total += $(children[i]).width()+parseInt($(children[i]).css('marginLeft'))+parseInt($(children[i]).css('marginRight'))+parseInt($(children[i]).css('paddingLeft'))+parseInt($(children[i]).css('paddingRight'));
    }
    return total;
  }
})}) (jQuery);
function add_param_to_url(href,myvar,myvalue){
  return href + ((href.indexOf('?')>0) ? '&' : '?')+myvar+"="+escape(myvalue);
}

$(document).ready(function (){
  $('.flash_in_popup.video-vimeo .video_image').click(function () {
    params = $(this).parseClassToArray('params');
    src = params['src'];
    width = params['width'];
    height = params['height'];
    $('#video_fancy_container').remove();
    title = typeof params['name'] != 'undefined' ? params['name'] : '';
    $('<div id="video_fancy_container"><div><iframe style="width: '+width+'px; height: '+height+'px; border: 0px;" src="'+src+'" id="video_fancy_container_inner"></iframe></div><h2>'+title+'</h2></div>').css({display: 'none'}).appendTo('BODY');
    $('<a href="#video_fancy_container"></a>').fancybox({transitionIn: 'elastic', hideOnContentClick: false, overlayOpacity: 0.7, frameHeight: height, frameWidth: width, callbackOnClose: function () {
      $('#fancy_div').attr('innerHTML','');
      if(typeof soundManager  != 'undefined') soundManager.play('mySound');
    }}).click();
    if(typeof soundManager  != 'undefined') soundManager.stop('mySound');
    $(window).oneTime(450, function () {
      $(window).resize();
    });
    $('#video_container, body>#video_fancy_container').remove();
  });
  $('.flash_in_popup .video_image').bind('click', function () {
    if($(this).parents('.flash_in_popup').is('.video-vimeo'))
      return;
    /* we need to show this in lightbox */
    params = $(this).parseClassToArray('params');
    src = params['src'];
    width = params['width'];
    height = params['height'];
    delete params['src'];
    delete params['width'];
    delete params['height'];
    var sa = new SWFObject(src, "vflash-video-container-popup", width, height,"9");
    for (i in params) {
      if(typeof params[i] == 'string')
        sa.addParam(i, params[i]);
    }
    title = '';
    $('<div id="video_fancy_container"><div id="video_fancy_container_inner"></div><div class="description"><h2>'+title+'</h2></div>').css({display: 'none'}).appendTo('BODY');
    $('<a href="#video_fancy_container"></a>').fancybox({hideOnContentClick: false, height: params['height'], frameHeight: params['height'], width: params['width'], frameWidth: params['width'], callbackOnClose: function () {
      $('#fancy_div').attr('innerHTML','');
    }}).click();
    sa.write('video_fancy_container_inner');
    $('#video_container, body>#video_fancy_container').remove();
    return false;
  });
  /* menu autoresizing */
  if((container = $('.main_menu').filter(":eq(0)")).length > 0) {
    if(container.width() < $('.page_menu').width()-41) // 40 = margin-left + margin-right of .main_menu + 1px?
      total_w = $('.page_menu').width()-41; // IE6 must rely on menu ul container
    else
      total_w = container.width();
    children_width_new = container.getChildrenWidth();
    addPadding = Math.floor((total_w - children_width_new) / (container.children().length * 2));
    children = container.children();
    children_width_new = 0;
    for(i=0;i<children.length;i++) {
      $(children[i]).find('A').each(function () {
        if($(this).parents('.submenu').length == 0) {
          padd = {paddingLeft: parseInt($(this).css('paddingLeft')) + addPadding, paddingRight: parseInt($(this).css('paddingRight'))+addPadding};
          $(this).css(padd);
          children_width_new += $(children[i]).outerWidth();
        }
      });
    }
    children_width_new = container.getChildrenWidth();
    to_add = total_w - children_width_new;
    child = children[0];
    paddingPlace = 'paddingLeft';
    while(to_add > 0 && child) {
      $(child).children().filter('A').each(function () {
        if($(this).parents('.submenu').length == 0) {
          if(to_add > 1) {
            $(this).css(paddingPlace, parseInt($(this).css(paddingPlace)) + 1);
          }
          to_add --;
        }
      });
      child = $(child).next();
      if(child == null || typeof child == 'object' && typeof child.length != 'undefined' && child.length == 0) {
        paddingPlace = 'paddingRight';
        child = children[0];
      }
    }
  }

});
function debug() {
  console.log.apply(null, arguments);
}

$(document).ready(function () {
  for(key in calendars) {
    // now lets init the calendar (jquery-ui)
      d = new Date();
    if(typeof calendars[key]['first_date'] == 'undefined') {
      st = [d.getFullYear() -1, 1, 1];
    } else {
      st = calendars[key]['first_date'].split('-');
    }
    if(typeof calendars[key]['last_date'] == 'undefined') {
      en = [d.getFullYear() + 2, 1, 1];
    } else {
      en = calendars[key]['last_date'].split('-');
    }
    min_date = new Date(st[0], st[1]-1, st[2], 0, 0, 1, 0);
    max_date = new Date(en[0], en[1]-1, en[2], 23, 59, 59, 999);
    conf = {hideIfNoPrevNext: true, showOtherMonths: true, selectOtherMonths:false, minDate: min_date, maxDate: max_date,  dayNamesMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S'], beforeShowDay: function (date) {
        key= this.id;
        selectable = true;
        class_name = "";
        tooltip = "";
        m = ""+(date.getMonth()+1); // starts at 0
        d = ""+date.getDate();
        if(m.length==1) m = "0"+m;
        if(d.length==1) d = "0"+d;
        date_str = date.getFullYear()+'-'+m+'-'+d+' 00:00:00';
        if(typeof calendars[key][date_str] != 'undefined') {
          curritem = calendars[key][date_str];
          class_name += ' type-'+curritem['types'].split(',').join(' type-');
          tooltip += curritem['names'].split('|').join("\n")
        }
      return [selectable, class_name, tooltip];
    }, onChangeMonthYear: function (year, month, picker) {
      //we need to ask for new data...
      key= picker.id;
      opts = {act: "update_calendar", ajax: "json", year: year, month: month, number_of_months: $('#'+key).datepicker('option', 'stepMonths'), key: key};
      opts.events_type = $('.events h2 .current').attr('id');
      $.get('/site/ajax.php', opts, function (tjson) {
        key= tjson.key;
        calendars[key] = $.extend(calendars[key], tjson.calendar_events);
        //this should be called at the end...
        $('#'+key).parents('LI:eq(0)').find('.list-items:eq(0)').html(tjson.list_items);
        $('#'+key).datepicker('refresh');

      }, 'json');
    }};
    if($('#'+key).parents('.homepage').length == 0 && $('#'+key).parents('.column-left').length == 0 && $('#'+key).parents('.column-right').length == 0) {
      conf.numberOfMonths = [3, 1];
      conf.stepMonths = 3;
    }
    $('#'+key).datepicker(conf);
  }
  $('.events h2 span, .events h1 span').click(function () {
    cont = $(this).parent().parent().find('ul.events-container');
    current = $(this).siblings('.current').removeClass('current');
    newcl=$(this).addClass('current').css('backgroundColor');
    $(this).css({backgroundColor: $(current).css('backgroundColor')})
    $(current).css({backgroundColor: newcl});
    now = cont.find('>li.'+$(this).attr('id'));
    now.css({position: 'absolute'});
    now.siblings().fadeOut().removeClass('tab-selected');
    now.fadeIn().addClass('tab-selected');;
    now.parent().css('height', now.css('height'));
  });
  $('ul.right-icons li').bind('mouseenter', function () {
    $(this).animate({marginLeft: "10px"}, 'slow');
  }).bind('mouseleave', function () {
    $(this).animate({marginLeft: "0px"}, 'slow');
  });
  $('.top_cover .banners').stopTime();
  cover = $('.top_cover .banners').everyTime(5000, function () {
    if(!$(this).hasClass('mouse-is-over')) {
      $(this).changeBanner('slow');
    }
  }).mouseover(function () {
    $(this).addClass('mouse-is-over');
  }).mouseout(function () {
    $(this).removeClass('mouse-is-over');
  });
  cover.find('.back').bind('click', function (e) {
    $('.top_cover .banners').changeBanner('slow', -1);
    return false;
  });
  cover.find('.next').bind('click', function (e) {
    $('.top_cover .banners').changeBanner('slow', 1);
    return false;
  });
  cover.data('change_function', function (banners, banner) {
    // now let's update the switcher
    //remove all classes
    counter = $(banners).find('.banner-counter');
    for(i in banners.find('.bannerItem')) {
      counter.removeClass('selected'+i);
    }
    items = banners.find('.bannerItem');
    counter.addClass('total'+items.length).addClass('selected'+$.inArray(banner.get(0), items));
  });
  cover.changeBanner('slow', 0);
  /* news animation */
  $(document).oneTime(2500, function () {
    $(document).everyTime(10000, 'news', function() {
      $('.column-right .news_list, .homepage .news_list, .documents.homepage_first .inBoxContent').each(function () {
        cont=$(this);
        if(cont.hasClass('mouse-is-over'))
          return ;
        if(cont.find('>:not(.featured)').length <= 1) {
          //there is not enough items to scroll with
          return ;
        }
        o = children = cont.find('>:not(.featured):eq(0)'); //cont1 children
        cont.css({height: cont.height(), overflow: 'hidden'});
        cl = $(o).clone(true);
        cl.fadeOut(0);
        cont.append(cl);
        cl.stop(true).fadeIn('slow');
        $(o).stop(true).fadeTo('slow', 0, function() {
          $(this).css({lineHeight: 1, fontSize: 1, height: $(this).height()});
          $(this).animate({height: 1}, 2000, function () {
            $(this).remove();
            $(this).parents('.news_list:eq(0), .inBoxContent').css('height', '');
          })
        });
      });
    });
  });
  $('.newsBox .boxContent').mouseover( function() {
    $(this).find('.news_list').addClass('mouse-is-over');
  });
  $('.newsBox .boxContent').mouseout( function() {
    $(this).find('.news_list').removeClass('mouse-is-over');
  });
  $('.side-events .calendars').accordion({header: 'h3', icons: {'header': '', 'headerSelected': ''}});
});
/**
  * slidingAds(): This will allow you to use ads from side
  *
  * available options:
  *   speed[='slow']: The speed of animations
  *   visible_selector[='div.visible']: selector (or element), which should be allways shown
  *   event[='mouse']: on which event you want to display the ad (mouse / click)
  *   event_originator[=&visible_selector]: Which selector / element should be clicked on (only for click), if empty, visible_selector is used
  *
  * example HTML:
  * <div class="sliding-adds2">
  *   <div class="hidden sliding-add from-bottom">
  *     <div class="visible">
  *       <a href="#" class="clicker buttons"></a>
  *       <a href="#id=1" class="close buttons"></a>
  *       Lorem ipsum dolor sit amet consectur adipiscing elit.
  *     </div>
  *     <div class="sliding-content">
  *       <img src="http://localhost/slider_image.png" />
  *       Proin scelerisque, turpis nec varius feugiat, orci ante consectur augue, sed molestie.
  *       <a href="http://localhost/Some-page.html" class="link-out">Click here</a>
  *     </div>
  *   </div>
  * </div>
  *
  * expected CSS:
  *  .sliding-add { position: absolute; }
 */

sliding_adds_elms = [];
(function(bb) {$.extend($.fn, {
  slidingAdsGetSizes: function () {
    if(typeof $.browser != 'undefined' && $.browser.msie && $.browser.version == '6.0') {
      return { ww: $(window).width(), wh:$(window).height(), sct: myParseInt($(document).scrollTop()), scl: myParseInt($(document).scrollLeft()) };
    }
    return { ww: $(window).width(), wh:$(window).height(), sct: /*myParseInt($(document).scrollTop())*/0, scl: /*myParseInt($(document).scrollLeft())*/0 };
  },
  slidingAds: function(opts) {
    // setup the options
    if (typeof $.browser == 'undefined') {
      alert('Error: jQuery.browser is not supported anymore, slidingAds will fail in IE6');
    }
    if (typeof $.browser != 'undefined' && $.browser.msie && $.browser.version == '6.0') {
      $(this).css('position', 'absolute');
    } else {
      $(this).css('position', 'fixed');
    }
    options = $.extend({}, {speed: 'slow', displayOpened: false, visible_selector: 'div.visible', event: 'mouse'}, opts);
    if(typeof options.event_originator != 'string' && typeof options.event_originator != 'object') { options.event_originator = options.visible_selector; }

    if(typeof $.browser != 'undefined' && $.browser.msie && $.browser.version == '6.0') {
      //we need this only for browsers not supporting position: fixed (IE6)
      // link the resize function to scroll
      $(window).scroll(function (e) {
        $(window).resize();
      });
    }

    // we need this because of window size change
    $(window).resize(function () { // calculate new position of the ads, when the window changes
      sliding_adds_elms = $('div.sliding-ad');
      sizes=$(this).slidingAdsGetSizes(); ww=sizes.ww; wh=sizes.wh; sct=sizes.sct; scl=sizes.scl;
      ow = $(document).find('#alldocs').outerWidth(); oh = $(document).find('#alldocs').outerHeight();
      if(scl+ww+1 >= ow) { $(window).scrollLeft(ow - ww); }
      if(sct+wh+1 >= oh) { $(window).scrollTop(oh - wh); }
      sliding_adds_elms.each(function () {
        otpions = $(this).data('options');
        vis = $(this).find('.visible');
        h=myParseInt($(this).outerHeight());
        w=myParseInt($(this).outerWidth());
        vis = $(this).find(options.visible_selector);
        vh=vis.outerHeight();
        vw=vis.outerWidth()
        if(!$(this).hasClass('small')) {
          if($(this).hasClass('from-left')){ opts = { left: scl+w, width: w };
          } else if ($(this).hasClass('from-right') ) { opts = { left: scl+ww-w, width: w };
          } else if ($(this).hasClass('from-top') ) { opts = { top: sct, height: h };
          } else { opts = { top: sct+wh-h, height: h }; }
        } else {
          if($(this).hasClass('from-left')){ opts = { left: scl+vw, width: vw };
          } else if ($(this).hasClass('from-right') ) { opts = { left: scl+ww-20, width: 20 };
          } else if ($(this).hasClass('from-top') ) { opts = { top: sct-(h-vh), height: h }
          } else { opts = { top: sct+wh-vh, height: vh }; }
        }
        $(this).stop(true, true).css(opts);
      });
    });

    // set the event
    if(options.event == 'click') {
      o=$(options.event_originator, this).data('sliding_ad', this);
      if(o.length==0)
        o = $(opts.event_originator);
      if(o.length!=0)
        o.click(function () {
          s=$(this).parents('.sliding-ad');
          s.trigger(s.hasClass('full') ? 'hide' : 'show');
          return false;
        });
    } else {
      $(this).mouseenter(function () {
        $(this).trigger('show');
      }).mouseleave(function () {
        $(this).trigger('hide');
      })
    }

    // now apply the ad settings
    out = $(this).data('options', options).each(function () {

      // init function
      options = $(this).data('options');
      $(this).css('zIndex', 5);
      style = opts = {};
      $(this).css({overflow: 'hidden', display: ''}).removeClass('hidden');
      vis = $(this).find(options.visible_selector);
      h=0;$(this).children().each(function() { h+= myParseInt($(this).outerHeight()); });
      w=0;$(this).children().each(function() { w+= myParseInt($(this).outerWidth()); });
      sizes=$(this).slidingAdsGetSizes(); ww=sizes.ww; wh=sizes.wh; sct=sizes.sct; scl=sizes.scl;
      vh=vis.outerHeight();
      vw=vis.outerWidth()
      if($(this).hasClass('from-left')){ style = { left: scl-(w-vw), width: (w-vw) }; opts = { left: scl-(w-vw), width: w }; }
      else if ($(this).hasClass('from-right') ) { style = { left: scl+ww, width: 0 }; opts = { left: scl+ww-vw, width: vw }; }
      else if ($(this).hasClass('from-top') ) { style = { top: sct-(h-vh), height: (h-vh) }; opts = { top: sct-(h-vh), height: h }; }
      else { style = { top: sct+wh, height: 0 }; opts = { top: sct+wh-vh, height: vh }; }
      style.display="block";
      $(this).data('offset_top', $(document).scrollTop());
      $(this).css(style).animate(opts, options.speed, function () {
        $(this).addClass('small');
      });
    }).bind('show', function () {

      // show function
      options = $(this).data('options');
      vis = $(this).find(options.visible_selector);
      h=0;$(this).children().each(function() { h+= myParseInt($(this).outerHeight()); });
      w=0;$(this).children().each(function() { w+= myParseInt($(this).outerWidth()); });
      sizes=$(this).slidingAdsGetSizes(); ww=sizes.ww; wh=sizes.wh; sct=sizes.sct; scl=sizes.scl;
      if($(this).hasClass('from-left')){ opts = { left: scl, width: w };
      } else if ($(this).hasClass('from-right') ) { opts = { left: scl+ww-(w/2), width: w/2 };
      } else if ($(this).hasClass('from-top') ) { opts = { top: sct, height: h };
      } else { opts = { top: sct+wh-h, height: h }; }
      style.display="block";
      $(this).animate(opts, options.speed, function () {
        $(this).removeClass('small').addClass('full');
      });
    }).bind('hide', function () {

      // hide function
      options = $(this).data('options');
      vis = $(this).find(options.visible_selector);
      h=0;$(this).children().each(function() { h+= myParseInt($(this).outerHeight()); });
      w=0;$(this).children().each(function() { w+= myParseInt($(this).outerWidth()); });
      sizes=$(this).slidingAdsGetSizes(); ww=sizes.ww; wh=sizes.wh; sct=sizes.sct; scl=sizes.scl;
      vh=vis.outerHeight();
      vw=vis.outerWidth();
      if($(this).hasClass('from-left')){ opts = { left: scl-(w-vw), width: w };
      } else if ($(this).hasClass('from-right') ) { opts = { left: scl+ww - 20, width: 20};
      } else if ($(this).hasClass('from-top') ) { opts = { top: sct-(h-vh), height: h };
      } else { opts = { top: sct+wh-vh, height: vh }; }
      $(this).animate(opts, options.speed, function () {
        $(this).removeClass('full').addClass('small');
      });
    }).bind('destroy', function () {

      // hide the ad completely
      return $(this).fadeOut('slow', function () {
      });
    }).bind('reinit', function () {

      // show the ad again
      return $(this).fadeIn('slow', function () {
      });
    });

    // show whole ad, when requested
    if(options.displayOpened) {
      $(this).stop(true).trigger('show');
    }

    return out;
  }
});
/* -- end of slidingAds */
})(jQuery);
/*
 * Call back function for advanced sliding Ad feature
*/
function sliding_ad_close_click () {
  xdisabled_sliders = getCookie('disabled_sliders');
  if(typeof disabled_sliders != 'string') disabled_sliders = '';
  if(preg=/id=([0-9]+)/.exec($(this).attr('href'))) {
    if(!$.inArray(preg[1], disabled_sliders.split(',')) != -1) {
      d=new Date();
      setCookie('disabled_sliders', (disabled_sliders.length > 0 ? disabled_sliders+',':'')+preg[1]);
      $(this).parents('.sliding-ad:eq(0)').trigger('destroy');
    }
  }
  return false;
}

/* myParseInt(): this will never return non-int type, not even NaN */
function myParseInt(i) {
  o = 0;
  if(typeof i != 'string' || typeof i != 'number')
    o = isNaN(parseInt(i)) ? 0 : parseInt(i);
  return isNaN(o) ? 0 : o;
}

/* helper cookie functions for sliding_ad_close_click() function */

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) {
      tempstr = unescape(c.substring(nameEQ.length,c.length));
      //* replace all + with ' ' space - because of different interpretation in PHP
      while(tempstr.match(/\+/))
        tempstr = tempstr.replace(/\+/,' ');
      return tempstr;
    }
  }
  return null;
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=-1" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}
$(document).ready(function () {
  $(document).oneTime(500, function () {
    $('.sliding-ad').slidingAds({event: 'click', displayOpened: true,
      event_originator: '.clicker'}).find('.close').click(sliding_ad_close_click);
  });
  $(document).oneTime(500, function () {
    $('.main-left-icons').css({width: '0px', left: 0}).animate({width: 28, left: -28})
  });
});
