$j(document).ready(function() {
    $j("a._blank").attr('target', '_blank');
    $j("img.absmiddle").attr('align', 'absmiddle');
		
    $j('a.popup').bind('click', function(){
        varpopup_window = window.open($j(this).attr('href'), 
            'Goldentile', 
            "width=800,height=600,menubar=no,location=yes,resizable=no,scrollbars=no,status=yes,screenX=20,screenY=30");
        return false;
    });
		
    activateMenu();
});
	
function centerWindow() {
    var canCool;
    canCool = navigator.appVersion.charAt(0); 
    var top;
    var left; 
    if (canCool>=4) { 
        left = (screen.width - 800)/2; 
        top  = (screen.height - 600)/2; 
        window.moveTo(left,top); 
        window.resizeTo(800, 600);
        window.focus(); 
    }
}
	
function activateMenu() {
    $j("#menu a").hover(function() {
        var block = $j(this).parent().parent().parent();
        var is_vis = $j(this).parent().parent().parent().prev();
        if (!block.hasClass('first') && !is_vis.hasClass('vis') && !block.hasClass('vis')){
            var prev = $j(this).parent().parent().parent().prev().find(".bg_right");
            prev.css({
                'background-position': 'right 100px'
            });
        }
        block.toggleClass('hov');	
    }, function() {
        var block = $j(this).parent().parent().parent();
        var is_vis = $j(this).parent().parent().parent().prev();
        if (!block.hasClass('first') && !is_vis.hasClass('vis') && !block.hasClass('vis')){
            var prev = $j(this).parent().parent().parent().prev().find(".bg_right");
            prev.css({
                'background-position': 'right center'
            });
        }
        block.toggleClass('hov');
    });
    // для выделенного пункта меню
    var vis_menu = $j("#menu").find(".vis");
    if(vis_menu.attr('class')){
        var prev = vis_menu.prev().find(".bg_right");
        if(prev) prev.addClass('pre_vis');
    }
		
    if ($j.browser.msie) {
        var mainWidth = 962;
        var menuWidth = $j("#menu").width();
        var menuPadding = Math.floor((mainWidth-menuWidth)/2);
        if(menuPadding>0){
            $j("#menu").css({
                'padding-left': menuPadding, 
                'padding-right': menuPadding
            });
        }
    }
}
	
// -- Index --
		
function activateIndexPage() {
}
	
// -- Flash --
	
function activateFlash( base, wrapper, src, width, height ){        
    $j('#'+wrapper).flash(
    { 
        'wmode':'opaque',
        src: src,
        width: width,
        height: height,
        base: '/' + base + '/'
    },
    {
        version: 8
    }
    );
}
	
function activateFlashHeader(wrapper, src, width, height ){        
    $j('#'+wrapper).flash(
    { 
        'wmode':'opaque',
        src: src,
        width: width,
        height: height
    },
    {
        version: 8
    }
    );
}
	
// -- Catalog --
	
function activateSampleMenu() {
    $j('.param a').bind('click', function() {			
        $j(this).toggleClass('open').toggleClass('close').parent().next().toggle();
    });
}
	
function activateCollectionShowOne() {
    activateNextCollectionLink();
    activateTilesHints();
    activateTech();
    activateCart();
    activateShowTile();
    activateShowDesignsOnTilesPage();
    activateAnimatedTiles();
    ieFix6();
}
	
function activateNextCollectionLink() {
    $j(".white").hover(function() {
        // toggle - нельзя (если при загрузке, курсор над элементом, работает не правильно)
        $j(this).find(".next_color").addClass('vis');
    }, function() {
        $j(this).find(".next_color").removeClass('vis');
    });
}
	
