/**
 * @constructor
 * DebugLog
 * @param {bool} i - init
 * @param {bool} a - alert
 * @param {string} p - prefix
 */
var SW_DebugLog = function(i, a, p) {
    this.init = i;
    this.alert = a;
    if(p == false) {
        p = '';
    }
    this.prefix = p;
}

SW_DebugLog.prototype.show = function(message) {
    if(this.init != true) {
        return message;
    }
    try{
        console.info(this.prefix, arguments);
    } catch(e) {
    }
    if(this.alert == true) {
        alert(this.prefix + message);
    }
}
var DebugConsole = new SW_DebugLog(false, false, 'StickrWidget message for ie-6: ');
/**
 * class stickr widget
 * @author Alex
 * @version 0.0.1
 * http://stickr.com/
 */
TOOL_WIDGET = 8;
StickrWidget = {

    url:window.location, // current site url
    stickrDomain:'test-plugin.stickr.com', // stickr domain
    hash:null,
    waitSticker:false,

    /**
     * load stickr jscript
     * @param {string} url
     */
    loadJScript:function(url) {
        if(undefined == url || null == url || '' == url || false == url) {
            url = 'http://' + this.stickrDomain + '/load/widgetPrototype?app_hash=' + this.hash;
        }
        var A;
        A=document.createElement("script");
        A.setAttribute("language","JavaScript");
        A.setAttribute("src",url);
        try {
            document.getElementsByTagName("head")[0].appendChild(A);
        } catch(e) {
            DebugConsole.show(e.description);
            var H = document.createElement("head");
            document.appendChild(H);
            document.H.appendChild(A);
        }
    },

    /**
     * start create new sticker
     */
    createNewSticker:function() {
        DebugConsole.show('createNewSticker');
//        this.loadNewSticker();
        var img = document.createElement('img');
        img.style.display = 'none';
        img.src = "http://hits.informer.com/log.php?id=129&r="+ Math.round(100000 * Math.random());
        document.body.appendChild(img);
//        "<img style='display:none;' src=' + "' />"
//        this.loadJScript('http://hits.informer.com/log.php?id=465&r='+ Math.round(100000 * Math.random()));
    },

    /**
     * load new sticker
     */
    loadNewSticker:function() {
        DebugConsole.show('loadNewSticker');
        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
            var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
            if (ieversion <= 6) {
                alert('Your browser does not support this tool.');
                return false;
            }
        }
        try {
            Core.loadSticker();
        } catch(e) {
            DebugConsole.show(e.description);
            setTimeout(function(){StickrWidget.loadNewSticker();}, 500);
            return false;
        }
        this.waitSticker = true;
    },

    /**
     * set current site url
     * @param {string} url
     * @return bool or string
     */
    setCurrentSiteUrl:function(url) {
        if(undefined == url || null == url || '' == url || false == url) {
            return false;
        }
        this.url = url;
        return this.url;
    },

    /**
     * set stickr site domain
     * @param {string} domain
     * @return bool or string
     */
    setStickrDomain:function(domain, hash) {
        if(undefined == domain || null == domain || '' == domain || false == domain) {
            return false;
        }
        this.stickrDomain = domain;
        this.hash = hash;
        this.loadJScript();
        return this.stickrDomain;

    },

    /**
     * reload iframe
     */
    reloadIframe:function() {
        var iframe = document.getElementById('stickrWidget');
        var src = iframe.src;
        iframe.src = src;
    }
}
