showTweetLinks = 'all';

function drawFooter() {
    if ($(window).height() > $('body').height()) {
        $('#copy').addClass('a');
    } else {
        $('#copy').removeClass('a');
    }
}
;
$(document).ready(function() {
    drawFooter();
    $(window).resize(function() {
        drawFooter();
    });
});

function stripSlashes(str) {
    return str.replace(/\\/g, '');
}
;
$(document).ready(function() {
//    $("div.scrollable").scrollable({'keyboard':false});
    $.preloadCssImages();
    $("a#movie").fancybox({
                'hideOnContentClick': false,
                'callbackOnClose': function() {
                    $("#fancy_content").empty();
           }
    });

    $('.scrollable').slides({
            preload: true,
            play: false,
            pause: 1000,
            hoverPause: true,
            pagination: false,
            slideSpeed: 500,
            generatePagination: false
        });
    $('.slides_container div a').fancybox();

    $(".submit").click(function() {
        var from = $('#from').val();
        var comment = $('#comment').val();
        var submit = true;
        if (from.length < 1 || comment.length < 1) {
            $.fancybox('<p>Please fill in both fields. Thanks! <a onclick="$.fancybox.close();">Close</a></p>', {
                'padding':20,
                'showCloseButton':true
            });
        } else {
            $.ajax({
                url: "./actions/add_comment.php",
                data: "from=" + from + "&comment=" + comment + "&location=usketch.php",
                type: "POST",
                cache: false,
                success: function (data) {
                    //location.reload(true);
                    if (data == 'ok') {
                        $('#form').fadeOut();
                        $('#thanks').fadeIn();
                    } else {
                        $.fancybox('<p>An error occured, please try again later! <a onclick="$.fancybox.close();">Close</a></p>', {
                            'padding':20,
                            'showCloseButton':true
                        });
                    }
                }
            });
            $('#from, #comment').val('');
            $(this).attr('disabled', 'disabled');
            setTimeout(function() {
                $(this).removeAttr('disabled');
            }, 3000);
        }
        return false;
    });

    $(".nav").click(function() {
        $('.nav').removeClass('active');
        $(this).addClass('active');
        $.ajax({
            url: "./actions/get_comments.php?page=" + $(this).attr('id') + "&location=usketch.php",
            type: "GET",
            dataType: 'json',
            cache: false,
            success: function (response) {
                var html = '';
                $.each(response.data, function(i, comm) {
                    html += '<p>' + stripSlashes(comm.comment) + ' <span>from ' + stripSlashes(comm.from) + '</span></p>';
                });
                $('#comments').html(html);
            }
        });
        return false;
    });

    $("#faq1").css("background", "url('./styles/images/usketch/faq_mark.png') no-repeat center right");
    $("div#device").css("background", "url('./styles//images/usketch/faq_device01.png') no-repeat center");
    $("div#hint").css("background", "url('./styles/images/usketch/faq_hint01.png') no-repeat center");

});

function swapImages(photo){
    $("p[id^=faq]").each(function(index, el) {
        $(el).css("background", "none");
    });
    
    $("#faq"+photo).css("background", "url('./styles/images/usketch/faq_mark.png') no-repeat center right");
    $("div#device").css("background", "url('./styles//images/usketch/faq_device0"+photo+".png') no-repeat center");
    $("div#hint").css("background", "url('./styles/images/usketch/faq_hint0"+photo+".png') no-repeat center");
}
