/*
 *  Copyright (c) Besttoolbars, 2011
 *
 */

var appsgeyser = {
    init: function(options){
        this.containerid = options.block_id;
        this.appid = options.app_id;
        this.appname = options.app_name;
        this.width = options.width;
        this.height = options.height;
        this.theme = options.theme;
        return this;
    },
    start: function(){
        this.addEvent(window, 'load', appsgeyser.insertHTML)
        //window.onload = function() {  appsgeyser.insertHTML(); };
    },
    addEvent: function ( obj, type, fn ) {
        if ( obj.attachEvent ) {
            obj['e'+type+fn] = fn;
            obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
            obj.attachEvent( 'on'+type, obj[type+fn] );
        } else
            obj.addEventListener( type, fn, false );
    },
    removeEvent: function ( obj, type, fn ) {
        if ( obj.detachEvent ) {
            obj.detachEvent( 'on'+type, obj[type+fn] );
            obj[type+fn] = null;
        } else
            obj.removeEventListener( type, fn, false );
    },
    insertHTML: function(){
        container = document.getElementById(appsgeyser.containerid);
        container.style.width = appsgeyser.width + "px";
        container.style.height = appsgeyser.height + "px";
        container.style.color = appsgeyser.theme.color;
        container.style.backgroundColor = appsgeyser.theme.background;
		var url='http://www.appsgeyser.com/' + appsgeyser.appname + '.apk'
		url=url.replace(/\x20/g, '+');
		container.innerHTML = '<div style="text-align:center;    padding-top: 10%;"><img alt="'+ appsgeyser.appname +'" align="center" width="80%" height="80%" src="http://chart.apis.google.com/chart?cht=qr&chs='+ (appsgeyser.width - 40) +'x'+ (appsgeyser.height - 40) +'&chld=L|0&chl='+ encodeURIComponent(url) +'" /></div>';
    }
}
