if ($.browser.msie && $.browser.version <= 6 || $.browser.mozilla && $.browser.version.slice(0,3) <= "1.9"){
$('body').empty();
$('body').load('/error/error.html', function(){
	alert('Данный сайт не поддерживает устаревшие версии браузеров.');
})
}
$(document).ready(function(e) {
	/*	var bH = $(window).height()-156;
		if( bH > 683) {
			$('.main-img, .main-page-carusel').css({
				'height':bH
			});

		}
		if (bH < 683) {
			$('.main-img, .main-page-carusel').css({
				'height':'683px'
			});
		}
	$(window).resize(function(){
		var bH = $(window).height()-156;
		if( bH > 700) {
			$('.main-img, .main-page-carusel').css({
				'height':bH
			});
		}
		if (bH < 683) {
			$('.main-img, .main-page-carusel').css({
				'height':'683px'
			});
		}
		return false;
		$(window).resize();
	})*/

	if ( $.browser.msie && $.browser.version <=7) {
	}
	else {
	  var params = {
		changedEl: ".lineForm select",
		scrollArrows: false,
		visRows: 5
	  }
	  cuSel(params);
	}
    
    /*$('#locationSelectCity').live('change', function() {
        alert(1);   
        divaCitiesReload(this, 'locationSelectCity');
    });*/
	
	if($('.radio').length > 0){
		$(".radio").dgStyle();
	}
	if ($('.checkbox').length > 0) {
		$(".checkbox").dgStyle();
	}
});	

/*COLORS*/
/*$('.catalog-menu ul li .sub-menu.i-colors li').find('a').each(function(index) {
	var i = parseInt(20*index)
    $(this).css({
		'background-position': '-'+i+'px top' 
	});
})*/;
/*-----*/
$(window).load(function(){
	$('.input-radio, .first-radio').each(function(s) {
		$(this).find('.radio').each(function(index) {
			var d = parseFloat('0.'+index);
			var index = 0.1+d;
			$(this).css('opacity', 0.5+index)
		});
    });
});

/*-----*/

if ($.browser.opera || $.browser.mozilla && $.browser.version.slice(0,3) == "1.9"){
	$('.item-round-inner').prepend($('<div class="big-mask"></div>'))
	$('.main-img .round a b, .item.right .round a b').find('img').each(function(index){
		var way = $(this).attr('src')
		var w = $(this).width();
		var h = $(this).height();
		$('<span class="o-img"></span>').insertBefore(this);
		$(this).closest('b').find('.o-img').css({'background-image': ' url('+way+')', 'width':w,'height':h});
		$(this).css({'display':'none'});
	})
}
if ( $.browser.msie && $.browser.version <=8) {
	$('.item-round-inner').prepend($('<div class="big-mask"></div>'))
	$('.catalog-menu ul li').find('a').stop().click(function() {
	if ($(this).closest('li').has('ul.sub-menu').length > 0){
		$('.sub-menu').hide();
		$('li.active').removeClass('active');
	    $(this).closest('li').toggleClass('active');
		$(this).closest('li').find('.sub-menu').toggle();
        return false;
	}

});
$('.order-round a span').each(function(){
	var h = parseInt($(this).height()/2);
	$(this).css('margin-top','-'+h+'px');
});
$('.phone').each(function(){
	var h = parseInt(($(this).height()/2)-($(this).find('b').height()/2));
	$(this).find('b').css('margin-top',+h+'px');
});


}


else {
	$('.catalog-menu ul li').find('a').click(function(e) {
		if ($(this).closest('li').has('ul.sub-menu').length > 0){
			$('.sub-menu').slideUp();
			$('li.active').removeClass('active');
			$(this).closest('li').toggleClass('active');
			$(this).closest('li').find('.sub-menu').slideToggle();
            return false;
		}
		
	});

}

//.round a:hover b img[width="176"]
$('.round a').each(function() {
    if ($(this).find('img, .o-img').width() == 186 || $(this).find('img, .o-img').width() > 176){
		$(this).find('img, .o-img').css('width', 176)
	}
	if ($(this).find('img, .o-img').height() == 186 || $(this).find('img, .o-img').height() > 176){
		$(this).find('img, .o-img').css('height', 176)
	}
	if ($(this).find('.main-img img, .o-img').css('height') !== 176 ){
		$(this).find('.main-img img, .o-img').css('height', 176)
	}
	if ($(this).find('.main-img img, .o-img').css('width') !== 176 ){
		$(this).find('.main-img img, .o-img').css('width', 176)
	}
	if ($(this).find('b').is('.no-top')){
		var h = parseInt($(this).find('b.no-top img, b.no-top .o-img').css('height'))
		var w = parseInt($(this).find('b.no-top img, b.no-top .o-img').css('width'))
		$(this).find('b.no-top img, b.no-top .o-img').css('height', h-10);
		$(this).find('b.no-top img, b.no-top .o-img').css('width',  w-10);
	}
});
$('.round a').hover(function(){
	
	$(this).find('img, .o-img').data('width', $(this).find('img, .o-img').width())
	$(this).find('img, .o-img').data('height', $(this).find('img, .o-img').height())
	if ( $.browser.msie && $.browser.version <=8) {
	}
	else {
		$(this).find('img, .o-img').css({
			'width':$(this).find('img, .o-img').data('width')+10,
			'height':$(this).find('img, .o-img').data('height')+10
		});
	}
},
	function(){
		$(this).find('img, .o-img').css({
		'width':$(this).find('img, .o-img').data('width'),
		'height':$(this).find('img, .o-img').data('height')
		});
})

