$(document).ready(function(){

var mw = $(window).width();
var mww = (mw/2)-480;

var mmw = $(window).width();
var mmww = (mmw/2)-300;

var mmh = $(window).height();
var mmhh = (mmh/2)-150;

//h = $(window).height();
//hh = (h/2-120);
//$('.howto').css({'top':hh+'px'});

$('.howto').bind({
        click: function () { window.location = '/how_to_buy/'},
    mouseover: function() { $(this).css({'background':'url(/images/howo.png) no-repeat left top'}); },
     mouseout: function() { $(this).css({'background':'url(/images/hown.png) no-repeat left top'}); }
})                                                                                                                


$('.atten').css({'left':mmww+'px','top':mmhh+'px'});

$('#attenx').click(function(){ $('.atten').hide(); });

$('.search-bar').css({ 'left':mww+'px', 'top':'68px' });

var sod = $('.sod').html();

if (sod!=null) $('.cart').css({'background':'url(/images/cartf.png)'});
if (sod==null) $('.cart').css({'background':'url(/images/carte.png)'});

var counts=0;

$('#qq').keypress(function (e)
{
	var c = String.fromCharCode(e.which);

	var cccc = $(this).val()+c;

	var counts  = cccc.length;

	$.get('/search-bar.php', { 'cccc': cccc, 'counts':counts }, function(data)
	{      
		if (data)
		{
			$('.search-bar').empty();
			$('.search-bar').append(data);
			$('.search-bar').slideDown('slow');
		}
		else
		{
			$('.search-bar').slideUp('slow');
		}
	});

	if ( e.keyCode == 8)
	{
		var counts  = (cccc.length);

		var cccc = $(this).val();

		$.get('/search-bar.php', { 'cccc': cccc, 'counts':counts }, function(data)
		{      
			if (cccc)
			{
				$('.search-bar').empty();
				$('.search-bar').append(data);
				$('.search-bar').slideDown('slow');
			}
			else
			{
				$('.search-bar').slideUp('slow');
			}
		});
	}  
});

$('#qqqq').click(function(){

	var slovo = $('#qq').val();

	$.get('/search-bar-save.php',{'slovo':slovo }, function(data)
	{

	});    								 
});

$('.menu-divider:last').hide();

$('.mainpage1').bind({
        click: function () { window.location = '/maneken/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face1o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face1n.jpg)'}); }
})                                                                                                                

$('.mainpage2').bind({
        click: function () { window.location = '/articles/205/747/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face2o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face2n.jpg)'}); }
})

$('.mainpage3').bind({
        click: function () { window.location = '/catalog/lech_trikotaj/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face3o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face3n.jpg)'}); }
})

$('.mainpage4').bind({
        click: function () { window.location = '/catalog/ortoped_izdelia/golenostop_i_stopa/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face4o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face4n.jpg)'}); }
})

$('.mainpage5').bind({
        click: function () {window.location = '/catalog/Ortoped_pillow/' },
    mouseover: function() { $(this).css({'background':'url(/images/new_face5o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face5n.jpg)'}); }
})

$('.mainpage6').bind({
        click: function () { window.location = '/articles/157/368/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face6o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face6n.jpg)'}); }
})

$('.mainpage7').bind({
        click: function () { window.location = '/ortoshka/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face7o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face7n.jpg)'}); }
})

$('.mainpage8').bind({
        click: function () { window.location = '/offers/doctor/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face8o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face8n.jpg)'}); }
})

$('.mainpage9').bind({
        click: function () { window.location = '/catalog/stelki/'},
    mouseover: function() { $(this).css({'background':'url(/images/new_face9o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face9n.jpg)'}); }
})

$('.mainpage10').bind({
        click: function () { window.location ='/catalog/reabilitation' },
    mouseover: function() { $(this).css({'background':'url(/images/new_face10o.jpg)'}); },
     mouseout: function() { $(this).css({'background':'url(/images/new_face10n.jpg)'}); }
})

$('.prop1').each(function(){
	var prop = $(this).html();

	if (prop.indexOf('Армед') != -1) { $(this).empty(); $(this).append('<img src=/images/armed.png>'); }
	if (prop.indexOf('Medi') != -1) { $(this).empty(); $(this).append('<img src=/images/medi.png>'); }
	if (prop.indexOf('Orlett') != -1) { $(this).empty(); $(this).append('<img src=/images/orlett.png>'); }
	if (prop.indexOf('Ortenberg') != -1) { $(this).empty(); $(this).append('<img src=/images/ortenberg.png>'); }
	if (prop.indexOf('Otto Bock') != -1) { $(this).empty(); $(this).append('<img src=/images/otto_bock.png>'); }
	if (prop.indexOf('Roten') != -1) { $(this).empty(); $(this).append('<img src=/images/roten.png>'); }
	if (prop.indexOf('Trelax') != -1) { $(this).empty(); $(this).append('<img src=/images/trelax.png>'); }
	if (prop.indexOf('Pedag') != -1) { $(this).empty(); $(this).append('<img src=/images/pedag.png>'); }
	if (prop.indexOf('Fresco') != -1) { $(this).empty(); $(this).append('<img src=/images/fresco.png>'); }
	if (prop.indexOf('Bronigen') != -1) { $(this).empty(); $(this).append('<img src=/images/bronigen.png>'); }
	if (prop.indexOf('Amoena') != -1) { $(this).empty(); $(this).append('<img src=/images/amoena.png>'); }
});

