$(document).ready(function(){

    //Breadcrumb last
    $('.smal-nav li:last').addClass('last');

    //Theming  order form submit button
    $("#webform-client-form-40 .form-submit").replaceWith('<div class="clearing"></div><button type="submit" name="op" id="edit-submit" class="rc-button rc-button__order"><em><b><i><strong>Заказать</strong></i></b></strong></em>');
    $(".order-page #edit-submitted-imya").focus();

    //Client list clear-fix
	$('.client:nth-child(4n)').after('<div class="clearing"></div>');

    //Random quotes
	var
	n = $(".right-box .quote").length;
	var randomNum = Math.floor(Math.random()* n );
	$(".right-box .quote:eq(" + randomNum + ")").show();

    //stickyfloat
    if($(".scroll-block-margin").length > 0){
        /*

         * stickyfloat - jQuery plugin for verticaly floating anything in a constrained area

         *

         * Example: jQuery('#menu').stickyfloat({duration: 400});

         * parameters:

         * 		duration 	- the duration of the animation

         *		startOffset - the amount of scroll offset after it the animations kicks in

         *		offsetY		- the offset from the top when the object is animated

         *		lockBottom	- 'true' by default, set to false if you don't want your floating box to stop at parent's bottom

         * $Version: 05.16.2009 r1

         * Copyright (c) 2009 Yair Even-Or

         * vsync.design@gmail.com

         */

        var RBHeight = $('.right-block').height() + 15 + 'px';

        $.fn.stickyfloat = function(options, lockBottom) {

            var $obj 				= this;
            var parentPaddingTop 	= parseInt($obj.parent().css('padding-top'));
            var startOffset 		= $obj.parent().offset().top;
            var opts 				= $.extend({ startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom:true }, options);

            $obj.css({ position: 'absolute' });

            if(opts.lockBottom){

                var bottomPos = $obj.parent().parent().height() - $obj.height() + parentPaddingTop; //get the maximum scrollTop value

                if( bottomPos < 0 )

                    bottomPos = 0;

            }

            $(window).scroll(function () {

                $obj.stop(); // stop all calculations on scroll event

                var pastStartOffset			= $(document).scrollTop() > opts.startOffset;	// check if the window was scrolled down more than the start offset declared.

                var objFartherThanTopPos	= $obj.offset().top > startOffset;	// check if the object is at it's top position (starting point)

                var objBiggerThanWindow 	= $obj.outerHeight() < $(window).height();	// if the window size is smaller than the Obj size, then do not animate.



                // if window scrolled down more than startOffset OR obj position is greater than

                // the top position possible (+ offsetY) AND window size must be bigger than Obj size

                if( (pastStartOffset || objFartherThanTopPos) && objBiggerThanWindow ){

                    var newpos = ($(document).scrollTop() -startOffset + opts.offsetY );

                    if ( newpos > bottomPos )

                        newpos = bottomPos;

                    if ( $(document).scrollTop() < opts.startOffset ) // if window scrolled < starting offset, then reset Obj position (opts.offsetY);

                        newpos = parentPaddingTop;



                    $obj.animate({ top: newpos - 100 }, opts.duration );

                }

            });

        };
        $('.scroll-block-margin').css('marginTop',RBHeight);
        $('#scroll-menu').stickyfloat({ duration: 400 });
    };

    //Main page scroller
    $(".scrollable").scrollable({circular: true}).navigator().autoscroll({interval: 8000});

    //Block equal height

    function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
    var thisHeight = $(this).height();
    if(thisHeight > tallest) {
    tallest = thisHeight;
    }
    });
    group.height(tallest);
    }
    equalHeight($(".main-catalog .item .bgc"));
    function equalHeight(group) {
       group.removeAttr('style');
      var tallest = 0;
      group.each(function() {
      var thisHeight = $(this).height();
      if(thisHeight > tallest) { tallest = thisHeight; } });
      group.css("height", tallest);
    }
    equalHeight($(".price-page h2"));
    window.onresize = function() { equalHeight($(".price-page h2")); }

    equalHeight($(".price-page .content"));
    window.onresize = function() {   equalHeight($(".price-page .content")); }

});



