$(function() {
    $(".image-item.copy-link").mouseover(function(){
        var imageId = $(this).attr("id").replace("image", "");
        var imageCode = $(this).attr("code");
        var textDir = ($(this).attr("is_public") == "1") ? $(this).parent().attr("href") : "The image is private. Please make it public";
        var text = ($(this).attr("is_public") == "1") ? "http://" + window.location.host + "/media/" + imageId : "The image is private. Please make it public";
        var url = "http://" + window.location.host + "/photo/" + imageId;
        var textDelete = "http://"+window.location.host + "/image/delete/"+imageId+"/"+imageCode;
        var textForum = ($(this).attr("is_public") == "1") ? '[url='+url+'][img]' + text + '[/img][/url]' : text;
        var textHTML = ($(this).attr("is_public") == "1") ? '<a target="_blank" title="Free Image Hosting - XS.to" href="' + textDir + '"><img src="' + text + '" border="0"/></a>' : text;

        $("#copy-link-title").html($(this).attr("title"));
        $("#copy-link-val").val(textDir);
        $("#copy-link-delete-val").val(textDelete);
        $("#copy-link-direct-val").val(text);
        $("#copy-link-forum-val").val(textForum);
        $("#copy-link-html-val").val(textHTML);
        try {
            copyLink.reposition();
            copyLinkDelete.reposition();
            copyLinkDir.reposition();
            copyLinkHtml.reposition();
            copyLinkForum.reposition();
        } catch(e){

        }
    });

    ZeroClipboard.setMoviePath( '/js/zeroclipboard/ZeroClipboard10.swf' );
    try {
        /**
         * Copy link
         */
        var copyLink = new ZeroClipboard.Client();
        copyLink.addEventListener( 'mouseDown', function(client) {

            // set text to copy here
            copyLink.setText( $("#copy-link-val").val());
        } );
        copyLink.glue( 'copy-link' );
        
        /**
         * Copy delete link
         */
        var copyLinkDelete = new ZeroClipboard.Client();
        copyLinkDelete.addEventListener( 'mouseDown', function(client) {

            // set text to copy here
            copyLinkDelete.setText( $("#copy-link-delete-val").val());
        } );
        copyLinkDelete.glue( 'copy-link-delete' );

        /**
         * Copy link direct
         */
        var copyLinkDir = new ZeroClipboard.Client();
        copyLinkDir.addEventListener( 'mouseDown', function(client) {
            // set text to copy here
            copyLinkDir.setText( $("#copy-link-direct-val").val());
        } );

        copyLinkDir.glue( 'copy-link-direct' );

        /**
         * Copy link direct
         */
        var copyLinkHtml = new ZeroClipboard.Client();
        copyLinkHtml.addEventListener( 'mouseDown', function(client) {
            // set text to copy here
            copyLinkHtml.setText( $("#copy-link-html-val").val());
        } );

        copyLinkHtml.glue( 'copy-link-html' );

        /**
         * Copy link forum
         */
        var copyLinkForum = new ZeroClipboard.Client();
        copyLinkForum.addEventListener( 'mouseDown', function(client) {
            // set text to copy here
            copyLinkForum.setText( $("#copy-link-forum-val").val());
        } );

        copyLinkForum.glue( 'copy-link-forum' );

    } catch(e){

    }
});
