  (function(jQuery){
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});
	function getRGB(color) {
		var result;
		if ( color && color.constructor == Array && color.length == 3 ) return color;
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)) return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
	}
	function getColor(elem, attr) {
		var color;
		do {
			color = jQuery.curCSS(elem, attr);
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 
			attr = "backgroundColor";
		} while ( elem = elem.parentNode );
		return getRGB(color);
	};
})(jQuery);

  /* Sliding menu */
  $.fn.slidingMenu = function(options) {
    options = $.extend({
      backgroundClass: "active-gray-item", initialOpacity: 1, slideSpeed: 1, easing: 'linear', callback: function(){}, backgroundContent: '<div></div>', activeClass: "active-gray-link", highlightOnClick: false
    }, options);
    options.slideTime = 200 * (1/options.slideSpeed);
    options.initial_height = parseInt($(this).find("li:eq(0)").find("a:eq(0)").outerHeight());
    options.initial_width = parseInt($(this).find("li:eq(0)").find("a:eq(0)").outerWidth());
    $(this).css({
      'position': 'relative'
    });
    $(this).find("li a").css({
      'display': 'inline-block',
      'position': 'relative'
    });
    $(this).prepend('<li class="'+options.backgroundClass+'" style="top:0px; left:0px; position: absolute; z-index: 0; display: none; width:'+options.initial_width+'px; height:'+options.initial_height+'px; ">'+options.backgroundContent+'</li>');
    if($.browser.msie && parseInt($.browser.version) < 9) {
        $('.'+options.backgroundClass).css({backgroundImage: 'url(../i/site/Default/active-item.gif)'});
    }
    options.initial_top = $(this).find("."+options.backgroundClass).eq(0).position().top;
    options.initial_left = $(this).find("."+options.backgroundClass).eq(0).position().left;
    if(options.highlightOnClick) {
      $(this).find("."+options.backgroundClass).eq(0).css({
        'display': 'block'
      });
    }
    $(this).find("li a").hover(function(){
        if(!$(this).hasClass(options.activeClass))
            $(this).animate({color: "#ef3f3b"}, options.slideTime, options.easing, options.callback);
    }, function(){
        if(!$(this).hasClass(options.activeClass))
            $(this).animate({color: "#191919"}, options.slideTime, options.easing, options.callback);
    });
    $(this).find("li a").click(function(){
      $(this).parent().parent().find('li a').animate({color: "#191919"}, options.slideTime, options.easing, options.callback).removeClass(options.activeClass);
      
      var t = $(this).position().top;
      var l = $(this).position().left;
      var w = $(this).outerWidth();
      var h = $(this).outerHeight();
      $(this).stop().animate({color: "#FFFFFF"}, options.slideTime, options.easing, options.callback).addClass(options.activeClass);
      $(this).parents("ul:first").find("."+options.backgroundClass).stop().animate({
        opacity: options.initialOpacity, top: t, left: l, width: w, height: h
      }, options.slideTime, options.easing, options.callback ).show();
    });
  };

function resizeWindow(){
    $ ("#mainarea").css ({minHeight : "0px"});
    $ ("#mainarea .inside").css ({minHeight : "0px"});
    if (document.documentElement.clientHeight > $ ("#mainarea").height ()) {
        $ ("#mainarea").css ({
            minHeight : $ ("#mainarea").parent ().height () - 221 + "px"
        });
        $ ("#mainarea .inside").css ({
            minHeight : $ ("#mainarea").height () - 167 + "px"
        });
    }
}

