﻿

var modnyspb = {
    replaceLetters: function(node) {
        $(node).each(function(){
            $(this).html($(this).html().replace('д','<small>D</small>'));
            $(this).html($(this).html().replace('у','<small>Y</small>'));
        });
        return this;
    },
    initCloseButtons: function(buttonNode,blockNode) {
        openedHtml = '<div class="hide-message"><div class="transparent-background"></div>'+
            '<div class="text">При необходимости, Вы можете скрыть этот блок.</div></div>'+
            '<span class="opentext" style="display:none;">раскрыть</span><span class="button">x</span>';
        closedHtml = '<div class="hide-message"><div class="transparent-background">'+
            '</div><div class="text">При необходимости, Вы можете скрыть этот блок.</div></div>'+
            '<span class="opentext">раскрыть</span><span class="button open">+</span>';
        $(buttonNode).attr('visible',
                function(){
                    if ($(this).find(' + '+blockNode).find('.closeable-body').css('display') == 'none') {
                        $(this).html(closedHtml);
                        return 'no';
                    } else {
                        $(this).html(openedHtml);
                        return 'yes';
                    }
                    //return (($(this).parent(buttonNode).find('+ '+blockNode).find('.closeable-body').css('display')=='none')?'no':'yes');
                }
            );
        openClose = function(){
            p = $(this).parent(buttonNode);
            t = $(this);
            if (p.attr('visible')=='yes') {
                if (t.hasClass('button')) t.text('+').addClass('open');
                p.find('.opentext').fadeIn();
                p.find('.hide-message').fadeOut();
                p.find('+ '+blockNode).find('.closeable-body').slideUp();
                p.attr('visible','no');
                p.find('+'+blockNode).fadeTo('fast', 1,
                    function(){if(jQuery.browser.msie){this.style.removeAttribute('filter')}});
                p.find('.opentext').addClass('hover');
				$.cookie('block_'+p.attr('itemid'), '1', { expires: 365 });
            } else {
                if (t.hasClass('button')) t.text('x').removeClass('open');
                else p.find('.button').text('x').removeClass('open');
                p.find('.opentext').fadeOut();
                p.find('+ '+blockNode).find('.closeable-body').slideDown();
                p.attr('visible','yes');
				
				$.cookie('block_'+p.attr('itemid'), '0', { expires: 365 });
            }
        };
        hover = function(){
            p = $(this).parent(buttonNode);
            if (p.attr('visible')=='yes') {
                p.find(' + '+blockNode).fadeTo('fast', 0.3);
                p.find('.hide-message').fadeIn(10);
            } else {
                p.find('.opentext').addClass('hover');
            }
        };
        unhover = function(){
            p = $(this).parent(buttonNode);
            if (p.attr('visible')=='yes') {
                p.find('+'+blockNode).fadeTo('fast', 1,
                    function(){if(jQuery.browser.msie){this.style.removeAttribute('filter')}});
                p.find('.hide-message').fadeOut(10);
            } else {
                p.find('.opentext').removeClass('hover');
            }
        };
        $(buttonNode).find('.button').hover(hover,unhover).click(openClose);
        $(buttonNode).find('.opentext').hover(hover,unhover).click(openClose);
        return this;
    },
    dropInputDefaulText: function(btnNode,text){
        $(btnNode).focus(function(){if(this.value==text){this.value=''}}
            ).blur(function(){if(this.value==''){this.value=text}});
        return this;
    },
    preloadImages: function(images){
        imagesSrc = new Array();
        for (i = 0; i < images.length; i++) {
            imagesSrc[i] = new Image();
            imagesSrc[i].src = 'images/buttons/'+images[i];
        }
        return this;
    },
    uncheckLetters: function(){
      $('#catalogue-filter .advanced-filter input').removeAttr('checked');
      $('#catalogue-filter .advanced-filter div').removeClass('selected');
    },
    initAlphabetFilter: function(node){
        this.uncheckLetters();
        $(node).find('div').click(function(){
            if ($(this).hasClass('selected')) {
                $(this)
                    .removeClass('selected')
                    .find('+input').removeAttr('checked');
            } else {
                $(this)
                    .addClass('selected')
                    .find('+input')
                        .attr('checked','checked').attr('value',$(this).html()+"%");
            }
        });
        return this;
    },
    closeFilterTab: function(){
        this.uncheckLetters();
        $('#catalogue-filter .filter-items li').removeClass('selected');
        $('#catalogue-filter .advanced-filter').slideUp('normal',function(){
            $('#catalogue-filter .tab').css('display','none');
            $('#catalogue-filter .filter-form').slideDown('normal');
        });
        $('#filter').attr('value','none');
		$.cookie('block_filtr', '', { expires: 365 });
    },
    switchFilterTab: function(tab/*,alltext*/) {
        jtab = $('#'+tab);
        if (jtab.css('display') == 'none') {
            this.uncheckLetters();
            $('#filter').attr('value',tab);
            $('#catalogue-filter .filter-items li').removeClass('selected');
            $('#catalogue-filter .filter-form').slideUp('normal',function(){
                $('#catalogue-filter .filter-form').css('display','none');
                //$('#catalogue-filter .show-all').css('display','block').find('span').html(alltext);
                $('#'+tab+'-li').addClass('selected');
                $('#catalogue-filter .advanced-filter').slideUp('normal',function(){
                    $('#catalogue-filter .tab').css('display','none');
                    jtab.css('display','block');
					$.cookie('block_filtr', tab, { expires: 365 });
                    $('#catalogue-filter .advanced-filter').slideDown('normal');
                });
            });
        } else {this.closeFilterTab();}
    }
}
$(document).ready(function(){

 
 
var shop_count=1;
$(".tccs").change(function(){
if($(this).val()==-1)
	$(this).next().next().show();
else $(this).next().next().hide(); 
}); 

 $('#add_addr').click(function(){
	shop_count++;
	$(this).before('<div class="addr_all">'+$(this).next().html()+'</div>');
	$(this).prev().find("b").text("Адрес "+shop_count+"-ого магазина");
	$(this).prev().find(".tccs").change(function(){
		if($(this).val()==-1)
			$(this).next().next().show();
		else $(this).next().next().hide(); 
	}); 
 });
 

    $('.voted').tooltip({
    track: true,
    delay: 85,

    opacity: 1
});

	$("#uploadify").uploadify({
		'uploader'       : '/bitrix/templates/new_main/swf/uploadify.swf',
		'script'         : '/uploadify.php',
		'cancelImg'      : '/bitrix/templates/new_main/images/cancel.png',
		'folder'         : '/upload/calendar',
		'auto'           : false,
		'fileExt'		 : '*.png;*.jpg;*.gif;*.jpeg',
		'fileDesc'		 : 'Images',
		'multi'          : false,
		'sizeLimit' 	 : 1048576,
		'buttonImg'		 : '/bitrix/templates/new_main/images/browse_btn.png',
		'buttonText' 	 : '',
		'onComplete'	 : function(event, queueID, fileObj, response, data) {
								$("#div_add_form").append('<input type="hidden" name="detail_pic" value="'+fileObj.name+'" />');
	},
		'onAllComplete'	 : function (){
								$('#upl_status_q1').text('0');
								if($('#upl_status_btn').text()=='1')
									qCheck();
		},
		'onSelect'		 : function(){
								$('#upl_status_q1').text('2');
		},
		'onProgress'	 :function(){
								$('#upl_status_q1').text('1');
								
		}
});
	 
	 
	
 	$("#uploadify1").uploadify({
		'uploader'       : '/bitrix/templates/new_main/swf/uploadify.swf',
		'script'         : '/uploadify.php',
		'cancelImg'      : '/bitrix/templates/new_main/images/cancel.png',
		'folder'         : '/upload/calendar',
		'fileExt'		 : '*.png;*.jpg;*.gif;*.jpeg',
		'fileDesc'		 : 'Images',
		'auto'           : false,
		'sizeLimit' 	 : 1048576,
		'multi'          : true,
		'buttonImg'		 : '/bitrix/templates/new_main/images/browse_btn.png',
		'buttonText' 	 : '',
		'onComplete'	 : function(event, queueID, fileObj, response, data) {
								$("#div_add_form").append('<input type="hidden" name="pic[]" value="'+fileObj.name+'" />');
	},
		'onAllComplete'	 : function (){
								$('#upl_status_q2').text('0');
								if($('#upl_status_btn').text()=='1')
									qCheck();
		},
		'onSelect'		 : function(){
								$('#upl_status_q2').text('2');
		},
		'onProgress'	 :function(){
								$('#upl_status_q2').text('1');
								
		}
	});
$("#cal_sug").autocomplete('http://modny-spb.ru/suggest_ca.php');
//$("#suggest_c").autocomplete(['третье', 'тройка', 'трактор']);
    $('input:checkbox:not([name="letters[]"])')
        .checkbox({cls:'jquery-safari-checkbox', empty:'/bitrix/templates/new_main/css/checkbox/empty.png'}); /*/bitrix/templates/main_new/*/
    modnyspb
        .replaceLetters('#mainmenu li a')
        .initCloseButtons('.colse-block-button','.closeable-block')
        .dropInputDefaulText('.subscribeEmail', 'ваш e-mail')
        .dropInputDefaulText('.searchQuery', 'поиск по сайту')
        .dropInputDefaulText('#catalogue-filter .search', 'поиск по каталогу')
        .dropInputDefaulText('#calendar-filter .search', 'поиск по календарю')
        .preloadImages(['ok_on.gif','ok_small_on.gif'])
        .initAlphabetFilter('#catalogue-filter .alphabet');

	$('.all_collect').hover(function(){
		$('.stee').show();
		$('.under_title').show();
		$('.title').addClass('top');
	}, function(){
		$('.stee').hide();
		$('.title').removeClass('top');
		$('.under_title').hide(); 
	});
	$('a[sl_id]').click(function(){
		var t=$(this).attr('sl_id');
		var f=$(this).text();
		$('span.colname').text(f); 

		$('div[citem]').removeClass('visible');
		$("div[citem='"+t+"']").addClass('visible');
		collect_init();
		//unhover:
		$('.stee').hide();
		$('.title').removeClass('top');
		$('.under_title').hide();
		
	});

$(".calen").hover(
	function(){$(this).find(".h_text").show()}, 
	function(){$(this).find(".h_text").hide( )}
	);
	
	 
});


