$().ready(function(){
  
  $('.slideshow').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    pager: '.tip-pagin',
    speed: 1000,
    timeout: 7000,
    activePagerClass: 'activeSlide',
    updateActivePagerLink: function(pager, currSlide) {
      $('.tip-item').hide();
      $(pager).find('a').removeClass('activeSlide').filter('a:eq('+currSlide+')').addClass('activeSlide');
      var cur = '#tip-'+$(pager).find('a.activeSlide').text();
      $(cur).show();
    }
	});
  
  $('.tip-item:first').show();

  var loaded = Array();
  var count = 0;
  
  $('#images-thumb').find('a').click(function(){
    var obj = this;
    
    $('#loading').show();
    $('#images-thumb').find('li.active').removeClass('active');
    var image = $(this).attr('href');
    var tag = $(this).find('img').attr('src');
    if (image == tag) {
      $('#loading').hide();
      $('#biger-image').attr('src', image).show();
      $(obj).parents('li').addClass('active');
      return false;
    }
    
    
    $('#biger-image').hide();
    for (k = 0; k < count; k++) {
      if (loaded[k] == image) {
        $('#loading').hide();
        $('#biger-image').attr('src', image).show();
        $(obj).parents('li').addClass('active');
        return false;
      }
    }

    var i = new Image(); 
    i.src = image; 
    i.onload = function() {
      loaded[count] = image;
      count++;
      $('#loading').hide();
      $('#biger-image').attr('src', image).show();
      
      $(obj).parents('li').addClass('active');
    }

    return false
  });
  
  var cont_height = 0;
  jQuery.each($('#images-thumb  img'), function(i){
    var width = $(this).attr("width");
    $(this).removeAttr("width").removeAttr("height").css({width: "", height: ""});
    $(this).load(function() {
      cont_height = $('#cont-image').height();
    });
    if (width) {
      $(this).attr("width", width);
    }
    else {
      $(this).attr("width", 90);
    }
  });

  var dy = 100;
  var may = 1;
  
  $('#top-arr').click(function(){
 
    if ( cont_height == 0 ) {cont_height = $('#images-thumb').height();}
    
    if ( $('#cont-image').position().top < 0 && may == 1 ) {
      may = 0;
      $('#cont-image').stop().animate({top: '+='+dy}, 500, function(){may = 1;});
    }

    return false;
  });

$('#bottom-arr').click(function(){
    if ( cont_height == 0 ) {cont_height = $('#images-thumb').height();}
    if ( ($('#cont-image').position().top + cont_height) >= 420 && may == 1 ) {
      may = 0;
      $('#cont-image').stop().animate({top: '-='+dy}, 500, function(){may = 1;});
    }
    return false;
  });

$('div.images-boxy').bind('mousewheel', function(event, delta) {
    if (delta > 0) {
      $('#top-arr').click();
    }
    else {
      $('#bottom-arr').click();
    }
    return false;
  });
  
 $('#bron-tab').find('a').click(function(){
    var el = $(this).attr('rel');
    $('#bron-tab').find('li.active').removeClass('active');
    $(this).parents('li').addClass('active');

    $('#tab-content').find('div.showed').removeClass('showed').hide();
    $(el).show().addClass('showed');
    return false;
  });  
  
});

function printPage(url) {
	var s='left=10,top=10,';
	var s1='width=700,height=630,';
	window.open(url, 'printpage', s+s1+'status=yes,toolbar=yes,menubar=no,scrollbars=yes,resizable=yes');
}
