var MaxData = 8;
var idData = new Array(MaxData);
var ColLeftBoxes = 0;
var ColRightBoxes = 0;
var myArray = new Array();
var myArrayTitle = new Array();
var myArrayCdown = new Array();
var BoxesAll = new Array("ColLeftBoxes", "ColRightBoxes", "ColLeftBoxes2", "ColRightBoxes2", "ColMiddleBoxes", "ColMiddleBoxes2");
var BoxesAllid = new Array("l", "r", "l2", "r2", "m", "m2");
var ActId = 0;
function nav_init(){
	cmDraw ('myMenuID', myMenu, 'hbr',prop);
}

function WindowOnload(f) 
{
	var prev=window.onload;
	window.onload=function(){
		if(prev)prev(); f();
		// Random_Box("rnd1", "first", 3);
	}
}
function requestCustomerInfo(div) {
	if(ActId >=0 && ActId < MaxData){
		var temp = $(div + ActId);
		idData[ActId] = temp.innerHTML;
		ActId++;
		if(ActId < MaxData)requestCustomerInfo(div);
	}
	else{
		alert("Betöltés kész!");
	}
}

function ajaxCustomerInfo() {
	if (ajaxRequest.readyState != 4) {
		 return;
	}
	//alert(ajaxRequest.responseText);
	idData[ActId] = ajaxRequest.responseText;
	ActId++;
	if(ActId < MaxData)requestCustomerInfo();
}

