$(document).ready(function() {

  $('.thumb').click(function() {
    itemId = $(this).attr('id');
    thumbSrc = $(this).attr('src');
    previewSrc = str_replace(thumbSrc, 'thumb_', 'preview_');
    originSrc = str_replace(thumbSrc, 'thumb_', 'origin_');
    $('#special-preview-img-' + itemId).attr('src', previewSrc);
    $('#special-preview-img-link-' + itemId).attr('href', originSrc);
  });

  $('#special-section-link').fancybox({'width':800, 'height':520});  

  $('#top-menu-item-tech').mouseover(function() {
    $('.popup-menu').show();
  });

  $('.left-col').mouseover(function() {
    $('.popup-menu').hide();
  });

  $('.header').mouseover(function() {
    $('.popup-menu').hide();
  });

  $('.content').mouseover(function() {
    $('.popup-menu').hide();
  });

  $('.popup-menu').mouseover(function() {
    $('li', this).mouseover(function() {
      $('.popup-menu-level-2', this).show();
      $('li', this).mouseover(function() {
        $('ul', this).show();
      });
      $('li', this).parent().mouseout(function() {
        $('ul', this).hide();
      });
    });
  });

  $('.popup-menu').mouseout(function() {
    $('.popup-menu-level-2', this).hide();
  });

  setInterval(specialTic, 800);

})

specialTic = function() {
  if ($('#special-section-link').css('display') == 'none') {
    $('#special-section-link').show();
  } else {
    $('#special-section-link').hide();    
  }
}

str_replace = function(haystack, needle, replacement) {
  var temp = haystack.split(needle);
  return temp.join(replacement);
}