$(function($)
{
    $('.ui-widget').delay(2000).fadeOut(2000);
    var lang = $('#current_language').val();
    var domain = $('#current_domain').val();
    if (domain == 'baltusaule.lv')
    {
        $('a#logo').css({backgroundImage: 'url(/static/shop/img/logo_lv.png)'});
    }
    else
    {
        $('a#logo').css({backgroundImage: 'url(/static/shop/img/logo_en.png)'});
    }
    $('h1').css({backgroundImage: 'url(/static/shop/img/slogan_'+lang+'.png)'});
    $('#products > li:nth-child(4n-3)').addClass('first');
    $('#products > li:nth-child(4n)').addClass('last');
    // subscribe to news form (sidebar)
    var subscriber = $('#subscribe #id_email').val();
    $('#subscribe #id_email').focusin(function()
    {
        if ($(this).val() == subscriber)
        {
            $(this).val('');
        }
    });
    $('#subscribe #id_email').focusout(function()
    {
        if ($(this).val() == '')
        {
            $(this).val(subscriber);
        }
    });
    $('form#subscribe').submit(function(e)
    {
        if (($('input[type=text]', this).val() == '') || ($('input[type=text]', this).val() == subscriber))
        {
            e.preventDefault();
        }
    });
    // search form (header)
    var searcher = $('#searcher').val();
    $('#searcher').focusin(function()
    {
        if ($(this).val() == searcher)
        {
            $(this).val('');
        }
    });
    $('#searcher').focusout(function()
    {
        if ($(this).val() == '')
        {
            $(this).val(searcher);
        }
    });
    $('form#search').submit(function(e)
    {
        if (($('input[type=text]', this).val() == '') || ($('input[type=text]', this).val() == searcher))
        {
            e.preventDefault();
        }
    });
    // item feedback form
    var feedback_name = $('#testimonial #id_name').val();
    var feedback_email = $('#testimonial #id_email').val();
    var feedback_body = $('#testimonial #id_body').val();
    $('#testimonial #id_name').focusin(function()
    {
        if ($(this).val() == feedback_name)
        {
            $(this).val('');
        }
    });
    $('#testimonial #id_name').focusout(function()
    {
        if ($(this).val() == '')
        {
            $(this).val(feedback_name);
        }
    });
    $('#testimonial #id_email').focusin(function()
    {
        if ($(this).val() == feedback_email)
        {
            $(this).val('');
        }
    });
    $('#testimonial #id_email').focusout(function()
    {
        if ($(this).val() == '')
        {
            $(this).val(feedback_email);
        }
    });
    $('#testimonial #id_body').focusin(function()
    {
        if ($(this).val() == feedback_body)
        {
            $(this).val('');
        }
    });
    $('#testimonial #id_body').focusout(function()
    {
        if ($(this).val() == '')
        {
            $(this).val(feedback_body);
        }
    });
    $('#testimonial').submit(function(e)
    {
        if ($('#testimonial #id_name').val() == feedback_name)
        {
            $('#testimonial #id_name').val('');
        }
        if ($('#testimonial #id_email').val() == feedback_email)
        {
            $('#testimonial #id_email').val('');
        }
        if ($('#testimonial #id_body').val() == feedback_body)
        {
            $('#testimonial #id_body').val('');
        }
    });
});