// Dobozokhoz a timer
function Counter(divID, start, intervall, from, num, isbig){
	//this.divID = divID;
	this.mydiv = $(divID);
	this.navdiv = $(divID + 'nav');
	this.mybutton = $(divID + 'p');
	this.bigctrl = isbig;
	// this.noControl = noControl;
	// this.count = start;
	this.count = from;
	this.intervall = intervall;
	this.from = from;
	this.num = num;
	var oThis = this;
	oThis.doTimer();
	Event.observe(divID + 'b', 'click', function(event) { oThis.step(-1); });
	Event.observe(divID + 'p', 'click', function(event) { oThis.go(); });
	Event.observe(divID + 'f', 'click', function(event) { oThis.step(1); });

}	
Counter.prototype = {
	aktiv:	0,
	next: 	function(){
			this.doTimer();
			this.count = Math.abs(this.count+1-this.from)%this.num+this.from;
			this.setbox();
	},
	doTimer:function(){
			this.aktiv = setTimeout(this.next.bind(this), this.intervall);
	},
	setbox:	function(){
			if(idData[this.count] != undefined){
				this.mydiv.innerHTML = idData[this.count];
				if(this.bigctrl == "")this.navdiv.innerHTML  = (this.num) + '/' + (this.count-this.from+1);
			}				
	},
	step:	function(num){
			clearTimeout(this.aktiv);
			this.aktiv = 0;
			// this.mybutton.className = this.bigctrl + 'bpause_off';
			this.mybutton.className = 'bpause_off';
			var counter = (num > 0 ? num : (this.count==this.from ? this.num+num : num));
			this.count = Math.abs(this.count+counter-this.from)%this.num+this.from;
			this.setbox();
	},
	go:		function(){
			if(this.aktiv){
				clearTimeout(this.aktiv);
				this.aktiv = 0;
				// this.mybutton.className = this.bigctrl + 'bpause_off';
				this.mybutton.className = 'bpause_off';
			}
			else{
				this.doTimer();
				// this.mybutton.className = this.bigctrl + 'bpause';
				this.mybutton.className = 'bpause';
			}
	}

}
// div class-ok :  boxTitle, boxBody, navi, back, bpause, forw
function InitNewBox(num, startData, IsMidCol, banned_buttons){
var newbox = "";
if(IsMidCol == ""){
	newbox =  '<table border="0" width="194" cellpadding="0" cellspacing="0" class="box_around">' + 
		'<tr><td class="playert"></td></tr>' + 
		'<tr><td class="playerm">' + 
		'<div id="content' + num + '" class="playBody clearfix">' + startData + '</div>';

	newbox = newbox + '<table border="0" cellpadding="0" cellspacing="0" width="100%"';
	
	if(banned_buttons)
		newbox = newbox + ' style="display:none;"'; 
	
	newbox = newbox + '>' +
		    '<tr>' +
			  '<td align="right">' +
				'<div id="content' + num + 'nav">&nbsp;</div>' +
			  '</td>' +
			  '<td class="' + IsMidCol + 'back" id="content' + num + 'b" width="18" height="18">&nbsp;</td>' +
			  '<td class="' + IsMidCol + 'bpause" id="content' + num + 'p" width="18" height="18">&nbsp;</td>' +
			  '<td class="' + IsMidCol + 'forw" id="content' + num + 'f" width="18" height="18">&nbsp;</td>' +
			  '<td width="30%">&nbsp;</td>' +
			'</tr>' +
		  '</table>';
	newbox = newbox + 
		  '</td></tr>' + 
		'<tr><td class="playerb"></td></tr>' + 
	  '</table>';
}
else{
	newbox =  '<table border="0" width="356" cellpadding="0" cellspacing="0" class="box_around">' + 
		'<tr><td class="bplayert"></td></tr>' + 
		'<tr><td class="bplayerm">' + 
		'<div id="content' + num + '" class="playBody clearfix">' + startData + '</div>' +
		  '<table border="0" cellpadding="0" cellspacing="0" width="100%">' +
		    '<tr>' +
			  '<td align="right" width="75%">' +
				'<div id="content' + num + 'nav" style="display:none;">&nbsp;</div>' +
			  '</td>' +
			  '<td class="back" id="content' + num + 'b" width="18" height="18">&nbsp;</td>' +
			  '<td class="bpause" id="content' + num + 'p" width="18" height="18">&nbsp;</td>' +
			  '<td class="forw" id="content' + num + 'f" width="18" height="18">&nbsp;</td>' +
			'</tr>' +
		  '</table>' +
		  '</td></tr>' + 
		'<tr><td class="bplayerb"></td></tr>' + 
	  '</table>';
}
return newbox;
}
function InitNewBox2(num, startData){
var newbox = '' +
	'<table border="0" cellpadding="0" cellspacing="0" class="tbl_box_Head">' +
	  '<tr>' +
	    '<td>' +
			'<div id="content' + num + 'title" style="display:none;"></div>' +
		    '<div id="content' + num + '">' + startData + '</div>'  +
			// '<div>' +
			// '<div class="boxBody">' +
			// '<div id="content' + num + '">' + startData + '</div>' +
			// '<br /></div>' +
			'<div class="navi">' +
		      '<table border="0" cellpadding="0" cellspacing="0">' +
			    '<tr>' +
				  '<td align="right" width="60%">' +
					'<div id="content' + num + 'nav" style="display:none;">counter</div>' +
				  '</td>' +
				  '<td class="back" id="content' + num + 'b" width="18" height="18">&nbsp;</td>' +
				  '<td class="bpause" id="content' + num + 'p" width="18" height="18">&nbsp;</td>' +
				  '<td class="forw" id="content' + num + 'f" width="18" height="18">&nbsp;</td>' +
				  '<td style="width:10px"></td>' +
				'</tr>' +
			  '</table>' +
			'</div>' +
			// '</div>' +
		'</td>' +
	  '</tr>' +
	'</table>';
return newbox;
}