var count_col;
var curr_col = 1;
function activateAnimatedTiles() {
    var col = $j('.container:first div.row'),	
    $color_link = $j('.color_link'),
    //curr_col = 1,
    $row = $j('.animated');                		
    count_col = col.size(); // global
//    window.setTimeout(function() {
//        count_col = col.size()
//    }, 100);


    $color_link.bind('click', function(){			
        var index = $color_link.index(this);        			
        $row.animate({
            'marginLeft':-index*475
        });
        curr_col = ++index;
        setTextForNextCollectionLink();
    });
        		
    $j('.next_color').bind('click', function(){
        //window.setTimeout(function(){
        //        	if (curr_col < count_col) {
        
        curr_col = (curr_col < count_col) ? curr_col : 0;
        curr_col ? $row.animate({
            'marginLeft': '-=475'
        }) : $row.animate({
            'marginLeft': 0
        });
        var cur_header =  $j('.container:first .col_left h3:eq(' + (curr_col) + ')'),
        id = cur_header.attr('id'),
        productId = id.split('---')[1],
        alias = id.split('---')[2];
        curr_col++;
        $j.ajax({
            type: "POST", 
            url: "/tilescollection/get-simular",  
            data: {
                'tilesCollectionAlias': alias,
                'productId': productId
            }, 
            success: function(data){	
                var json = checkResponse(eval("(" + data + ")"));
                $j('.catalog').find('#bread_crumb').remove().end()
                .find('h1').remove().end().find('.top_block').remove().end();

                $j('.catalog').prepend(json.collectionData);
                $j('.catalog #simularCarouselBlock').html(json.carouselBlock);
                setTextForNextCollectionLink();
                activateCarusel();
                if(window.history && history.pushState) {
                    history.pushState(null,null, alias + '.html');
                }
                gapi.plusone.go("custom-gap")

                //activateCollectionShowOne();
                activateNextCollectionLink();
                //activateAnimatedTiles();
                //activateTilesHints();
                //activateTech();
                //activateCart();
                activateShowTile();
                activateShowDesignsOnTilesPage();
                ieFix6();
            //					$rating.html(msg);					
            //					showGrowl($j('#voted'), 'green');
            //					
            //					// только что загружены и разбинднены					
            //					$j('.rating a').bind('click', function(){
            //						showGrowl($j('#already_vote'), 'red');
            //					});
            }
        });

    //        	} else {
    //        		$row.animate({'marginLeft': 0});
    //        		curr_col = 1;
    //				setTextForNextCollectionLink();
    //        	}
  //      }, 1000)
    });
}
	
function setTextForNextCollectionLink(last) {
    // смена текста
    if (curr_col == count_col) {
        var index = 0;
    } else {
        var index = curr_col;
    }
    var text = $j('.container:first .col_left h3:eq(' + (index) + ')').text();
    var $next_color = $j('.next_color');
    $next_color.text(text);
		
    // отзеркаливание стрелки
    if (curr_col == count_col) {
        $next_color.addClass('flip');
    } else {
        if ($next_color.hasClass('flip')) {
            $next_color.removeClass('flip');
        }
    }
		
    // выделение превью
    $j('.transparent').removeClass('transparent');
    $j('.color_link:eq(' + (curr_col - 1) + ')').addClass('transparent')
}
	
function activateTilesHints() {
    $j('.help_link .a img').hover(function(){			
        $j(this).next().show();
    }, function(){
        $j(this).next().hide();

    });
}
	
function activateTech() {
    $j('.tech_show').hover(function(){
        $j(this).next().show();
    }, function(){
        // TODO: отслеживать курсор мышки, не над подсказкой ли мы находимся
        $j(this).next().hide();
    });
}

function activateCart() {
    $j('.add_to_cart').bind('click', function(){
        var $this = $j(this);			
        setCartData($this.attr('id').split('_')[1]);			
    });
}

function activateCartData() {
    activateCartDelete();
    activateCartChangeCount();
}

function activateCartChangeCount() {
    var localChangeCount = function($this) {
        var id = $this.attr('id').split('_')[1];
        var count = Number($this.attr('value'));
        count = $this.hasClass('meter') 
        ? (Math.round(count * 100 ) / 100) 
        : Math.round(count);
        changeCountCartData($this, id, count);	
    };
    $j('.item-quantity').bind('blur', function(){
        localChangeCount($j(this));	
    }).bind('keypress', function(e) {
        if(e.keyCode==13){
            localChangeCount($j(this));
        }
    });
}
function activateCartDelete() {
    $j('.remove-tile').bind('click', function(e){
        e.preventDefault();
        var $this = $j(this);
        var col = $this.parent().parent();
        removeCartData($this.attr('value'), col);			
    });
}
function setCartData(tailId) {
    $j.ajax({
        type: "POST", 
        url: "/cart/add-single-tail", 
        data: {
            'tailId': tailId
        }, 
        success: function(data){	
            var response = checkResponse(eval("(" + data + ")"));
            if(response.data) {
                $j('#cart').html('(' + response.data.count + ')');
            //showGrowl($j('#voted_' + id), 'green');
            }
                
        }
    });
}
function changeCountCartData(obj, tailId, count) {
    $j.ajax({
        type: "POST", 
        url: "/cart/change-count-tail", 
        data: {
            'tailId': tailId,
            'count': count
        }, 
        success: function(data){	
            var response = checkResponse(eval("(" + data + ")"));
            if(response.data) {
                obj.attr('value', response.data.count);
                var tr = obj.parent().parent(),
                price = Number(tr.find('.unit_price').text());
                tr.find('.extended_price').html((Math.round(price * response.data.count * 100) / 100 ) + ' грн');
                calculateCart();
            //showGrowl($j('#voted_' + id), 'green');
            }     
        }
    });
}
function removeCartData(tailId, col) {
    $j.ajax({
        type: "POST", 
        url: "/cart/remove-tail", 
        data: {
            'tailId': tailId
        }, 
        success: function(data){	
            var response = checkResponse(eval("(" + data + ")"));
            if(response.data) {
                col.fadeOut(1000, function () {
                    col.remove();
                    calculateCart();
                });
                $j('#cart').html(response.data.count > 0 ? '(' + response.data.count + ')' : '');
            //showGrowl($j('#voted_' + id), 'green');
            }
                
        }
    });
}

