$(function() {

  /* ----------------------------------------------------------------
    Browsers and versions
  ---------------------------------------------------------------- */
  var isIE = ($.browser.msie);
  var isOpera = ($.browser.opera);
  
  $('#nav-id-1 > a').css('zoom', '1'); // fix for ie7

  $('#header-links > span').hover(function() {
    $('#header').css('z-index', 100);
  }, function() {
    $('#header').css('z-index', 10);
  })
  

  /* ----------------------------------------------------------------
    external links
  ---------------------------------------------------------------- */
  $("a[href^=http]").each(function() {
    if ((this.href.indexOf(location.hostname) == -1) && ($(this).has('img').length == 0)) {
      $(this)
        .addClass('external')
        .click(function() {
          window.open(this.href);
          return false;
        });
    }
  });
  $("a[href$=pdf], a.external-link").click(function() {
    window.open(this.href);
    return false;
  });


  /* ----------------------------------------------------------------
    files
  ---------------------------------------------------------------- */
  $('a[href$=.pdf], a[href$=.jpg], a[href$=.tif], a[href$=.gif], a[href$=.png], a[href$=.ai], a[href$=.eps], a[href$=.txt], a[href$=.docx], a[href$=.xls], a[href$=.doc], a[href$=.mpg], a[href$=.zip]').addClass('file');
  $('a[href$=.gif], a[href$=.png]').addClass('img');
  $('a[href$=.jpg]').addClass('jpg');
  $('a[href$=.ai]').addClass('ai');
  $('a[href$=.mpg]').addClass('mpg');
  $('a[href$=.zip]').addClass('zip');
  $('a[href$=.pdf]').addClass('pdf');
  $('a[href$=.xls]').addClass('xls');
  $('a[href$=.docx], a[href$=.doc]').addClass('word');
  
  
  /* ----------------------------------------------------------------
    striped tables
  ---------------------------------------------------------------- */
  $('table tr:odd').addClass('odd');
  $('table thead .odd, table tfoot .odd').removeClass('odd');
  
  
  /* ----------------------------------------------------------------
    print page
  ---------------------------------------------------------------- */
  /*$('#footer p.flr a:last').after(' | <a href="#" class="print">'+ printName +'</a>').next('.print').click(function() {
    window.print();
    return false;
  });*/


  /* ----------------------------------------------------------------
  	homepage banners
  ---------------------------------------------------------------- */
  var $cycle = $('#hp-banner > div'),
      $navLinks = $('#hp-banner > ul a');
  
  if ($navLinks.size() > 1) {
    $cycle.cycle({
      before: function() {
        $navLinks.removeClass('selected');
        $('a[href=#'+ this.id +']').addClass('selected');
      }
    });
    $navLinks.each(function(i) {
      $(this).click(function() {
        $cycle.cycle(i).cycle('pause');
        return false;
      });
    });
  } else {
    $('#hp-banner > ul').hide();
  }


  /* ----------------------------------------------------------------
  	homepage products
  ---------------------------------------------------------------- */

var boxSizes = [ 80, 100, 160, 100, 80 ];
var boxPositions = [ 0, 105, 230, 415, 540 ];
var boxOffsets = [ 0, 10, 20, 10, 0 ];

$('#hp-prd li').each( function(i) {
    $(this).attr('position', i );
    });

$('#hp-prd span.button').click( function() {
    var direction = $(this).attr('class');

    $('#hp-prd li').each( function() {
        var pos = parseInt( $(this).attr('position') );
        
        if( direction == 'button go-right' ) {
            pos = pos + 1;
            if( pos == 5 ) {
                pos = 0;
      }
        } else if ( direction == 'button go-left' ) {
            pos = pos - 1;
            if( pos == -1 ) {
                pos = 4;
        }
        }
        
        $(this).attr('position', pos );
        $(this).animate({
            'width': boxSizes[pos] + 'px',
            'left': boxPositions[pos],
            'top': boxOffsets[pos]
        }, function() {
          animation = false;
        });

        $(this).find('> a > img').animate({
            'width': boxSizes[pos] + 'px'
        }, function() {
          animation = false;
        });
      });
  });
  
  
  
  /* ---------------------------------------------------------------- 
  	search
  ---------------------------------------------------------------- */
  var $searchInput = $('#search-text'),
      $searchLabel = $('#search label'),
      defaultValue = $searchLabel.text();
  $searchLabel.hide();
  $searchInput.val(defaultValue);
  $searchInput
    .focus(function () {
      // remove text
      if (this.value === defaultValue) {
        $(this).val('');
      }
    })
    .blur(function() {
      // add text
      if ($.trim(this.value) == '') {
        $(this).val(defaultValue);
      }
    });


  /* ----------------------------------------------------------------
    lightbox
  ---------------------------------------------------------------- */
  $('a[rel=lightbox]').fancybox({
    //overlayColor: '#fff',
    //overlayOpacity: '0.8',
    titlePosition: 'over',
    transitionIn: 'elastic',
    transitionOut: 'elastic'
  });
  
  
  /* ----------------------------------------------------------------
    Products (Plus / Minus)
  ---------------------------------------------------------------- */  
  $(".moreProductsContent").addClass("nod");
    $(".moreProducts").click(function(){
      $(this).toggleClass("daleMinus");
      $(this).next(".moreProductsContent").toggleClass("nod")
  });


  /* ----------------------------------------------------------------
    Choose office on Kontakty box
  ---------------------------------------------------------------- */
  $('#choose-office').change(function() {
    location.href = this.value;
  });
		
		
  /* ----------------------------------------------------------------
    Kraj
  ---------------------------------------------------------------- */
	$('#kraj').change(function() {
    $('#kraj-form').submit();
  });
	$('#kraj-form').submit(function(event) {
		event.stopPropagation();
		window.location.href=$('#kraj').val();
		return false;
	});
	$('#kraj').val(window.location.href.replace(/http:\/\/[^\/]*/, ""));

	$('#calsForm select').change(function() {
    window.location.href=$('#calsForm select').val();
  });
  
  
  
  $('#loginForm').submit(function(e) {
    window.open($(':selected', this).val());
    return false;
  });
  
  
  /* ----------------------------------------------------------------
    Corners
  ---------------------------------------------------------------- */
  if (isIE || isOpera) {
    $('a.corners').corners({
      width: '10px',
      height: '10px',
      debug: true
    });
  }
  

  /* ----------------------------------------------------------------
    BubbleTip
  ---------------------------------------------------------------- */    
      
  $('.bubble').each(function(index) {
      var t = this.id.split('_');
      $('#' + this.id).bubbletip($('#' + t[0]), { deltaDirection: t[1] });
  });  
  

  /* ----------------------------------------------------------------
    Box - Height 
  ---------------------------------------------------------------- */   
   var left = $('.box1');
   var right = $('.box2');
   for(i=0;i<left.length;i++) {
      if(left[i].offsetHeight > right[i].offsetHeight) {
        right[i].style.height = left[i].offsetHeight + 'px';
        $(right[i]).css('height',(left[i].offsetHeight-23) + 'px');
      } else {
        left[i].style.height = right[i].offsetHeight + 'px';
        $(left[i]).css('height',(right[i].offsetHeight-23) + 'px');
      }
    }

   
   /* ---------------------------------------------------------------- 
	toggle district checkbox in Consultants
	---------------------------------------------------------------- */
 var tog = false;
 $('#toggleDistricts').bind('click', function() {
	  $("input[type=checkbox]").attr("checked", !tog);	  
	  tog = !tog; 
	  if (tog) {
	  $('#toggleDistrictsLabel').html('Odznačit vše');
	  } else {
		  $('#toggleDistrictsLabel').html('Označit vše');
	  }
	  
 }); 
 

/* call back form */
if( $('#call-back-trigger').size() > 0 && $('#call-back-form').size() > 0 ) {
    var layerHeight = 520;
    var autorun = false;

    if( $('#call-back-form form ul.error').size() > 0 ) {
        layerHeight = layerHeight + 80;
        autorun = true;
    }
    
    if( window.location.hash == '#zavolame-vam' ) {
        autorun = true;
    }
    
    var fancyCfg = {
        'width' : 620,
        'height' : layerHeight,
        'padding' : 20,
        'hideOnContentClick' : false,
        'centerOnScroll' : false,
        'autoScale' : false,
        'autoDimensions' : false,
        'titleShow' : false,
        'overlayShow' : true,
        'transitionIn' : 'none',
        'transitionOut' : 'none'
    };
    
    $('#call-back-trigger').fancybox( fancyCfg );
    
    if( autorun ) {
        $('#call-back-trigger').trigger('click');
    }
}

$(window).hashchange( function() {
    if( window.location.hash == '#zavolame-vam' ) {
        $('#call-back-trigger').trigger('click'); 
    }
});





// auto default values
$(".auto-defaults textarea[title], .auto-defaults input[type=text][title], input.auto-defaults[title]").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');
        } 
    });
});
 

$('.roboform button[type="submit"]').mouseover( function() {
    $('.roboform input[name="email"]').val('');
});

 
});