$(document).ready(function(){
    $('.j-text-field').each (function (){
        new TextField (this);
    });
    $('.j-textarea').each(function (){
        new TextArea(this, $(this).attr('class'));
    });
    new Slideshow($('.j-slideshow'), $('#submenu'));
    
    if($('.submenu').attr('class') != undefined) $('.submenu').slidingMenu();
    
    resizeWindow();
    $(window).resize(resizeWindow);
    
    //table
    $(".decoration-table tr:odd").addClass("odd-tr");
    $(".decoration-table th:last-child").addClass("no-border");
    $(".decoration-table td:last-child").addClass("no-border");
    $(".decoration-table tr:last-child td").addClass("border-bottom");
    
    //button template
    $('.button-template').each(function(){
        var childs = $(this).html();
        var div = $('<span></span>');
        div.html(childs);
        $(this).html(div);
    });
    /* msie7 */
    $('.button-template span').each(function(){
        if($.browser.msie && parseInt($.browser.version) < 8) {
            var ieHeight = $(this).height();
            var ieParentHeight = $(this).parent().height();
            var pd = (ieParentHeight - ieHeight) / 2;
            if(pd > 0) $(this).css({paddingTop: pd + "px"});
        }
    });
	$('.big-button span').each(function(){
        if($.browser.msie && parseInt($.browser.version) < 8) {
            var ieHeight2 = $(this).height();
            var ieParentHeight2 = $(this).parent().height();
            var pd2 = ((ieParentHeight2 - ieHeight2) / 2) - 10;
            if(pd2 > 0) $(this).css({paddingTop: pd2 + "px"});
        }
    });
	
	//button animation
	$('.big-button').each (function (){
        new buttonAnimation (this);
    });
	$('.button-template').each (function (){
        new buttonAnimation (this);
    });
	$('.link-but').each (function (){
        new buttonAnimation (this);
    });
	$('.next').each (function (){
        new buttonAnimation (this);
    });
	$('.prev').each (function (){
        new buttonAnimation (this);
    });
	
	//news list
	$(".news:last-child").addClass("news2");
	$(".reviews-block:last").addClass("reviews-block2");
	
	var params = {
	changedEl: ".fb-content select",
	scrollArrows: true
	}
	cuSel(params);
	
	var zindex = 100;
	$(".cusel").each(function() {
		$(this).css("z-index",zindex);
		zindex--;
	});

	$('#j_howUse').change(function(){
		var val = $(this).val();
		
		if('5' == val) {
			$('#j_howUseOther').show();
		} else {
			$('#j_howUseOther').hide();
		}
	});

	$('#j_howKnown').change(function(){
		var val = $(this).val();
		
		if('6' == val) {
			$('#j_howKnownOther').show();
		} else {
			$('#j_howKnownOther').hide();
		}
	});

	$('#j_userSector').change(function(){
		var val = $(this).val();
		
		if('20' == val) {
			$('#j_userSectorOther').show();
		} else {
			$('#j_userSectorOther').hide();
		}
	});
	
});

/* Custom text field */
function TextField (container){
    var _this = this;
    
    this.className = $(container).attr ('class')
    this.container = $(container);
    
    this.container.wrap ('<div class="text-field-container ' + this.className + '"><div></div></div>')
}

/* Custom textarea */
function TextArea (container, className){
    var _this = this;
    
    this.container = $ (container);
    this.container.wrap ('<div class="textarea ' + className + '"><div class="ta-outer"><div class="ta-inner"></div></div></div>');
    var taInner = this.container.parent().parent();
    taInner.before('<div class="ta-top"><div class="ta-right"></div></div>');
    taInner.after('<div class="ta-bottom"><div class="ta-right"></div></div>');
}

/* Slideshow */
function Slideshow(container, controls){
    var _this = this;
    
    this.container = $ (container);
    $('.slide:first-child', this.container).addClass('active');
    this.controls = $ (controls);
    
    $('.home-button').hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); });
    
    $('.home-button').click(function(){
        _this.Slide(0);
        _this.controls.find('.active-gray-link').animate({color: "#191919"}, 200, 'linear').removeClass('active-gray-link');
        _this.controls.find('li:first-child').animate({opacity: 0}, 200, 'linear');
        $(this).addClass('active');
        return false;
    });
    this.controls.find('li').click(function(){
        $('.home-button').removeClass('active')
        _this.Slide($(this).index());
        return false;
    });
}

Slideshow.prototype.Slide = function(ind){
    if(!this.container.find('.slide').eq(ind).hasClass('active')) {
        this.container.find('.slide').hide().removeClass('active');
        this.container.find('.slide').eq(ind).fadeIn(500).addClass('active');
    }
}

/* button animation */
function buttonAnimation (container){

    $(container).mousedown(function()
	{
		$(container).addClass(" button-active");
	});
	$(container).mouseup(function()
	{
		$(container).removeClass(" button-active");
	});
    
}










