function inputIn(obj, text) {
   if ($(obj).val() == text) {
      $(obj).val('');
      $(obj).removeClass('empty');
   }
}
function inputOut (obj, text) {
   if ($(obj).val() == '' || $(obj).val() == text) {
      $(obj).val(text);
      $(obj).addClass('empty');
   }
}
function inputHelper(obj, text) {
   $(obj)
      .bind ('focus', function () {
         inputIn (this, text);
      })
      .bind ('blur', function () {
         inputOut (this, text);
      });
	inputOut(obj, text);
}
    
function scrollpane(){
	if ($('.health').length == 0 && $('.scrollpane').length > 0) {
        $('.scrollpane').jScrollPane({
            scrollbarWidth: 20,
            dragMinHeight: 20,
            dragMaxHeight: 20
        });
    }
}

$(document).ready(function() {

	inputHelper($('.index-search-field').addClass('empty'), 'поиск по каталогу');

	if ($('.lightbox-gallery a').length > 0) $('.lightbox-gallery a').lightBox();

	scrollpane()

    if ($('.flash').length > 0) {
        $fw = 1080;
        $fh = 600;
        $('.flash').flash(
        { src: 'flash.swf',
        bgcolor: '#b8d25e',
        wmode: 'opaque',
        width: $fw,
        height: $fh },
        { version: 8 }
        );
    }

    if ($('.health').length > 0) {
        var popupclick = false;
        $('.health').click(function(){
            if (popupclick) {
                popupclick = false;
            } else {
                $('.hpopup').hide();
                return false;
            }
        });
        $('.click').click(function(){

            var id = $(this).attr('id').match(/\d+/);
            
            if (typeof(data[id]) == 'undefined') return ;

            $('.hpopup .scrolltop h2').html(data[id].t);
            $('.hpopup .scrollpane .htext p').html(data[id].d);

            $('.scrollpane .searchrow').remove();

            for (i in data[id].p)
            {
                $('.scrollpane').append('<div class="searchrow clearfix"><div class="search2">' +
                '<img src="' + BASE_URL + data[id].p[i].image + '"/></div><div class="search3">' +
                '<a href="' + BASE_URL + data[id].p[i].url + '">' + data[id].p[i].title + '</a>' +
                //'<p>'+ data[id].p[i].typetitle +'</p>' +
                '<div class="tteatype">' +
                '<div title="'+ data[id].p[i].typetitle +'" class="teatype'+ data[id].p[i].typeid +'"></div>' +
                '<em>'+ data[id].p[i].typetitle +'</em>' +
                '</div>' +
                '</div></div>');
            }

            $('.hpopup').css({ left: (parseInt($(this).css('left'))+25)+'px', top: (parseInt($(this).css('top'))-54)+'px' });
            $('.hpopup').show();
            $('.scrollpane').jScrollPane({
                scrollbarWidth: 20,
                dragMinHeight: 20,
                dragMaxHeight: 20
            })[0].scrollTo(0);

            return false;
        });
        $('.hpopup').click(function(){
            popupclick = true;
        });

        //test
        $('#click3').click();
    }


    if ($('.itemline').length > 0) {
        $('.itemtitle').click(function(){
            if ($(this).attr('id') != '') {
                $('#'+$(this).attr('id')+'_line').toggle();
            }
        });

        //test
        $('#it2').click();
    }

    if ($('.cartrow').length > 0) {
        $('.cartrow .cart1 input').each(function(){
            if (!$(this).attr('checked')) {
                //удалить из корзины
                $(this).parent().parent().addClass('cartdel');
            }
        });
        $('.cartrow .cart1 input').click(function(){
            if ($(this).attr('checked')) {
                //вернуть в корзину
                $(this).parent().parent().removeClass('cartdel');
            } else {
                //удалить из корзины
                $(this).parent().parent().addClass('cartdel');
            }
        });
    }

    if ($('.cartp').length > 0) {
        $('.cartp').hover(function() {
            $('.cartpopup').show();
        }, function() {
            $('.cartpopup').hide();
        });
    }
    
    $('.faq h2 a').click(function () {
        var c = $(this).parents('.faq').find('.questions');
        if (c.css('display') == 'none') {
            c.slideDown()
        } else {
            c.slideUp();
        }

        $(this).parents('.faq').siblings().each(function () {
            $(this).find('.questions').slideUp();
        });
    });

    $('.questions > li > a').click(function () {
        var c = $(this).parents('li').find('.reply');
        if (c.css('display') == 'none') {
            c.slideDown()
        } else {
            c.slideUp()
        }
    });

    if ($('a.lightbox').length > 0 && typeof $('a.lightbox').lightBox == 'function') $('a.lightbox').lightBox();
    
   

    $('.but_print a').click(function() {
      if (window.print) {
         $('.but_print').hide();
         window.print();
      }
      return false;
    });
    $('.print-wrapper').click(function() {
      $('.but_print').show();
    });

});


function hideSiblings(element) {
    $(element).siblings().each(function () {
        $(this).children('.title').removeClass('active');
        contentHide(this);
    });
}