function calculateCart(){
    var cartTable = $j('#maincart tr');
    var total = 0;
    cartTable.each(function(index, value) {
        var tr = $j(value);
        if(index > 0 && tr.hasClass('cart-item')) {
            var price = Number(tr.find('.unit_price').text());
            var count = Number(tr.find('.quantity .item-quantity').attr('value'));
            if(price) {
                total += price * (count || 1);
            }    
        }
    });
    total = Math.round(total*100) / 100;
    if(total > 0) {
        
        $j('#total_price').html(total + ' грн');
    } else {
        $j('#maincart').remove();
        $j('#orderForm').remove();
        $j('#empty-cart').css({
            display:'block'
        });
    }

}
	
function activateShowTile() {
    $j('.show_tile').bind('click', function(){
        var $col_left = $j(this).parents('.col_left');
        var html = $j('.box_block_tile', $col_left).html();			
        setBlock(html);			
    });
		
    $j('.close').bind('click', function(){
        closeBlock();
    });		
}
	
function setBlock(html) {
    var $box = $j(".box");
    var $box_block	= $j('.box_block');
    var $box_data   = $j('.box_block .box_content .box_data');
    var width 		= $box_block.width();
    $box_data.html(html);		
    if ($j.browser.msie) {
        $box.height($j(document).height());
        $box_block.show();
			
        /*
				Проблемы с SELECT и Z-INDEX в Microsoft Internet Explorer 6.0
				Решение:
				1. изменять свойство CSS display для блока, содержащего select.
				2. разместить iframe под перекрывающим блоком. (при скролле страницы, селект будет все таки проскакивать)
				3. изменить интерфейс таким образом, чтобы данная проблема не возникала (поместить в один контейнер)
			*/
        if ($j.browser.version == '6.0') {
            $j('select').css('visibility', 'hidden');
        }
		
    } else {
        $box.height($j(document).height()).fadeIn('slow');
        $box_block.fadeIn('slow');
    }
    window.scroll(0,0);
}
	
function closeBlock() {
    var $box = $j(".box");
    var $box_block	= $j('.box_block');	
    var $box_data   = $j('.box_block .box_content .box_data');
		
    if ($j.browser.msie) {			
        $box.height(0);
        $box_block.hide();
        $box_data.empty();
        // Если открывали дизайн
        $j('.box_content', $box_block).removeClass('box_content_design');
			
        /*
				Проблемы с SELECT и Z-INDEX в Microsoft Internet Explorer 6.0
				Решение:
				1. изменять свойство CSS display для блока, содержащего select.
				2. разместить iframe под перекрывающим блоком. (при скролле страницы, селект будет все таки проскакивать)
				3. изменить интерфейс таким образом, чтобы данная проблема не возникала (поместить в один контейнер)
			*/
        if ($j.browser.version == '6.0') {
            $j('select').css('visibility', 'visible');
        }
		
    } else {			
        $box_block.fadeOut(700, function() {
            $box.height(0);
            $box_data.empty();
            // Если открывали дизайн
            $j('.box_content', $box_block).removeClass('box_content_design');
        });
    }
}
	
