$j = jQuery.noConflict();
$j(function(){
  
  
  var agent=navigator.userAgent.toLowerCase();
  var is_iphone = ((agent.indexOf('iphone')!=-1));
  if (is_iphone) {
    $j('#main-nav li.last big').each(function(){
      var telNo = $j(this).text().replace(/\(.*\)/,'').replace(/\s+/g,'');
      $j(this).parent().parent().attr('href', 'tel:' + telNo);
    });
  }

  
  
  if($j('.subcate-list')) {
    $j('.subcate-list ul li:odd').addClass('list-end');
  }
  
  if($j('.sub-nav ul li ul.clearfix')){
    $j('.sub-nav ul li ul.clearfix').find('li').each(function(){
      if($j(this).find('ul').children().size()) {
        $j(this).addClass('subchild');
      }
    });
  }
  
  // slider
  if($j('.slider-body')) {
    iObj = $j('.scrollable .items');
    sObj = $j('.scrollable');
    /**$j('.scrollable').find('a').each(function(){
      if($j(this).html().length < 1) {
        $j(this).remove();
      }
    });**/
    
    $j('.scrollable').scrollable({
      circular: true
    }).navigator({
      'navi': '.scroll-nav'
    }).autoscroll({
      interval: 6000,
      autoplay: true
    });
    $j('.scrollable .items').children('.csc-default').each(function(){
      if($j(this).find('.with-background').children().size()) {
        var bgImage = $j(this).find('.with-background').find('img').attr('src');
        $j(this).attr('style', 'background-image: url('+bgImage+');');
      }
    });
  }
  $j('#main-nav li').mouseover(function(){
    if($j(this).next().is('li')) {
      $j(this).next().children('a').addClass('hideline');
    }
  }).mouseout(function(){
    if($j(this).next().is('li')) {
      $j(this).next().children('a').removeClass('hideline');
    }
  });
  
  $j('#main-nav li').each(function(){
    if($j(this).hasClass('active')) {
      $j(this).next().children('a').addClass('hideline');
    }
  });
  
  if($j('.bm_sitemap')) {
    
    var blockMaxHeight = 100;
    var blocksNum = $j('ul.level_1').size();
    var tmpArray = new Array();
    
    for(var _bi = 0; _bi < blocksNum; _bi++) {
      if(tmpArray.length == 4) {
        tmpArray = [];
      }
      tmpArray.push(_bi);     
      blockMaxHeight = Math.max($j('ul.level_1').eq(_bi).innerHeight(), blockMaxHeight);
      if(_bi % 4 != 3) {
        $j('ul.level_1').eq(_bi).css('margin-right', '21px');
      } else {
        for(var i = 0; i < 4; i++) {
          $j('ul.level_1').eq(tmpArray[i]).height(blockMaxHeight);
        }
        blockMaxHeight = 100;
      }
    }
    if(tmpArray.length < 4) {        
        for(var i = 0; i < tmpArray.length; i++) {
          $j('ul.level_1').eq(tmpArray[i]).height(blockMaxHeight);
        }  
    }
    $j('.hasAccessRights').each(function(){
      $j('<span></span>').appendTo($j(this));
    });
  }
  
  if($j('.tx-irfaq-pi1').children('dl').size()) {
    var hashClass = window.location.hash.substring(1);
    $j('.' + hashClass).parent().click();
  }
  
  if($j('.login-hover-title').is('h2')) {
    $j('.login-hover-title').hover(function(){
      $j(this).next().show();
    });
    $j('.login-hover-title').next().hover(function(){
    },function(){
      $j(this).hide();
    });
  }
  
});
