﻿// JScript File
		
	Ext.layout.SlideLayout = Ext.extend(Ext.layout.FitLayout, 
	{
		deferredRender : false,
		renderHidden : false,
		easing: 'easeBothStrong',
		duration: .5,
		opacity: 1,

		setActiveItem : function(itemInt)
		{
			if (typeof(itemInt) == 'string') 
			{ 
				itemInt = this.container.items.keys.indexOf(itemInt); 
			}
			else if (typeof(itemInt) == 'object') 
			{ 
				itemInt = this.container.items.items.indexOf(itemInt); 
			}

			var item = this.container.getComponent(itemInt);

			if(this.activeItem != item)
			{
				if(this.activeItem)
				{
					if(item && (!item.rendered || !this.isValidParent(item, this.container)))
					{
						this.renderItem(item, itemInt, this.container.getLayoutTarget()); 
						item.show();
					}

					//
					// Use this to shift in the X coordinate
					//
					var myX = [this.container.body.getX() - this.container.body.getWidth(), 
								 this.container.body.getX() + this.container.body.getWidth()];

					//
					// Could use this if you wanted to shift in the Y coordinate too
					//
					var myY = [this.container.body.getY() - this.container.body.getHeight(), 
								 this.container.body.getY() + this.container.body.getHeight()];

					var myDir = (this.activeItemNo < itemInt ? 'prev' : 'next');	

					if (myDir == 'next')
					{
						this.activeItem.el.shift(
						{ 
							duration: this.duration, 
							easing: this.easing, 
							opacity: 1,
							x:(this.activeItemNo < itemInt ? myX[0] : myX[1])
						});

						var myShiftX = (this.activeItemNo < itemInt ? myX[1] : myX[0] );
						item.el.setX(this.container.body.getX());
						item.el.setY(this.container.body.getY());
						item.el.shift(
						{ 
							duration: this.duration, 
							easing: this.easing, 
							opacity: 1 
						});
					}
					else
					{
						this.activeItem.el.shift(
						{ 
							duration: this.duration+1, 
							easing: this.easing, 
							opacity: 0
						});
						var myShiftX = this.container.body.getX();
						item.el.setX((this.activeItemNo < itemInt ? myX[1] : myX[0] ));
						item.el.setY(this.container.body.getY());
						item.el.shift(
						{ 
							duration: this.duration, 
							easing: this.easing, 
							opacity: 1, 
							x:myShiftX
						});
					}
				}
				this.activeItemNo = itemInt;
				this.activeItem = item;
				this.layout();
			}
		},

		renderAll : function(ct, target)
		{
			if(this.deferredRender)
			{
				this.renderItem(this.activeItem, undefined, target);
			}
			else
			{
				Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target);
			}
		}
	});
	Ext.Container.LAYOUTS['slide'] = Ext.layout.SlideLayout; 
		
	function cardStart()
	{
		var navHandler = function(direction,timer)
		{
			//debugger;
			startIndex = 1;
			endIndex = 2;
			myItem = slide.getLayout().activeItem;
			myItemString = myItem.id.split('-');	

			myIndex = parseInt(myItemString[1]) + direction;
			if (myIndex > endIndex)
				myIndex = startIndex;
			if (myIndex < startIndex)
				myIndex = endIndex;
				

//			if	(myIndex == startIndex){ Ext.getCmp('move-prev').disable();}

//			if (myIndex > startIndex){ Ext.getCmp('move-prev').enable();}

//			if (myIndex == endIndex){ Ext.getCmp('move-next').disable();}

//			if (myIndex < endIndex){ Ext.getCmp('move-next').enable();}

			nextItem = 'card-'+myIndex;
			slide.getLayout().setActiveItem(nextItem);
//			if (timer)
//				setTimeout(function() { navHandler(1,true) }, 5 * 1000);


			
		}		
		var slide = new Ext.Panel({
				layout: 'slide',
				activeItem: 1,
				height: 420,
				width: 625,
				border: false,
				layoutConfig: 
				{
					easing: 'easeBoth',
					border: false,
					duration: .8,
					opacity: .2
				},
				items: [
				{
					xtype: 'panel',
					border: false,
					id: 'card-1',
					hidden: true,
					html: '<a href="startsolution.aspx"><img src="MarketingImages/slides/OvateNewRelease.jpg" alt=""> </a>'

				},
				{
					xtype: 'panel',
					border: false,
					hidden: true,
					id: 'card-2',
					html: '<a href="docs/Unique_Selling_Proposition_For_Employment_Services_Companies.aspx"><img src="MarketingImages/slides/UniqueValuePropv2.jpg" alt=""> </a>'
				}										
				]
				
			}
		);
		slide.render('contentXX');
		slide.getLayout().setActiveItem(0);
//		setTimeout(function() { navHandler(1,true) }, 5 * 1000);
		var interval = setInterval(function() { navHandler(1); }, 5 * 1000);
		

	}