function activateCarusel() {
    activateSubMenu();
		
    $object_carousel = $j('.carousel');
    $object_carousel.each(function(){
        $curr_carousel = $j(this);
        $curr_carousel.jcarousel({
            initCallback: function(carousel){ 
                $object_carousel.css({
                    'visibility':'visible'
                });
					
                var $carusel_prev	= jQuery('.arrow_left');
                var $carusel_next	= jQuery('.arrow_right');				
                $carusel_prev.bind('click', function() {
                    carousel.prev();
                    return false;
                });					
                $carusel_next.bind('click', function() {
                    carousel.next();
                    return false;
                })
            },		
            itemFallbackDimension: 578, //it's the size of jCarousel clip

            animation: "slow",
            scroll: 2//,
        //buttonNextHTML: null,
        //buttonPrevHTML: null
        });
    });
}
	
function activateProducts() {
    var $sub_menu_a = $j(".sub_menu a");
		
    $sub_menu_a.hover(function() {
        $j(this).parent().parent().parent().toggleClass('hov');	
    }, function() {
        $j(this).parent().parent().parent().toggleClass('hov');
    });
}
function activateSubMenu() {
    var $sub_menu_a = $j(".sub_menu a");
		
    $sub_menu_a.hover(function() {
        $j(this).parent().parent().parent().toggleClass('hov');	
    }, function() {
        $j(this).parent().parent().parent().toggleClass('hov');
    });
		
    $sub_menu_a.bind('click', function() {
        var $this = $j(this);
        var $parent = $this.parent().parent().parent();
        if (! $parent.hasClass('vis')) {
            $j('.sub_menu .vis').removeClass('vis');
            $parent.addClass('vis');
            $j('.carousel_wrapper').fadeOut();
            var index = $sub_menu_a.index($this);		
            $j('.carousel_wrapper:eq(' +index+')').fadeIn();
        }			
    });
		
    $j(".sub_menu a:first").click();
}
	
function activateShowDesignsOnTilesPage() {
    $j('.show_design').bind('click', function(){
        $j('.box_block .box_content').addClass('box_content_design');
        var html = $j(this).next().html();
        setBlock(html);			
    });
		
    $j('.close').bind('click', function(){
        closeBlock();
    });
}
	
function ieFix6() {		
    if (!$j.browser.msie || $j.browser.version != '6.0') {
        return;
    }

    $j('.white:not(.white_end)').each(function(){
        var $this = $j(this);
        $this.height(parseInt($this.parent().height()*1.15));
    });
		
    $j('.white_end').each(function(){
        var $this = $j(this);
        $this.height(parseInt($this.parent().height()));
    });
}
	
// -- Designs --
	
function activateDesignSampleForm(currentLangSuffix) {
    var $sampleForm = $j('#sampleForm');
    $p_type = $j('#p_type');
    $p_square = $j('#p_square');
		
    $sampleForm.bind('submit', function() {												  
        return false;
    });
		
    $p_type.bind('change', function() {
        designSampleRedirect(currentLangSuffix);
    });
		
    $p_square.bind('change', function() {
        designSampleRedirect(currentLangSuffix);
    });
}
	
function designSampleRedirect(currentLangSuffix) {
    // FIXME: Неправильно такие вещи вносить в javascript, да еще и привязыватся к языку
    var redirect_string = currentLangSuffix == 'ru' ? '/design/' : '/' + currentLangSuffix + '/design/';
    if ($p_type.val() != '') {
        redirect_string += '-type:' + $p_type.val();
    }
		
    if ($p_square.val() != '') {
        redirect_string += '-square:' + $p_square.val();
    }
		
    window.location = redirect_string;
}
	
function activateShowDesigns() {		
    $box = $j(".box");
    $box_block = $j('.box_block');
    $box_data = $j('.box_block .box_content .box_data');
		
    $j('.show_design').bind('click', function(){
        $j('.box_block .box_content').addClass('box_content_design');
        var $col_left = $j(this).parents('.design_date');
        var html = $j('.box_block_design', $col_left).html();
        setBlock(html);			
    });
		
    $j('.close', $box_block).bind('click', function(){
        closeBlock();
    });
}
	
//  -- Map --
	
