function mycarousel_itemLoadCallback(carousel, state)
{
    // Since we get all URLs in one file, we simply add all items
    // at once and set the size accordingly.
    if (state != 'init')
        return;
 
    jQuery.get('portfolio.txt', function(data) {
        mycarousel_itemAddCallback(carousel, data);
        $('.ligthbox').lightBox();
    });
};
 
function mycarousel_itemAddCallback(carousel, data)
{
    // Simply add all items at once and set the size accordingly.
    var items = data.split('|');
 
    for (i = 0; i < items.length; i++) {
        carousel.add(i+1, mycarousel_getItemHTML(items[i]));
    }
 
    carousel.size(items.length);
};
 
/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    var partItems = item.split('~');
    var url = partItems[4] ? '<p><strong>URL:</strong> <a href="http://' + $.trim(partItems[4]) + '" title="Přejít na tento web (otevře se v novém okně nebo záložce)" target="_blank">' + $.trim(partItems[4]) + '</a></p>' : '';
    
    var itemContent = '<div class="item"><div class="left"><h3>' + $.trim(partItems[0]) + '</h3><p>' + $.trim(partItems[1]) + '</p><p><strong>Technologie:</strong> ' + $.trim(partItems[2]) + '</p>' + url + '</div><a href="./images/portfolio-' + $.trim(partItems[3]) + '-big.jpg" title="' + $.trim(partItems[0]) + ' &ndash; ' + $.trim(partItems[1]) + '" class="ligthbox"><img src="./images/portfolio-' + $.trim(partItems[3]) + '.jpg" width="695" height="164" alt="" /></a></div>';
    
    return itemContent;
};

function mycarousel_initCallback(carousel)
{
   
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
 
$(document).ready(function() {
    $('#mycarousel').jcarousel({
        itemLoadCallback: mycarousel_itemLoadCallback,
        visible: 1,
        animation: 1000,
        auto: 10,
        wrap: "last",
        scroll: 1,
        initCallback: mycarousel_initCallback
    });
    
    if (!/msie|MSIE 6/.test(navigator.userAgent)) {
      $("header").css("position","fixed");
      $("#content").css("padding-top","150px");
      $("#content .up").css("visibility", "hidden");
    
      $('#linkHome').css('visibility', 'hidden').css('opacity', '0');
      $('#linkHome, #logo a').click(function(){
        $('#linkHome').animate({opacity: 0}, 500, function(){$('#linkHome').css('visibility', 'hidden');});
      });
      
      if($.cookie("tipmenu") != "no") {
        var timeout = setTimeout("showTip()", 5000);
      }
    }
       
    var clicked = false;
    $("nav a, #logo a").click(function(event){
      event.preventDefault();
      $('.menuTip').animate({opacity: 0}, 500, function(){$(this).css('display', 'none');});
      $.cookie("tipmenu", "no", { expires: 30, path: "/" });
      var id = $(this).attr("href").replace('#','');
      scrollWin(id);
      clearTimeout(timeout);
    });
});

var scrolling = false;

function scrollWin(id){
  
  if(scrolling == false){
    scrolling = true;
    if($.browser.opera){$('html').animate({
      scrollTop: $("#" + id).offset().top-160},
      500,
      function(){
        scrolling = false;
        if (id != "home")
          $('#linkHome').css('visibility', 'visible').animate({opacity: 1}, 500);
      }
    );} else $('html,body').animate({
      scrollTop: $("#" + id).offset().top-160},
      500,
      function(){
        scrolling = false;
        if (id != "home")
          $('#linkHome').css('visibility', 'visible').animate({opacity: 1}, 500);
    });
  }
  $('nav a').css('font-weight', 'normal');
  $('#link'+id).css('font-weight','bold');
}

function showTip() {
  $('<img/>', {
    "class": "menuTip",
    "src": "./images/menu-tip.gif",
    "alt": "TIP: navigace v rámci stránky"
  }).appendTo('#tip');
  $('.menuTip').animate({opacity: 1}, 500);
}


