var rotateDelay = 4000; 	// ile czasu ma byc widoczny box

/*
var txts = [];

txts[1] = [];
txts[2] = [];
txts[3] = [];
txts[4] = [];


txts[1]['cont'] = "<img src='img/komp.jpg' /><p>1Zestaw Home, 1476 PLN z VAT</p><p>AMD ATHLON X2 4200+ | 1024MB DDR2 800 MHz | 250GB SATA | DVDRW | GA-MA69VM-S2 | LCD 19\'</p>";
txts[2]['cont'] = "<img src='img/komp.jpg' /><p>2Zestaw Home, 1476 PLN z VAT</p><p>AMD ATHLON X2 4200+ | 1024MB DDR2 800 MHz | 250GB SATA | DVDRW | GA-MA69VM-S2 | LCD 19\'</p>";
txts[3]['cont'] = "<img src='img/komp.jpg' /><p>3Zestaw Home, 1476 PLN z VAT</p><p>AMD ATHLON X2 4200+ | 1024MB DDR2 800 MHz | 250GB SATA | DVDRW | GA-MA69VM-S2 | LCD 19\'</p>";
txts[4]['cont'] = "<img src='img/komp.jpg' /><p>4Zestaw Home, 1476 PLN z VAT</p><p>AMD ATHLON X2 4200+ | 1024MB DDR2 800 MHz | 250GB SATA | DVDRW | GA-MA69VM-S2 | LCD 19\'</p>";
 

txts[1]['top'] = '0px';
txts[2]['top'] = '0px';
txts[3]['top'] = '0px';
txts[4]['top'] = '0px';
*/

var source = [];

var timeoutID = [];
var actTab, nextTab, delay;
function makeRotate()
{
	rotate($('tabId').value);
}

function rotate(tabId)
{
	if(tabId > options)
	{
		lastTab = options;
		tabId = 1;
	}
	else
	{
		var lastTab = $('lastTab').value;
	}	

	timeoutID[11] = insertContent.delay(100,[], [tabId]);
	
	if($('tab' + lastTab))
	{
		$('tab' + lastTab).set('class', 'none');
	//	$('tab' + lastTab).get('tween', {property: 'opacity', duration: 'long'}).start(1);
	}
	
	$('lastTab').set('value', tabId);
	//$('tab' + tabId).setStyle('opacity', 0);
	$('tab' + tabId).set('class', 'act');
	
	
	timeoutID[4] = $('tab' + tabId).get('tween', {property: 'opacity', duration: 'long'}).start(0);
	
	timeoutID[5] = $('textContent').tween('opacity', [0, 1]);
	
	timeoutID[1] = showTab.delay(700,[], [tabId]);
	
	tabId++;
	
	$('tabId').set('value', tabId);
	
	timeoutID[0] = rotate.delay(rotateDelay,[], [$('tabId').value]);			
	//timeoutID[0] = makeRotate.periodical(rotateDelay);
}

function insertContent(tabId)
{
	timeoutID[33] = $('promoBoxContent').setStyle('background', txts[tabId]['bg']);
	timeoutID[3] = $('textContent').set('html', txts[tabId]['cont']);
	//timeoutID[2] = $('textContent').tween('marginRight', [-130, 20]);
}

function tab(tabId, start)
{
	last = $('lastTab').value;
	
	if($('tab' + last))
	{
		$('tab' + last).set('class', 'none');
		$('tab' + last).get('tween', {property: 'opacity', duration: 'long'}).start(1);
	}
	
	
	$('lastTab').set('value', $('tabId').value)
	$('tabId').set('value', tabId);
	
	$clear(timeoutID[0]);
	$clear(timeoutID[1]);
	$clear(timeoutID[2]); 
	$clear(timeoutID[3]);
	$clear(timeoutID[4]);	
	$clear(timeoutID[5]);
	$clear(timeoutID[6]);
	$clear(timeoutID[11]);	 
	
	makeRotate();
	//timeoutID[0] = rotate.delay(700,[], [$('tabId').value]);			

	if(txts.length > 1)
	{
		//timeoutID[0] = makeRotate.periodical(rotateDelay);
	}
}

function showTab(tabId)
{
	$('tab' + tabId).get('tween', {property: 'opacity', duration: 'long'}).start(1);
}

function createField(name, value)
{
	the_field = document.createElement('input');
	the_field.setAttribute('type', 'hidden'); 
	the_field.setAttribute('name', name);
	the_field.setAttribute('id', name);
	the_field.setAttribute('value', value);
	document.getElementById("menuBox").appendChild(the_field);
}

function movePicture(type)
{

	//alert(1);
	//timeoutID[109] = $('selectedPc').get('tween', {property: 'opacity', duration: 'long'}).start(1);
	//timeoutID[110] = 
	switch(type)	
	{
		case 'alpha':
			movePicture.delay(500,[], ['left']);
			movePictureAction('selectedPc', 'opacity', 0, 100);
			break;
		case 'left':
			movePicture.delay(600,[], ['top']);
			movePictureAction('selectedPc', 'marginLeft', 0, -300);
			break;
		case 'top':
			movePicture.delay(450,[], ['width']);
			movePictureAction('selectedPc', 'marginTop', 0, -140);
			break;
			
		case 'width':
			movePicture.delay(100,[], []);
			movePictureAction('selectedPcimg', 'height', 220, 240);
			break;			
	}
	
	//timeoutID[111] = $('selectedPc').tween('marginTop', [0, -30]).delay(700,[], []);
	
}

function movePictureAction(id, css, start, end)
{
	if( $(id))
	{
		timeoutID[110 + css] = $(id).tween(css, [start, end]);
	}
}