$('.order-round a span').each(function(){
	var h = parseInt($(this).height()/2);
	$(this).css('margin-top','-'+h+'px');
	

});
$('.phone').each(function(){
	var h = parseInt(($(this).height()/2)-($(this).find('b').height()/2));
	$(this).find('b').css('margin-top',+h+'px');
});


/**
* Магазины
*/
function divaCitiesReload(select, idToReload)
{
    //alert(idToReload);
    if (select == null) {
        loadShopsList();    
    }
    var reload = false;
    if (idToReload != 'page') {
        var itemToReload = $('#' + idToReload);
        var countryId = parseInt($(select).val());
        if (! (countryId > 0) ) return true;
        var list = divaCitiesList['section_' + countryId];
        
        if (itemToReload.is('select') == true){
            var content = '<option value="0">...</option>';    
            if (list.length > 0) {
                for (i = 0; i < list.length; i++) {
                    content += '<option value="' + list[i].id + '">' + list[i].name + '</option>';
                }
            } else {
                reload = true;
            }
            itemToReload.html(content);
        } else {
            var content = '<span val="0" class="selected">...</span>';
            if (list.length > 0) {
                for (i = 0; i < list.length; i++) {
                    content += '<span val="' + list[i].id + '">' + list[i].name + '</span>';
                }
            } else {
                //$('#locationSelectCity').val('');
                reload = true;
            }
            $('#' + idToReload).val('0');
            $('#cusel-scroll-' + idToReload).html(content);
            var params = {
                refreshEl: "#" + idToReload,
                visRows: 5,
                scrollArrows: false
            }
            cuSelRefresh(params);
            $('#cuselFrame-' + idToReload + ' div.cuselText').html('...');
            $('#cusel-scroll-' + idToReload + ' span[val="0"]').click();
        }
    } else {
        if ($(select).val() != '0') {
            reload = true;
        }
    }
    
    if (reload == true || 1 == 1) {
        loadShopsList();
    }
}

function divaJobReload(select, idToReload)
{
    //alert(idToReload);
    if (select == null) {
        loadShopsList();    
    }
    var reload = false;
    if (idToReload != 'page') {
        var itemToReload = $('#' + idToReload);
        var countryId = parseInt($(select).val());
        if (! (countryId > 0) ) return true;
        var list = divaCitiesList['section_' + countryId];
        if (itemToReload.is('select') == true){
            var content = '<option value="0">...</option>';    
            if (list.length > 0) {
                for (i = 0; i < list.length; i++) {
                    content += '<option value="' + list[i].id + '">' + list[i].name + '</option>';
                }
            } else {
                reload = true;
            }
            itemToReload.html(content);
        } else {
            var content = '<span val="0" class="selected">...</span>';
            if (list.length > 0) {
                for (i = 0; i < list.length; i++) {
                    content += '<span val="' + list[i].id + '">' + list[i].name + '</span>';
                }
            } else {
                reload = true;
            }
            $('#' + idToReload).val('0');
            $('#cusel-scroll-' + idToReload).html(content);
            var params = {
                refreshEl: "#" + idToReload,
                visRows: 5,
                scrollArrows: false
            }
            cuSelRefresh(params);
            $('#cuselFrame-' + idToReload + ' div.cuselText').html('...');
            $('#cusel-scroll-' + idToReload + ' span[val="0"]').click();
        } 
    } else {
        if ($(select).val() != '0') {
            reload = true;
        }
    }
    
    
}

function loadShopsList()
{
    $('#shopsListRight').html('<p style="text-align:center;"><img style="margin-top: 30px;" src="/bitrix/tpl_new/images/ajax-loader.gif" alt="Загружаем..." /></p>');
    $.ajax({
        type: 'GET',
        url: '/bitrix/_ajax/shops.php',
        data: {
            IBLOCK_ID: $('#locationIblockId').val(),
            COUNTRY_ID: $('#locationSelectCountry').val(),
            SECTION_ID: $('#locationSelectCity').val(),
            METRO: $('#locationSelectMetro').val()
        },
        success: function(data) {
            $('#shopsListRight').html(data);
            $("#shopsListRight .carusel").jCarouselLite({
                btnNext: ".bot-arr",
                btnPrev: ".top-arr",
                speed: 800,
                visible:3,
                vertical:true,
				mouseWheel: true,
                circular:true
            });
        }
    });
}

	


/*
if( $('input[type=radio]').length > 0 || $('input[type=checkbox]').length > 0){
	$('input[type=radio]').each(function(){
		$(this).wrap('<div class="radio" />');
		$(this).closest('.input-radio').find('label[for]').remove()
	})
}
*/

