
var defaultText = 'Podaj swój e-mail...';

$(document).ready(function() {
	
	//określenie domyślnego tekstu dla pola "Subskrybuj"
    $('#subscribe-field').attr("value", defaultText).css('color', '#aaa')
    .focus(function() {
        if (defaultText == $(this).attr("value")) {
            $(this).attr("value", "").css('color', '#333');
        }
    })
    .blur(function() {
        if (!$(this).attr("value")) {
            $(this).attr("value", defaultText).css('color', '#aaa');
        }
    });

    //obsługa listy FAQ
    $("div#faq-box div.faq-question h4 a").toggle(function() {
        var index_a = $("div#faq-box div.faq-question h4 a").index(this);
        $("div#faq-box div.faq-question div").eq(index_a).slideDown('fast');
    }, function() {
        var index_b = $("div#faq-box div.faq-question h4 a").index(this);
        $("div#faq-box div.faq-question div").eq(index_b).slideUp('fast');
    });
	
	//obsługa podmiany tła buttonów gry i roweru oraz przycisku 'Szukaj''
	$('#button-gra').mouseover(function() {
		var src = $(this).attr("src").match(/[^\.]+/) + "-over.gif";
		$(this).attr("src", src);
	})
	.mouseout(function() {
		var src = $(this).attr("src").replace("-over", "");
		$(this).attr("src", src);
	});

	$('#button-rower').mouseover(function() {
		var src = $(this).attr("src").match(/[^\.]+/) + "-over.gif";
		$(this).attr("src", src);
	})
	.mouseout(function() {
		var src = $(this).attr("src").replace("-over", "");
		$(this).attr("src", src);
	});

    $('#search-btn').mouseover(function() {
        var src = $(this).attr("src").match(/[^\.]+/) + "-over.gif";
        $(this).attr("src", src);
    })
    .mouseout(function() {
        var src = $(this).attr("src").replace("-over", "");
        $(this).attr("src", src);
    });

    //powiększanie zdjęcia do newsa
    $('.news-image').click(function() {
        var path = 'http://www.dobrycel.pl/photos/default/news/';
        var src = $(this).attr('src');
        var file = src.substring(27);
        var filePath = path + file;

        var background = $('<div/>');
        $(background).attr('id', 'overlay-background').animate({
          'opacity' : '.5'
        }, 1000).css({
          'width' : $(document).width(),
          'height' : $(document).height(),
        });

        $('body').append(background);

        var newImage = $('<img/>');
        var width = $('body').width();
        $(newImage).attr('src', filePath).attr('id', 'large-news-image').css({
           'left' : width/2 - 270 + 12
        });

        var closeIcon = $('<img/>');
        $(closeIcon).attr('src', 'http://www.dobrycel.pl/images/gra/icons/close.gif').attr('id', 'close-icon').css({
            'left' : width/2 + 270 - 11
        });

        $(newImage).fadeIn(1000, function() {
            $(this).bind('click', function() {
                $(this).fadeOut(1000);
                $('div#overlay-background').fadeOut(1000, function() {
                    $(this).remove();
                });
                closeIcon.hide();
            });
        });

        closeIcon.click(function() {
            newImage.fadeOut(1000);
            $('div#overlay-background').fadeOut(1000, function() {
                $(this).remove();
            });
            $(this).hide();
        });

        $('body').append(newImage).children('.news-image').hide();
        $('body').append(closeIcon);
    });
});
