$(document).ready(function() {

	/* This is basic - uses default settings */
	$('.edit_headline').editable('/req/update_newsletter.php', {
		event: 'dblclick'
	});
	$(".edit_content").editable('/req/update_newsletter.php', { 
         data: function(value, settings) {
            /* Convert <br> to newline. */
            var retval = value.replace(/<br[\s\/]?>/gi, '\n');
            return retval;
        },
         type      : "autogrow",
		 cancel    : "Cancel",
         submit    : "OK",
         onblur    : "ignore",
		 event: "dblclick",
          autogrow : {
           lineHeight : 18,
           minHeight  : 36
        }
     });
     $(".share[title]").qtip({
           position: {
              corner: {
                 tooltip: 'bottomMiddle',
                 target: 'topMiddle'
              }
           },
           style: {
                  border: {
                     width: 1,
                     radius: 2,
                     color: '#3a3a3a'
                  },
                  background: '#EEEEEE',
                  padding: 5, 
                  textAlign: 'center',
                  'font-size': 12,
                  tip: true, // Give it a speech bubble tip with automatic corner detection
               }
    });
    $(".tweet[title]").qtip({
               position: {
                  corner: {
                     tooltip: 'topLeft',
                     target: 'rightMiddle'
                  }
               },
               show: {
                      when: false, // Don't specify a show event
                      ready: true // Show the tooltip when ready
                   },
                   hide: false, // Don't specify a hide event
               style: {
                      border: {
                         radius: 2,
                         color: '#3a3a3a'
                      },
                      background: '#FFFFFF',
                      padding: 5,
                      textAlign: 'left',
                      width: 185,
                      'font-size': 12,
                      tip: true, // Give it a speech bubble tip with automatic corner detection
                   }
    });
    $('a[rel="popup"]').each(function()
   {
        $(this).qtip(
        {
              content: {
                    title: {
                            text: $(this).attr("alt"),
                            button: 'X'
                    },
                    url: '/req/get_newsletter_media.php',
                    data: {id: $(this).attr("title")},
                    method: 'get'
               },
              position: {
                 target: $(document.body), // Position it via the document body...
                 corner: 'center' // ...at the center of the viewport
              },
              show: {
                 when: 'click', // Show it on click
                 //solo: true // And hide all other tooltips
              },
              hide: { when: { event: 'unfocus' } },
              style: {
                width: {
                    max: 840
                },
                title: {
                    'background': "#141414",
                    'color': '#FFFFFF',
                    'font-weight': 'normal'
                },
                 padding: '20px',
                 border: {
                    width: 2,
                    radius: 2,
                    color: '#FFFFFF'
                 },
                 background: '#141414'
              },
              api: {
                
                 onShow: function()
                {
                    var self = this;
                    $('.gallery').each(function() {
                        $(this).click(function() {
                            self.loadContent(
                                '/req/get_newsletter_media.php',
                                {
                                    id: $(this).attr("title"),
                                    number: $(this).attr("rel")
                                },
                                'get'
                            );
                            self.updateTitle(
                                $(this).attr("alt")
                            );
                        });
                    });

                },
                onContentUpdate: function()
                {
                
                    var self = this;
                    $('.gallery').each(function() {
                        $(this).click(function() {
                            self.loadContent(
                                '/req/get_newsletter_media.php',
                                {
                                    id: $(this).attr("title"),
                                    number: $(this).attr("rel")
                                },
                                'get'
                            );
                            self.updateTitle(
                                $(this).attr("alt")
                            );
                        });
                    });
                    
                }
              }
           });
        });
     $('a[rel="contact"]').each(function()
   {
        $(this).qtip(
        {
              content: {
                    title: {
                            text: 'Contact Us',
                            button: 'X'
                    },
                    url: '/req/contact_us.php',
               },
              position: {
                 target: $(document.body), // Position it via the document body...
                 corner: 'center' // ...at the center of the viewport
              },
              show: {
                 when: 'click', // Show it on click
                 //solo: true // And hide all other tooltips
              },
              hide: { when: { event: 'unfocus' } },
              style: {
                width: {
                    max: 840
                },
                title: {
                    'background': "#141414",
                    'color': '#FFFFFF',
                    'font-weight': 'normal'
                },
                 padding: '20px',
                 border: {
                    width: 2,
                    radius: 2,
                    color: '#FFFFFF'
                 },
                 color: '#FFFFFF',
                 background: '#141414'
              }
           });
        });
    $('a[rel="media_edit"]').each(function()
   {
        $(this).qtip(
        {
              content: {
                    title: {
                            text: 'Edit Media',
                            button: 'X'
                    },
                    url: '/req/edit_newsletter_media.php',
                    data: {id: $(this).attr("title")},
                    method: 'get'
               },
              position: {
                 target: $(document.body), // Position it via the document body...
                 corner: 'center' // ...at the center of the viewport
              },
              show: {
                 when: 'click', // Show it on click
                 //solo: true // And hide all other tooltips
              },
              hide: false,
              style: {
                title: {
                    'background': "#141414",
                    'color': '#FFFFFF',
                    'font-weight': 'normal'
                },
                width: 600,
                 padding: '20px',
                 border: {
                    width: 2,
                    radius: 2,
                    color: '#FFFFFF'
                 },
                 background: '#141414',
                 color: '#FFFFFF'
              },
              api: {
                 beforeShow: function()
                 {
                    // Fade in the modal "blanket" using the defined show speed
                    $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                 },
                 beforeHide: function()
                 {
                    // Fade out the modal "blanket" using the defined hide speed
                    $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                 }
              }
           });
        });
     $('a[rel="article_delete"]').each(function()
    {
        $(this).qtip(
        {
              content: {
                    title: {
                            text: 'Are You Sure?',
                            button: 'X'
                    },
                    url: '/req/delete_article_confirm.php',
                    data: {id: $(this).attr("title")},
                    method: 'get'
               },
              position: {
                 target: $(document.body), // Position it via the document body...
                 corner: 'center' // ...at the center of the viewport
              },
              show: {
                 when: 'click', // Show it on click
                 //solo: true // And hide all other tooltips
              },
              hide: false,
              style: {
                title: {
                    'background': "#141414",
                    'color': '#FFFFFF',
                    'font-weight': 'normal'
                },
                width: 600,
                 padding: '20px',
                 border: {
                    width: 2,
                    radius: 2,
                    color: '#FFFFFF'
                 },
                 background: '#141414',
                 color: '#FFFFFF'
              },
              api: {
                 beforeShow: function()
                 {
                    // Fade in the modal "blanket" using the defined show speed
                    $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                 },
                 beforeHide: function()
                 {
                    // Fade out the modal "blanket" using the defined hide speed
                    $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                 }
              }
           });
        });
    $('a[rel="article_add"]').each(function()
    {
        $(this).qtip(
        {
              content: {
                    title: {
                            text: 'Add An Article',
                            button: 'X'
                    },
                    url: '/req/add_newsletter_article.php',
                    data: {id: $(this).attr("title")},
                    method: 'get'
               },
              position: {
                 target: $(document.body), // Position it via the document body...
                 corner: 'center' // ...at the center of the viewport
              },
              show: {
                 when: 'click', // Show it on click
                 //solo: true // And hide all other tooltips
              },
              hide: false,
              style: {
                title: {
                    'background': "#141414",
                    'color': '#FFFFFF',
                    'font-weight': 'normal'
                },
                width: 600,
                 padding: '20px',
                 border: {
                    width: 2,
                    radius: 2,
                    color: '#FFFFFF'
                 },
                 background: '#141414',
                 color: '#FFFFFF'
              },
              api: {
                 beforeShow: function()
                 {
                    // Fade in the modal "blanket" using the defined show speed
                    $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                 },
                 beforeHide: function()
                 {
                    // Fade out the modal "blanket" using the defined hide speed
                    $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                 }
              }
           });
        });
    $('a[rel="media_delete"]').each(function()
    {
        $(this).qtip(
        {
              content: {
                    title: {
                            text: 'Are You Sure?',
                            button: 'X'
                    },
                    url: '/req/delete_media_confirm.php',
                    data: {id: $(this).attr("title")},
                    method: 'get'
               },
              position: {
                 target: $(document.body), // Position it via the document body...
                 corner: 'center' // ...at the center of the viewport
              },
              show: {
                 when: 'click', // Show it on click
                 //solo: true // And hide all other tooltips
              },
              hide: false,
              style: {
                title: {
                    'background': "#141414",
                    'color': '#FFFFFF',
                    'font-weight': 'normal'
                },
                width: 600,
                 padding: '20px',
                 border: {
                    width: 2,
                    radius: 2,
                    color: '#FFFFFF'
                 },
                 background: '#141414',
                 color: '#FFFFFF'
              },
              api: {
                 beforeShow: function()
                 {
                    // Fade in the modal "blanket" using the defined show speed
                    $('#qtip-blanket').fadeIn(this.options.show.effect.length);
                 },
                 beforeHide: function()
                 {
                    // Fade out the modal "blanket" using the defined hide speed
                    $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
                 }
              }
           });
        });

       // Create the modal backdrop on document load so all modal tooltips can use it
       $('<div id="qtip-blanket">')
          .css({
             position: 'absolute',
             top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
             left: 0,
             height: $(document).height(), // Span the full document height...
             width: '100%', // ...and full width

             opacity: 0.8, // Make it slightly transparent
             backgroundColor: 'black',
             zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
          })
      .appendTo(document.body) // Append to the document body
      .hide(); // Hide it initially
        
});
