

(function($){
         BASEURL = $('head base').attr('href');
    var continerid = 'ii' + $.unique_id();
    var iframeid = continerid + 'self';
    var lasturl = null;
    function showIssuuIframe(url) {
        $.thickbox.show(this);
    }
    $(document).ready(function(){
        var
        w = 926, h = 500,
        s = ['display : none', 'width : ' + w + 'px', 'height : ' + h + 'px',
        'margin-left : -' + (w / 2) + 'px',
        'margin-top : ' + (-(h / 2) + ($("html").scrollTop() || $("body").scrollTop())) + 'px'];
        $("body").append(
            '<div class="TBwindow " id="' + continerid + '" style="' + s.join('; ') + '; ">' +
            '<a class="TBcloseTop TBclose" href=""></a>' +
            '<iframe FRAMEBORDER="0" scrolling="no" src="' + BASEURL + 'loading.html" style="height : ' + h + 'px; width : ' + w + 'px;" id="' + iframeid + '"></iframe>' +
            '</div>'
            );

    });

    $.show_issuu_TB = function(url) {
        var layouturl = 'http://peugeot.lv/content/issuu/basicBlueCanvas/layout.xml';
        var layouturlesc = escape(layouturl).replace(new RegExp('/', 'g'), '%2F');
        var src = url + '?mode=embed&viewMode=presentation&layout=' + layouturlesc + '&showFlipBtn=true';
        if (!lasturl || lasturl != src) {
            lasturl = src;
            $('#' + iframeid).attr('src', src);
            setTimeout(function(){
            
            }, 100);            
        }
        $.thickbox.show('#' + continerid);
    
    }



    $.fn.issuu = function() {
        return $(this).each(function(){
            $(this).click(function(e){
                e.preventDefault();
                $.show_issuu_TB($(this).attr('href'));
            });
        });
  
    };
})(jQuery)

