$(function(){
	$("a[rel='brezfot']").fancybox(); 
});

(function($)
{
    
    $(function()
    {

        
       
        /*
         * Homepage
         */
        var banners_change_interval = 3000;
		i = 1;
        function home_show_banner(holder)
        {
            var counte = $(".holder").size();
			//alert( 'i = '+i+' count - '+counte);

            $("#home_banner_choosers .active").each(function()
            {
                var current_index   = $(this).attr('id')
                    .replace('home_banner_holder_', '');
                $("#home_banner_holder_"+current_index).removeClass('active');
				$("#home_banner_"+current_index).fadeOut();
                $("#home_banner_holder_"+current_index).removeClass('loop_active_loop_last');
            });
            
			var next_index = $(holder).attr('id').replace('home_banner_holder_', '');
            i = i + 1;
            if(i == counte) {
				i = 0;
				$("#home_banner_holder_"+next_index).removeClass('active');
				$("#home_banner_holder_"+next_index).removeClass('loop_last');
				$("#home_banner_holder_"+next_index).addClass('loop_active_loop_last');
			}
			$("#home_banner_holder_"+next_index).addClass('active');
            $("#home_banner_"+next_index).fadeIn();
			
			
			var prev_index  = next_index-1;

			
			
			
            $(".separate_holder").css({visibility: 'visible'});
            
            if ($("#s"+next_index)){
             $("#s"+next_index).css({visibility: 'hidden'});
            }
            if ($("#s"+prev_index)){
             $("#s"+prev_index).css({visibility: 'hidden'});
            }
        }
        if ($("#home_banner_choosers .holder").length > 0) {
            $("#home_banner_choosers").everyTime(banners_change_interval, function() {
                if ($(".active", this).nextAll(".holder:not('.active')").length) {
                    home_show_banner($(".active", this).nextAll(".holder:not('.active')"));
                } else {
                    home_show_banner($(".holder:eq(0)", this));
                }
            });
            
            $("#home_banner_choosers .holder").each(function()
            {
                var holder = this;
                $("a", this).click(function()
                {
                    $("#home_banner_choosers").stopTime(); 
                    home_show_banner(holder);
                });
            });
        }
        

    });
})(jQuery);


(function($){
 $.fn.extend({
 
     customStyle : function(options) {
      if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
      return this.each(function() {
      
            var currentSelected = $(this).find(':selected');
            $(this).after('<span class="select_st"><span class="select_stInner" id="a_'+$(this).attr('id')+'">'+currentSelected.text().substr(0,3)+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
            var selectBoxSpan = $(this).next();
            var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));            			
			
            var selectBoxSpanInner = selectBoxSpan.find(':first-child');
            selectBoxSpan.css({display:'inline-block'});
            selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
            var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
            $(this).height(selectBoxHeight).change(function(){
                selectBoxSpanInner.text($("#"+$(this).attr('id')+" :selected").text().substr(0,3)).parent().addClass('changed');
                
            });
            
      });
      }
    }
 });
})(jQuery);    




function fix_bar()
{
	     
	  var box = $(".contact");
	  var cnt = box.parent();
	  var box_position = box.position();
	  var cnt_position = cnt.offset();
	  var documentHeight = $(document).height()
	  var top_box = $(".main_menu");
	  var bottom = cnt_position.top+cnt.height()-box.height();
	  var top_position = $(window).scrollTop()+$(window).height()-box.height()-cnt_position.top;
	  if (top_position > bottom)
	     top_position = bottom;
	  var max_top = top_box.offset().top+top_box.height();

	  if (top_position <= max_top){	
			top_position = max_top;
	}

	  box.css({
		'position': 'absolute',
		
		'top' : top_position+'px'
	  });
}

 $(window).scroll(function () { 
		fix_bar();
		
 });


	
$(document).ready(function(){

		fix_bar();
	
});
