/*******************************************************************************
 * sort of var_dump() for JS
 ******************************************************************************/
var log = function(){
    if (window && window.console && window.console.log) 
        for (var i = 0, len = arguments.length; i < len; i++) 
            console.log(arguments[i]);
} //Ende log
/*******************************************************************************
 * all the things that have to be done on document load
 * requires JQuery 1.3 !!!!!!
 *
 * @return void
 ******************************************************************************/
$(function(){
    var ajaxLoaderGIF = '../../assets/jquery/plugins/ad-gallery/1.2.4/images/loader.gif';
    try {
        $("a.extern").live("click", function(){
            window.open($(this).attr("href"));
            return false;
        });
    } 
    catch (e) {
        log(e);
    }
    try {
        $(".wishlist-toggler").live("click", function(){
            $(".wishlist").each(function(){
                $(this).toggle();
            });
        });
    } 
    catch (e) {
        log(e);
    }
    try {
        $("a.merken").live("click", function(){
            var $t = $(this);
            $.getJSON(this.href, function(data){
                if (data.u) {
                    $t.attr("href", data.u);
                }
                if (data.n) {
                    $t.html(data.n);
                }
                if (data.c >= 0) {
                    $(".merkzettel-counter").each(function(){
                        $(this).html("" + data.c + "");
                    });
                }
            });
            return false;
        });
    } 
    catch (e) {
        log(e);
    }
    try {
        $(".ad-gallery").adGallery({
            description_wrapper: $("#xyz"),
            effect: 'fade',
            height: 350,
            loader_image: ajaxLoaderGIF,
            slideshow: {
                enable: false
            },
            thumb_opacity: 1,
            width: 500,
            callbacks: {
                init: function(){
                    $(".ad-back").html("Zur&uuml;ck");
                    $(".ad-forward").html("Vorw&auml;rts");
                },
                afterImageVisible: function(){		
                    var _image = $("img", this.current_image);
                    var _id = parseInt(_image.attr("src").split("#")[1].split("-")[1]);
                    $.ajax({
                        data: {
                            i: _id,
                            s: _site,
                            t: "getimagedescription"
                        },
                        dataType: "json",
                        success: function(data){
                            if ($("#custom #image-information").html()) {
                                $("#custom #image-information").empty();
                            }
                            else {
                                $("#custom").append('<div id="image-information"></div>');
                            }
                            if (data.descriptionHTML.length > 0) {
                                $(".ad-descriptions").html(data.descriptionHTML);
                            }
                            if (data.customHTML.length > 0) {
                                $("#custom #image-information").html(data.customHTML);
                            }
														$(".godfather").delay(1000).slideToggle("slow");
                        },
                        url: "../../content_scripts/ajax/handle.php"
                    });
                },
                beforeImageVisible: function(){
                }
            }
        });
    } 
    catch (e) {
        log(e);
    }
});

