function offerMorePhotosControl(){
    $(".show-thumbs").on("click", function(){
        if ($(this).hasClass("closed")){
            $(this).removeClass("closed").addClass("opened").children().removeClass("zmdi-chevron-down").addClass("zmdi-chevron-up");
            $("ol.thumbs").css("height","100%");
        } else if ($(this).hasClass("opened")){
            $(this).removeClass("opened").addClass("closed").children().removeClass("zmdi-chevron-up").addClass("zmdi-chevron-down");
            $("ol.thumbs").css("height","80px");
        }
    });
}

function offerMostViewedControl(){
    if ($("#offerView").length){
        var update = false,
            offersViewed = readCookie("offersViewed"),
            offer_id = getUrlParameter("o");  // offer_id oferty
        if (offersViewed){  // jest ciasteczko
            var offers = offersViewed.split(',');  // rozdziel ciacho na offer_idki
            if ($.inArray(offer_id, offers) > 0){  // oferta juz woffer_idziana
            } else {  // oferta nie woffer_idziana
                offers.push(offer_id);
                createCookie("offersViewed",offers.join(),31);
                update = true;
            }
        } else {  // nie ma ciasteczka
            createCookie("offersViewed",offer_id,31);  // stworz i wpisz offer_id
            update = true;
        }
        if (update === true){
            $.ajax({
                method: "POST",
                url: "mostViewed/update",
                dataType: "json",
                data: { oid: offer_id },
                success: function(data, textStatus, jqXHR){
                    console.log(textStatus);
                },
                error: function(jqXHR, textStatus, errorThrown){
                    console.log(jqXHR);
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        }
    }
}

$(document).ready(function(){
    offerMorePhotosControl();
    offerMostViewedControl();
    
    $("#offer-carousel").on("slide.bs.carousel", function(e){
        var $img = $(e.relatedTarget).children("img");
        $img.attr("src", $img.data("src"));
    });
});