﻿Ext.namespace("Ext.ux");

/**
 * @class Ext.ux.TabPanel
 * @extends Ext.TabPanel
 *
 * Enable tabs to be positioned on the left side of a TabPanel. In order to make as few changes as possible, we reuse
 * the header element and place it on the left side
 */

/**
 * @constructor
 * @param {Object} cfg A config object
 *  @cfg {String} tabPosition 'top', 'button', 'left' or right
 *  @cfg {Number} tabWidth (only applies if verticalTabs is set to true)
 *  @cfg {String} textAlign 'left' or 'right', deafults to 'left' (only applies if verticalTabs is set to true)
 */
Ext.ux.TabPanel = function(cfg) {
  if (cfg.tabPosition == 'left' || cfg.tabPosition == 'right') {
    cfg.cls = cfg.cls || '';
    cfg.cls = 'verticalTabs ' + cfg.cls;
    if (cfg.textAlign && cfg.textAlign == 'right') {
      cfg.cls = 'alignRight ' + cfg.cls;
    }
    cfg.cls = (cfg.tabPosition == 'left' ? 'leftTabs ' : 'rightTabs ') + cfg.cls;
    this.intendedTabPosition = cfg.tabPosition;
    this.verticalTabs = true;
    cfg.tabPosition = 'top';
  }
  Ext.ux.TabPanel.superclass.constructor.call(this, cfg);
};

Ext.extend(Ext.ux.TabPanel, Ext.TabPanel, {
  tabWidth : 150,

  afterRender : function() {
    Ext.ux.TabPanel.superclass.afterRender.call(this);
    if (this.verticalTabs) {
      this.header.setWidth(this.tabWidth);
      this.header.setHeight(this.height || this.container.getHeight());
    }
  },

/**
 * Adjust header and footer size.
 * @param {Number} w width of the container
 * @return {Number} the body will be resized to this width
 */
  adjustBodyWidth : function(w) {
    if (this.verticalTabs) {
      if (Ext.isIE6) {
        //I got the value "3" through trial and error; it seems to be related with the x-panel-header border; if the border
        //is set to "none", then this substraction is not necessary - but it does not seem related to the border width, margin or padding of any
        //of the panels so I dont know how to calculate it; please let me know if you have any idea what's going on here
        this.bwrap.setWidth(w - 3);
      }
      return w;
    }
    else {
      return Ext.ux.TabPanel.superclass.adjustBodyWidth.call(this, w);
    }
  },

/**
 * Get the new body height and adjust the height of the tab strip if it is vertical.
 * @param h {Number}
 */
  adjustBodyHeight : function(h) {
    if (this.verticalTabs) {
      this.header.setHeight(h + (this.tbar ? this.tbar.getHeight() : 0));
    }
    return Ext.ux.TabPanel.superclass.adjustBodyHeight.call(this, h);
  },

/**
 * If the tab strip is vertical, we need to substract the "header" width.
 * @return {Number} The frame width
 */
  getFrameWidth : function() {
    return Ext.ux.TabPanel.superclass.getFrameWidth.call(this) + this.verticalTabs ? this.tabWidth : 0;
  },

/**
 * If the tab strip is vertical, we don't need to substract it's height
 * @return {Number} The frame height
 */
  getFrameHeight : function() {
    return Ext.ux.TabPanel.superclass.getFrameHeight.call(this) - (this.verticalTabs ? this.header.getHeight() : 0);
  }
});

Ext.onReady(function(){
  var tabtest = new Ext.ux.TabPanel({
    activeTab: 0,
	id:'tabmenu',
    tabPosition:'right',
    textAlign:'left',
	bodyBorder:false,
	border:false,
    tabWidth:280,
	animScroll:true,
    tabStripWidth:200,
	deferredRender:false,
	height: 200,
    defaults:{autoScroll: true},
	listeners:{render: function(tabPanel){
                                      tabPanel.getEl().on('click',function(e){clearInterval(autoRefreshProcId)},tabPanel);
	}
	},
    items:[{
	  id:0,
      title: '<img src="./images/burn3.png" align="left" style="margin-right:8px;" /><span class="menu-title">Тиражиране</span><span class="menu-text">Разнообразни носители, опаковки,<br>холдери... </span>',
      html: '<img src="./images/replicating.jpg" /><div class="slideshow-content"><h1>Тиражиране</h1>Всичко за Вашия проект: от носителя – със стандартна или нестандартна форма, печат върху носителя и запис, до окомплектоване в разнообразни опаковки – картонени, CD/DVD кутийки с обложки, M-PACK, мултимедийни картички, холдери.</div>'
    },{
      id:1,
      title: '<img src="./images/design.png" align="left" style="margin-right:8px;margin-top:4px;" /><span class="menu-title">Дизайн</span><span class="menu-text">С наша помощ добрите идеи могат да<br>станат красиви продукти</span>',
      html: '<img src="./images/design.jpg" /><div class="slideshow-content"><h1>Дизайн</h1>Имате виждане, но не знаете как да го постигнете? Ние ще „облечем” идеите Ви в подходящ дизайн.<br><br>Доверете ни се, ние можем да направим това за Вас!</div>'
    },{
      id:2,
      title: '<img src="./images/contacts.png" align="left" style="margin-right:8px;margin-top:4px;" /><span class="menu-title">Контакти</span><span class="menu-text">Има много начини да стигнете до нас.<br>Изберете най-удобния за Вас!</span>',
      html: '<img src="./images/contacts.jpg" /><div class="slideshow-content" style="height:150px;"><h1>Контакти</h1><table border="0" cellspacing="0" cellpadding="0" width="370"><tr><td><div class="contact-title">фирма:</div></td><td><div align="left"> М-ДИЗАЙН ЕООД</div></td></tr><tbody><tr><td width="90" valign="top"><div class="contact-title">адрес:</div></td><td>София, Младост 4, бул. Д-р Атанас Москов,<br /> бл. 458, партер (до вх. 6)<br /><a onclick="window.open(\'http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&ll=42.635056,23.374743&spn=0.00577,0.013947&t=h&z=17&msid=117389736343553764996.000461257673cc02d7e76\', \'GoogleMaps\');" href="#">[&nbsp;карта ]</a><br><br></td></tr><tr><td width="90" valign="top"><div class="contact-title">GSM:</div></td><td><div align="left"> 089 6704 088, 088 8735 630</div></td></tr><tr><td width="90"><div class="contact-title">тел./факс:</div></td><td width="370"><div align="left">02/ 4912 430</div></td></tr><tr><td width="90" valign="top"><div class="contact-title">e-mail:</div></td><td width="370"><div align="left"> <a href="mailto:office@cdprint.bg">office@cdprint.bg</a><br /></div></td></tr></tbody></table></div>'
    }
        ]
  });
var menu_id = Ext.get('menu');
tabtest.render(menu_id);



function animTabs(){
Ext.getCmp('tabmenu').setActiveTab(currentTab);
currentTab++;
if(currentTab == 3){
	currentTab = 0;
}
}
var currentTab = 0;
var autoRefreshProcId = setInterval(animTabs, 5000);
});
