var URL = getBase();
function getBase() {
    var metas = document.getElementsByTagName('meta');
    for (var i = 0; i < metas.length; i++) if (metas[i].getAttribute('name') == 'base') break;
    return metas[i].getAttribute('content');
}

// highslide
hs.graphicsDir = URL+'img/hs/';
hs.showCredits = false;
hs.allowMultipleInstances = false;
hs.preserveContent = false;
hs.restoreCursor = '';
hs.outlineType = null;
hs.align = 'center';
hs.dimmingOpacity = .5;
hs.dimmingGeckoFix = true;
hs.expandDuration = 0;
hs.restoreDuration = 0;
hs.transitionDuration = 0;
hs.dimmingDuration = 0;
hs.registerOverlay({
    overlayId: 'closebutton',
    position: 'top right',
    useOnHtml: true
});
// highslide slideshow
if (hs.addSlideshow) hs.addSlideshow({
    slideshowGroup: 'gallery',
    interval: 4000,
    repeat: false,
    useControls: true,
    fixedControls: 'fit',
    overlayOptions: {
        opacity: .5,
        position: 'bottom center'
    }
});

var params = {wmode: 'opaque', bgcolor: '#015613'};
swfobject.embedSWF(URL+'swf/body_lt.swf', 'lt', '630', '800', '9.0.0', 'expressInstall.swf', {}, params);
swfobject.embedSWF(URL+'swf/body_rt.swf', 'rt', '340', '400', '9.0.0', 'expressInstall.swf', {}, params);

$(function(){
// feedback
    var fb_subject = $('.feedback input[name="subject"]').val();
    $('.feedback [name="subject"]').focus(function(){
        if ($(this).val() == fb_subject) $(this).val('');
    }).blur(function(){
        if ($(this).val() == '') $(this).val(fb_subject);
    });
    var fb_mess = $('.feedback textarea[name="mess"]').val();
    $('.feedback [name="mess"]').focus(function(){
        if ($(this).val() == fb_mess) $(this).val('');
    }).blur(function(){
        if ($(this).val() == '') $(this).val(fb_mess);
    });

// contacts
//    $('.contacts-list .map').hide();
    $('.contacts-list .expand').show();
    $('.contacts-list .expand a').click(function(){
        var i = $(this).parent().parent();
        i.find('.map').slideDown('fast', function(){
            i.find('.expand').hide();
            i.find('.collapse').show();
        });
        return false;
    });
    $('.contacts-list .collapse a').click(function(){
        var i = $(this).parent().parent();
        i.find('.map').slideUp('fast', function(){
            i.find('.expand').show();
            i.find('.collapse').hide();
        });
        return false;
    });

// lang
    $('#lang ul').hide();
    $('#lang div').hover(
        function(){
            $(this).find('ul').fadeIn('fast');
        },
        function(){
            $(this).find('ul').fadeOut('fast');
        }
    );

// search
    var search_ph = $('#footer .site-search :text').val();
    $('#footer .site-search :text').addClass('ph').focus(function(){
        if ($(this).val() == search_ph) $(this).removeClass('ph').val('');
    }).blur(function(){
        if ($(this).val() == '') $(this).addClass('ph').val(search_ph);
    });

// catalog search
    $('.search :submit, .auth :submit').hover(
        function(){
            $(this).addClass('hover');
        },
        function(){
            $(this).removeClass('hover');
        }
    );
});

function hs_submit(form) {
    if ($(form).parent().attr('id') != 'feedback') {
        $.post(
            $(form).attr(URL+'modules/contacts/ajax/public.contacts.php'),
            $(form).serialize(),
            function(data) {
                hs.close(form);
            }
        );
        return false;
    }
}

function auth(){
    $.ajax({
        type: "POST",
        url: URL+'modules/members/ajax/public.members.php',
        dataType: "text",
        data: "login="+$('#login').val()+"&password="+$('#pass').val(),
        success: function(msg){
        $("#resultLogin").show().html(msg);
            window.location.reload(true);
        },
        error: function(responseObj){
            $("#resultLogin").show().html(responseObj.responseText);
        },
        beforeSend: function(){
//            $("#resultLogin").show().html("Checking");
        },
        complete: function(responseObj){
            $("#resultLogin").show().html(responseObj.responseText);
        }
    });
    return false;
}

function reg(form){
    $.ajax({
        type: "POST",
        url: URL+'modules/members/ajax/public.members.php?a=reg',
        dataType: "text",
        data: $("form").serialize(),
        success: function(msg){
            $("#result_reg").show().html(msg);
        },
        error: function(responseObj){
            $("#result_reg").show().html(responseObj.responseText);
        },
        beforeSend: function(){
//            $("#result_reg").show().html("Checking");
        },
        complete: function(responseObj){
            $("#result_reg").show().html(responseObj.responseText);
            hs.close(form);
        }
    });
    return false;
}