function activateMap() {		
    var $map_bg = $j(".map_img");
    var $map_area = $j("#Map area");
		
    $map_area.hover(function() {
        var index = $map_area.index(this);
        $map_bg.css('background-position', '0 -' + ((index + 1) * 308) + 'px'); 	
    }, function() {
        $map_bg.css('background-position', '0 0');
    });
		
    var $map = $j('.map:first .col_right');
    $map_area.bind('click', function() {
        var $city = $j('#city-' + $j(this).attr('id')).clone();
        $map.html($city);			
    });
    $j('#kyiv').click();
		
    var $map2 = $j('.map:eq(1) .col_right');		
    $j('.country_link a').bind('click', function() {
        $j('.country_link .vis').removeClass('vis');
        $j(this).addClass('vis');
        var $country = $j('#country-' + $j(this).attr('id')).clone();
        $map2.html($country);			
    });
    $j('.country_link .vis').click();
		
    $j('#footer .cont').addClass('bott_line');
    $j('.gmap .map_data div').removeClass('init-map');
    
    $j('.map_title a').bind('click', function(e) {
        e.preventDefault();
        var me = $j(this),
            className,
            parent = me.parent();
            
        if(!parent.hasClass('active')) {
            $j('.map_title li, .map_data div').removeClass('active');
            className = parent.attr("class");
            parent.addClass('active');
            if(className && className.length)
                $j('.map_title a, .map_data div.'+className).addClass('active');
        }
    })
}
	
// -- Poll --
	
function activatePoll() {
    $j('.rating a').bind('click', function(){
        var $this = $j(this);
        var $parentId = $this.parent().attr('id');
        var id = $parentId.split('_')[1];
        var rate = $this.attr('rel');
        if ($this.parent().hasClass('already_vote')) {
            showGrowl($j('#already_vote_' + id), 'red');
            return;
        }			
			
			
        var i = 1;
        var interval = window.setInterval(function(){
            if (i == rate) {
                window.clearInterval(interval);
            }
            $j('#' + $parentId + ' a:eq(' + (i-1) + ')').removeClass('undone').addClass('done');
            i++;			
        }, 700);
        $this.parent().addClass('already_vote');
        //			$j('.rating a').unbind('click').bind('click', function(){
        //					showGrowl($j('#already_vote'), 'red');
        //			});

        $j.ajax({
            type: "POST", 
            url: "/imagepoll/vote-for-image", 
            data: {
                'imageId': id, 
                'rate':rate
            }, 
            success: function(msg){	
                showGrowl($j('#voted_' + id), 'green');
            }
        });
    });
}
function activateShowCompare() {
    $j('a.compare').bind('click', function(){
        var $this = $j(this);
        var id = $this.attr('id');
        var $compare = $j('a.compare').not('#' + id);
        var $ids = [];
        if($compare) {
            for(var i = 0; i < $compare.length; i++) {
                $ids.push($compare[i].id.split('_')[2]);
            }
            $j.ajax({
                type: "POST", 
                url: "/imagepoll/compare-for-image", 
                data: {
                    'pollId': id.split('_')[1], 
                    'imageId': id.split('_')[2], 
                    'data': $ids.join(':')
                }, 
                success: function(data){	
                    //                    showGrowl($j('#voted'), 'green');
                    $j('.catalog').html(data);
                    activateShowCompare();
                }
            });
        }
			
    });
    $j('a.noone').bind('click', function(){
        var $this = $j(this);
        var $compare = $j('a.compare');
        var $ids = [];
        if($compare) {
            for(var i = 0; i < $compare.length; i++) {
                $ids.push($compare[i].id.split('_')[2]);
            }
            $j.ajax({
                type: "POST", 
                url: "/imagepoll/compare-for-image", 
                data: {
                    'pollId': $compare[0].id.split('_')[1], 
                    'imageId': 'noone', 
                    'data': $ids.join(':')
                }, 
                success: function(data){	
                    //                    showGrowl($j('#voted'), 'green');
                    $j('.catalog').html(data);
                    activateShowCompare();
                }
            });
        }
			
    });
}
function activateShowVote() {
    $j('a.vote-text').bind('click', function(){
        var $this = $j(this);
        var id = $this.parent().attr('id');
        $j.ajax({
            type: "POST", 
            url: "/imagepoll/vote-for-image", 
            data: {
                'pollId': id.split('_')[1], 
                'imageId': id.split('_')[2],
                'rate': $this.text(),
                'info': $j('#vote-info textarea').val()
            }, 
            success: function(data){	
                $j('.catalog').html(data);
                activateShowVote();
            }
        });	
    });
}
//	function activatePoll(alreadyVote) {
//		$j('.rating a').bind('click', function(){
//			if (alreadyVote) {
//				showGrowl($j('#already_vote'), 'red');
//				return;
//			}			
//			var $rating = $j('.rating');
//			var $this = $j(this);
//			var id = $this.parent().attr('id').split('_')[1];
//			var rate = $this.attr('rel');
//			
//			var i = 1;
//			var interval = window.setInterval(function(){
//				if (i == rate) {
//					window.clearInterval(interval);
//				}
//				$j('.rating a:eq(' + (i-1) + ')').removeClass('undone').addClass('done');
//				i++;			
//			}, 700);
//			
//			$j('.rating a').unbind('click').bind('click', function(){
//					showGrowl($j('#already_vote'), 'red');
//			});
//
//			$j.ajax({
//				type: "POST", 
//				url: "/poll/vote-for-collection", 
//				data: {'collectionID': id, 'rate':rate}, 
//				success: function(msg){	
//					showGrowl($j('#voted'), 'green');
//				}
//			});
//		});
//	}
	