function setBox() {
	var element = 0;
	var myCounter = 0;
	var whichCol = 0;
	var IsMidCol = 0;
	// var myleftCol = $('ColLeftBoxes');
	var myAllCol = new Object();
	for(m=0; m<BoxesAll.length; m++){
		myAllCol[BoxesAllid[m]] = $(BoxesAll[m]);		
	}
	//alert(myAllCol.l);
	var myAktivBox = new Array();
	var myAktivCounter = new Array();
	var myAktivElement = new Array();
	var myBigControl = new Array();
	// var myNoControl = new Array();
	//alert(myArray.length);
	for(var i=0;i< myArray.length; i++)
	{
		mydiv = myArray[i].substring(0,4);
		// alert(myArray[i].substring(3,5));
		element = parseInt(myArray[i].substring(4));
		whichCol = myArray[i].substring(6);
		if(whichCol.substring(0, 1) == "m")IsMidCol = "b";
		else IsMidCol = "";
		// IsMidCol = "";// Ezzel jelzem, ha kell a nagyobb gom, jelenleg csak a kicsi megy
		
		// Az 'alro' id-ju forgotban letiltom a gombokat
		if(mydiv == "alro"){//alert(mydiv);
			banned_buttons = 1;
		}
		else{
			banned_buttons = 0;
		}
		if(mydiv.substring(0, 3) == "tem"){//alert(mydiv);
			type = 1;
		}
		else{
			type = 2;
		}
		//alert(element);
		newdiv = false;
		for(j=0; j<element; j++){
			if(temp = $(mydiv + j)){
				newdiv = true;
				idData[ActId] = temp.innerHTML;
				// alert(idData[ActId]);
				ActId++;
				//new Counter('content' + i, 0, 5000, myCounter, element);
			}			
		}	
		//alert(newdiv);
		if(newdiv){
			//alert(whichCol);
			// if(whichCol == "l"){
				// myleftCol.innerHTML = myleftCol.innerHTML + InitNewBox(i);
				myAllCol[whichCol].innerHTML = myAllCol[whichCol].innerHTML + 
					(type == 1 ? InitNewBox2(i, idData[myCounter], IsMidCol, banned_buttons) : InitNewBox(i, idData[myCounter], IsMidCol, banned_buttons));
				//alert(myAllCol[whichCol].innerHTML);
				if(temp = $('content' + i)){
					myAktivBox.push(i);
					myAktivCounter.push(myCounter);
					myAktivElement.push(element);
					myBigControl.push(IsMidCol);
					// myNoControl.push(banned_buttons);
				}
				else{
					alert('nem létezik!');
				}
				//
			// }
			//new Counter('content' + i, 0, 5000, myCounter, element);
		}
		myCounter += element;
	}	
	// alert(myAktivBox.length);
	// alert('boxlenght: ' + myAktivBox.length + ' - counter: ' + myAktivCounter.length + ' - element: ' + myAktivElement.length);
	var idozitesDef = 20000;
	for(i=0; i<myAktivBox.length; i++){
		if(temp = $('content' + i + 'title')){
			// alert(myArrayTitle[i]);
			temp.innerHTML = myArrayTitle[i];
		}
		if(myArrayCdown[i]){
			myIdozites = (myArrayCdown[i] > 1000 ? myArrayCdown[i] : idozitesDef);
		}
		else{
			myIdozites = idozitesDef;
		}
		new Counter('content' + myAktivBox[i], 0, myIdozites, myAktivCounter[i], myAktivElement[i], myBigControl[i]);
	}
}
Event.observe(
	window,
	'load',
	function() {
		// requestCustomerInfo('divtray');
		setBox();
		// new Counter('content1', 0, 10000, 0, 3);
		// new Counter('content2', 0, 15000, 3, 3);
		// new Counter('content3', 0, 5000, 4, 4);
	}
);

function Replace_Style(){
	num = Math.random()*10;
	num = (Math.round(num)%7)+1;
	// alert(num);
	// alert('<link href="style_' + num + '.css" rel="stylesheet" type="text/css">');
}

// mydiv - a réteg ahol megjelenik
// tray - a réteg id-jének karakteres része amiből a tratalom jön
// count a db szám amiből választok
function Random_Box(mydiv, tray, count){

	var num = 	(Math.round(Math.random()*10) % count);
	if(myDivCnt = $(mydiv)){
		if(temp = $(tray + num)){
			myDivCnt.innerHTML = temp.innerHTML;
		}
	}
}
/*
google.load("search", "1", {"nocss" : true});
// google.load("search", "1");

function OnLoad() {
  // Create a search control
  var searchControl = new google.search.SearchControl();

  // Add in a full set of searchers
  var localSearch = new google.search.LocalSearch();
  // searchControl.addSearcher(localSearch);
  searchControl.addSearcher(new google.search.WebSearch());
  // searchControl.addSearcher(new google.search.VideoSearch());
  // searchControl.addSearcher(new google.search.BlogSearch());

  // Set the Local Search center point
  localSearch.setCenterPoint("Hungary, HU");

  // Tell the searcher to draw itself and tell it where to attach
  searchControl.draw(document.getElementById("searchcontrol"));

  // Execute an inital search
  searchControl.execute("");
}
google.setOnLoadCallback(OnLoad);

// Call this function when the page has been loaded
function initialize() {
	var searchControl = new google.search.SearchControl();
	searchControl.addSearcher(new google.search.WebSearch());
	searchControl.addSearcher(new google.search.NewsSearch());
	searchControl.draw(document.getElementById("searchcontrol"));
}
// google.setOnLoadCallback(initialize);
*/
	