/*
 * Giftag integration
 *
 * This should be placed in a <script/> tag somewhere after jQuery 
 */

$(function() {
    /*
     * This will need to change depending on final image location
     */
    var button_image = "http://www.giftag.com/media/images/insignia.gif";

    /*
     * Creates URL to post to Giftag and opens a centered window
     */
    addToGiftag = function() {
        /* Fix up image because it's relative and we need the full path */
        var img_src = window.location.protocol + "//" 
            + window.location.host 
            + window.location.port
            + $("#mainImage").attr("src");


        /* URL to Giftag */
        var href = 'http://www.giftag.com/bookmarklet/create/item?name=' 
                + escape(document.title) 
                + '&url=' + escape(window.location) +
                '&image_url=' + escape(img_src); 

        /* Popup window placement and dimensions */
        var h = 310;
        var w = 755;
        var win = null;
        var winl = (screen.width-w)/2;
        var wint = (screen.height-h)/2;
        var settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,toolbar=no';
        
        /* Open window */
        var win = window.open(href,"Add_to_Giftag",settings);
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
    }

    /* Insert Giftag button */
    $("#model").after('<p id="giftag" onclick="addToGiftag()" style="padding-top: 12px; cursor: pointer;">'
            + '<img src="' + button_image + '" style="margin-right: 5px;"/>'
            + '<span><b>Add to Universal Wishlist</b></span></p>');

});  