/*var alreadyVote = false;
	function ckeckAlreadyVote() {
		alreadyVote = $j('#alreadyVote').size() > 0 ? true : false;
	}*/
	
/*function activatePoll(alreadyVote) {		
		//ckeckAlreadyVote();
		$j('.rating a').bind('click', function(){
			if (alreadyVote) {
				showGrowl($j('#already_vote'), 'red');
				return;
			}			
			var $rating = $j('.rating');
			var $this = $j(this);
			var id = $this.parent().attr('id').split('_')[1];
			$rating.html('<img src="/images/load.gif" alt="" />');
			$j.ajax({
				type: "POST", 
				url: "/poll/vote-for-collection", 
				data: {'collectionID': id, 'rate':$this.attr('rel')}, 
				success: function(msg){					
					$rating.html(msg);					
					showGrowl($j('#voted'), 'green');
					
					// только что загружены и разбинднены					
					$j('.rating a').bind('click', function(){
						showGrowl($j('#already_vote'), 'red');
					});
				}
			});
		});
	}*/
	
function showGrowl($div, color) {
    $j.blockUI({ 
        message: $div, 
        fadeIn: 700, 
        fadeOut: 700, 
        timeout: 2000, 
        showOverlay: false, 
        centerY: false,
        css: { 
            width: '350px', 
            top: '25px', 
            left: '', 
            right: '10px', 
            border: 'none', 
            padding: '5px', 
            backgroundColor: color, 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: .6, 
            color: '#fff' 
        } 
    });
}
	
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
	
function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return(setStr);
}
	
// -- Articles --
	
function activateHighlight(str) {		
    $j(".library").removeHighlight().each(function(){ 
        $j.highlight(this, str); 
    });
}
	
// -- Png fix --
	
function activatePngFix() {
    $j(".transparent, #footer").pngFix();
}
			
// -- Addithional --
	
function slideFlashMessanger(message) {
    jQuery('#messages').hide();
		
    if(message) {
        jQuery('#messages ul li:first').html(message);
    }
		
    jQuery('#messages').slideDown();
    setTimeout(function(){
        jQuery('#messages').slideUp();
    }, 3200);
}
	
function addAjaxIndicator(obj) {
    $j(obj).html('<img src="/images/ajax_load.gif" class="ajax_load" />');
}
	
function activateCalendar() {	
    // Календарь
    $j(".calendar-input").datepicker( {
        mandatory : true,
        yearRange : '1920:2020',
        dateFormat : $j.datepicker.ATOM
    }).attr("readonly", "readonly");
	
    $j(".calendar-image").bind('click', function() {
        $j(this).prev().focus();
    }).css("cursor", "pointer");
}
			
function ajaxError(){
    alert("Ошибка при передаче данных! Попробуйте снова");
}
	
function reloadPage(){
    window.location.reload();
    return;
}
	
function checkResponse(json) {	
    if (typeof (json) == 'undefined') {
        alert("Ошибка при передаче данных! Попробуйте снова");
        return false;
    }
			
    // var json = eval("(" + responseText + ")");	
    if (typeof (json) != 'object' && typeof (json) != 'array') {
        alert("Ошибка при передаче данных! Попробуйте снова");
        return false;
    }
	
    return json;
}
			
function var_dump(obj) {
    var result = null;
    for (var i in obj)
        result += 'object' + '.' + i + ' = ' + obj[i] + '\n';
    return result;
}
	 
function activateblock(){
    $j.blockUI({
        css: { 
            border: 'none', 
            padding: '15px', 
            backgroundColor: '#000', 
            '-webkit-border-radius': '10px', 
            '-moz-border-radius': '10px', 
            opacity: '.5', 
            color: '#fff'				
        }, 
        overlayCSS:{
            'z-index': 1007
        }
    }); 
}
	
function deactivateblock(){
    $j.unblockUI();
}
	
function you_are_sure(str){
    return confirm(str);
}
