jQuery(function($) {
   
  /* ---------------------------------------------------------------- 
  	cufon - replace fonts
  ---------------------------------------------------------------- */
  Cufon.replace('#content h1, #aside h3, #aside legend, .tz-hp h2');
  
  
  /* ---------------------------------------------------------------- 
  	search
  ---------------------------------------------------------------- */
  $('#search').focus(function () {
    // add class
    $(this).next('input').addClass('hover');
    // remove text
    var defaultValue = $(this).val();
    $(this).val('');
    $(this).blur(function() {
      // remove class
      $(this).next('input').removeClass('hover');
      // add text
      if ($.trim(this.value) == '') {
        $(this).val(defaultValue);
      }
    });
  });
  
  
  /* ---------------------------------------------------------------- 
  	menu
  ---------------------------------------------------------------- */
  $('#menu ul ul, #menu ul ul div').hide();
  
  $('#menu > ul > li').hoverIntent({
    interval: 30,
    timeout: 500,
    over: function() {
      $('ul', this).stop().slideDown(250);
    },
    out: function() {
      $('ul', this).stop().slideUp(250, function() { $(this).css({'height': 'auto'}); });
    }
  });
  $('#menu ul ul > li').hoverIntent({
    interval: 100,
    timeout: 100,
    over: function() {
      $('div', this).stop().css({'opacity': 0}).show().fadeTo('normal', 1);
    },
    out: function() {
      $('div', this).stop().fadeTo('normal', 0, function() { $(this).hide() });
    }
  });
  
  
  /* ---------------------------------------------------------------- 
    lightbox - gallery
  ---------------------------------------------------------------- */
  $('a.gallery, a[rel=thumbnail]').fancybox({
                    'titleShow'     : false
        });
  
  
  /* ---------------------------------------------------------------- 
    hAccordion
  ---------------------------------------------------------------- */
  $('#haccordion div.wrap1').hide();
  $('#haccordion > li').hoverIntent({
    interval: 150,
    timeout: 10,
    over: function() {
      $('#haccordion').height(350);
      $('div.wrap1', this).stop().css({'opacity': 0}).show().fadeTo('fast', 1);
    },
    out: function() {
      $('div.wrap1', this).stop().fadeTo('fast', 0, function() { 
        $(this).hide();
        $('#haccordion').height(76);
      });
    }
  });
  
  $('#haccordion').hAccordion({itemOffset: 83});
  
  
  /* ---------------------------------------------------------------- 
    selected plugin
  ---------------------------------------------------------------- */
  $('.model-color').selected();
  $('#models, #models-left, #models-right').selected({
    target: 'a',
    addedClass: 'selected',
    number: 1
  });
  $('#variants, #motors, #interier').selected({
    target: 'li.mark',
    addedClass: 'selected'
  });
  $('#wheels, #colors').selected({
    target: 'tr',
    addedClass: 'selected'
  });
  $('.accessories').selected({
    target: 'tr',
    addedClass: 'selected',
    number: 0
  });
  $('#pomocnik').selected({
    target: 'li',
    addedClass: 'selected',
    number: 2
  });
  
  /* ---------------------------------------------------------------- 
    konfigurator
  ---------------------------------------------------------------- */
  var cont = $('#konf-content').height() + parseInt($('#konf-content').css('padding-top')) + parseInt($('#konf-content').css('padding-bottom'));
  var nextTop = $('.konf-next-top').height() + parseInt($('.konf-next-top').css('padding-top')) + parseInt($('.konf-next-top').css('padding-bottom'));
  var nextBottom = $('.konf-next-bottom').height() + parseInt($('.konf-next-bottom').css('padding-top')) + parseInt($('.konf-next-bottom').css('padding-bottom'));
  
  $('.konf-panel-text').height(cont - (nextTop + nextBottom));
  
  
  /* ---------------------------------------------------------------- 
    tabs
  ---------------------------------------------------------------- */
  $('.tabs').tabs();
  
  
  /* ---------------------------------------------------------------- 
    safety
  ---------------------------------------------------------------- */
  $('#safety').safety();
  
  
  /* ---------------------------------------------------------------- 
    click toggle box
  ---------------------------------------------------------------- */
  $('.click-box').hide();
  $('.click').click(function() {
    $(this).next('.click-box').toggle(250);
    return false;
  });
  
  
  /* ---------------------------------------------------------------- 
    ie6
  ---------------------------------------------------------------- */
  ie6 = $.browser.msie && $.browser.version < 7;
  
  
  /* ---------------------------------------------------------------- 
    odkazy do noveho okna
  ---------------------------------------------------------------- */
  $("a[href^=http]").each(function() {
    if(this.href.indexOf(location.hostname) == -1) {
      $(this).click(function(){window.open(this.href);return false;});
    }
  });
  $("a[href$=pdf]").click(function(){window.open(this.href);return false;});
  
  
  /* ---------------------------------------------------------------- 
    priceFormat
  ---------------------------------------------------------------- */
  $.fn.priceFormat = function() {
    return $(this).text().replace('.', ',');
  };
  
  
  /* ---------------------------------------------------------------- 
    collapser - otevirani a zavirani boxu
  ---------------------------------------------------------------- */
  $('body').collapser({
    autoClose: true,
    duration: 300
  });
  
  
  /* ---------------------------------------------------------------- 
    print - nahled tisku
  ---------------------------------------------------------------- */
  $('#print-page').click(function() {
    if (ie6) {
      window.print();
    } else {
      window.open(this.href,'print','width=800,height=600,menubar=yes,scrollbars=yes,resizable=no,top=50,left=100'); 
    }
    return false; 
  });
  if (document.location.hash && (document.location.hash == '#print')) {
    $printStyle = $('link[media=print]');
    $('link[rel=stylesheet]').attr('media', 'none');
    $printStyle.attr('media', 'screen, print')
  }
  
  
  /* ----------------------------------------------------------------
    facebook
  ---------------------------------------------------------------- */
  $("#facebook-footer").click(function() {
    window.open(this.href,"_blank","width=620,height=440,scrollbars=true");
    return false;
  });
  
  
  /* ----------------------------------------------------------------
    detection iPod, iPhone, iPad
  ---------------------------------------------------------------- */
  var isiPad = navigator.userAgent.match(/iPad/i) != null; 	
  var isiPhone = navigator.userAgent.match(/iPhone/i) != null; 	
  var isiPod = navigator.userAgent.match(/iPod/i) != null;
  
  
  /* ----------------------------------------------------------------
    homepage flash banners - replace with image for iPhone and iPad
  ---------------------------------------------------------------- */
  if (isiPad || isiPhone || isiPod) {
    $('#hp-file p').hide();
    $('#hp-file img').show();
  }
  
  
});





$(document).ready( function() {
    $(".auto-defaults textarea, .auto-defaults input[type=text]").each( function(index) {
        if( '' == $(this).val() || $(this).attr('title') == $(this).val() ) {
            $(this).val( $(this).attr('title') );
            $(this).addClass('default');
        }
        $(this).focus( function() {
            if( $(this).attr('title') == $(this).val() ) {
                $(this).val('');
                $(this).removeClass('default');
            } 
        });
        $(this).blur( function() {
            if( '' == $(this).val() ) {
                $(this).val( $(this).attr('title') );
                $(this).addClass('default');
            } 
        });
    });
});

