/**
 * @author 3Devil
 */
var _application = ':: Discount Outdoor Kitchens DESIGN TOOL';
var __totalprice = 'Options Price';
var __instructions = '<p><b>Welcome to ' + _application + '</b></p>'
		 +'<ul>'
		 +'<li>You can hide/show navigation panels any time by pressing "H" or "h" from the keyboard'
		 +' or clicking the pin icon on the application title bar.</li>'
		 +'<li>You can hide/show hardware positions any time by pressing the button under "Island Options" panel and/or'
		 +'by pressing "P" or "p" from the keyboard.</li>'
		 +'<li>You can show this help any time by pressing "F2" from the keyboard or clicking the question mark icon'
		 +'on the application title bar.</li>'
		 +'<li>You can navigate trough active hardware zones by pressing "Alt" and the number of corresponding zone,'
		 +' i.e. "Alt + 1". "Alt + 0" is for 10th zone if there is such.</li>'
		 +'</ul>';
var __priceColor = "#800000";
var app;

Ext.example = function(){
    var msgCt;

    function createBox(t, s){
        return ['<div class="msg">',
                '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
                '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
                '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
                '</div>'].join('');
    }
    return {
        msg : function(title, format, pause){
			pause = pause || 2;
            if(!msgCt){
                msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
            }
            msgCt.alignTo(document, 't-t');
            var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
            var m = Ext.DomHelper.append(msgCt, {html:createBox(title, s)}, true);
            m.slideIn('t').pause(pause).ghost("b", {remove:true});
        },

        init : function(){
            var t = Ext.get('exttheme');
            if(!t){ // run locally?
                return;
            }
//            var theme = Cookies.get('exttheme') || 'aero';
            if(theme){
                t.dom.value = theme;
                Ext.getBody().addClass('x-'+theme);
            }
            t.on('change', function(){
                Cookies.set('exttheme', t.getValue());
                setTimeout(function(){
                    window.location.reload();
                }, 250);
            });

            var lb = Ext.get('lib-bar');
            if(lb){
                lb.show();
            }
        }
    };
}();

Ext.onReady(Ext.example.init, Ext.example);

Ext.onReady(function(){
	Ext.QuickTips.init();
	vp = new Ext.Viewport();
	vp.on('resize', function (){
		vsize = vp.getBox();
		try {
			app.center();
			app.realign();
		}
		catch (e) {}
		try {
			app.LandingPage.center();
		} catch(e) {}
	});
	
	app = new VDC.Application({
		url:'/cdt_islands.php' + (__islandLoad ? ('?setupuid=' + __islandLoad) : ''),
		purl:'/cdt_products.php'
	});
	
	app.render();
});