$('.propp1').each(function(){
	var prop = $(this).html();

	if (prop.indexOf('Армед') != -1) { $(this).empty(); $(this).append('<img src=/images/armed1.png>'); }
	if (prop.indexOf('Medi') != -1) { $(this).empty(); $(this).append('<img src=/images/medi1.png>'); }
	if (prop.indexOf('Orlett') != -1) { $(this).empty(); $(this).append('<img src=/images/orlett1.png>'); }
	if (prop.indexOf('Ortenberg') != -1) { $(this).empty(); $(this).append('<img src=/images/ortenberg1.png>'); }
	if (prop.indexOf('Otto Bock') != -1) { $(this).empty(); $(this).append('<img src=/images/otto_bock1.png>'); }
	if (prop.indexOf('Roten') != -1) { $(this).empty(); $(this).append('<img src=/images/roten1.png>'); }
	if (prop.indexOf('Trelax') != -1) { $(this).empty(); $(this).append('<img src=/images/trelax1.png>'); }
	if (prop.indexOf('Pedag') != -1) { $(this).empty(); $(this).append('<img src=/images/pedag1.png>'); }
	if (prop.indexOf('Fresco') != -1) { $(this).empty(); $(this).append('<img src=/images/fresco1.png>'); }
	if (prop.indexOf('Bronigen') != -1) { $(this).empty(); $(this).append('<img src=/images/bronigen1.png>'); }
	if (prop.indexOf('Amoena') != -1) { $(this).empty(); $(this).append('<img src=/images/amoena1.png>'); }
});

/*
$('#faq_button').click(function(){

       fio = $('input#fio').val();
     email = $('input#email').val();
     otziv = $('textarea#otziv').val();
     $.post('/faq/records/addrec.php',{'fio':fio, 'email':email, 'otziv':otziv }, function(data)
     {
	 $('input#fio').val('');
	 $('input#email').val('');
	 $('textarea#otziv').val('');
	 alert(data);
	window.location = '/faq/';
     });    								 
});
*/

$('#mains').bind({
    mouseover: function() { $(this).attr('src','/images/maino.gif'); },
     mouseout: function() { $(this).attr('src','/images/mainn.gif'); }
})

$('#questions').bind({
    mouseover: function() { $(this).attr('src','/images/questiono.gif'); },
     mouseout: function() { $(this).attr('src','/images/questionn.gif'); }
})

$('#manekens').bind({
    mouseover: function() { $(this).attr('src','/images/manekeno.gif'); },
     mouseout: function() { $(this).attr('src','/images/manekenn.gif'); }
})

$('a').each(function(){
	$(this).click(function(){
		var ssy = $(this).attr('href');
		if (ssy=='/about/') $(this).attr('href','#');
		if (ssy=='/offers/') $(this).attr('href','#');
		if (ssy=='/actions/') $(this).attr('href','#');
	});
});

var catt1 = $('.map-level-0').text();

var bread_name1 = $('.idd1').text();

if (bread_name1.indexOf('Лечебный трикотаж') != -1) $('.idd3').hide();
if (bread_name1.indexOf('Ортопедические изделия') != -1) $('.idd3').hide();
if ((bread_name1.indexOf('Госпитальный компрессионный трикотаж') != -1)||(bread_name1.indexOf('Компрессионный трикотаж для лимфологии') != -1)||(bread_name1.indexOf('Профилактический трикотаж') != -1)||(bread_name1.indexOf('Аксессуары') != -1)) $('.idd2').hide();

var model  = $('select[name=arrFilter_pf[MODEL]] option:selected').text();
var razmer = $('select[name=arrFilter_pf[RAZMER]] option:selected').text();
var color  = $('select[name=arrFilter_pf[COLOR]] option:selected').text();

//alert(model+razmer+color);

if ((model)&&(razmer)&&(color))
{
	if ((model=='(все)')&&(razmer=='(все)')&&(color=='(все)')) $('.catalog-section').hide();
	if ((model!='(все)')||(razmer!='(все)')||(color!='(все)')) $('.catalog-section').show();
}

if ((model)&&(!razmer)&&(!color))
{
	if (model=='(все)') $('.catalog-section').hide();
	if (model!='(все)') $('.catalog-section').show();
}

if ((model)&&(razmer)&&(!color))
{
	if ((model=='(все)')&&(razmer=='(все)')) $('.catalog-section').hide();
	if ((model!='(все)')||(razmer!='(все)')) $('.catalog-section').show();
}

if ((model)&&(color)&&(!razmer))
{
	if ((model=='(все)')&&(color=='(все)')) $('.catalog-section').hide();
	if ((model!='(все)')||(color!='(все)')) $('.catalog-section').show();
}

if ((razmer)&&(!model)&&(!color))
{
	if (razmer=='(все)') $('.catalog-section').hide();
	if (razmer!='(все)') $('.catalog-section').show();
}

if ((!model)&&(color)&&(razmer))
{
	if ((razmer=='(все)')&&(color=='(все)')) $('.catalog-section').hide();
	if ((razmer!='(все)')||(color!='(все)')) $('.catalog-section').show();
}

$('.sf').each(function(){
$(this).bind({
	click: function()
	{
		var uri = $('#uri').val();
		var idpid = $(this).attr('idpid');
		var idbid = $(this).attr('idbid');
		var pid = $('#pid'+idpid).val();
		var bid = $('#bid'+idbid).val();
		$.post('/personal/cart/preindex2.php',{ 'pid':pid, 'bid':bid }, function(data)
		{
			alert('Товар добавлен в корзину');
			window.location = uri;
		}); 
	}
})
});


});
