var done = 0;
var timeouts = new Array();
var globalLayer = 0;
try {
	if(IE) {
		changingContainerMarginsVertical = 19;
	}
}
catch(e) {
	changingContainerMarginsVertical = 0;

}

tabsImages = new Array();
tabsImages['active'] = new Array();
tabsImages['inactive'] = new Array();

// предзагрузка картинок табсов
for (a = 1; a < 6; a++) {
	tabsImages['active']['tab'+ a] = new Image();
	tabsImages['inactive']['tab'+ a] = new Image();
}

tabsImages['active']['tab1'].src = '../img/tab1_active_en.png';
tabsImages['active']['tab2'].src = '../img/tab2_active_en.png';
tabsImages['active']['tab3'].src = '../img/tab3_active_en.png';

tabsImages['inactive']['tab1'].src = '../img/tab1_inactive_en.png';
tabsImages['inactive']['tab2'].src = '../img/tab2_inactive_en.png';
tabsImages['inactive']['tab3'].src = '../img/tab3_inactive_en.png';




function initialization() {
	tabActive = getElement('tab1');
	displayedArray = getElementsByClassName('tableChanging', document.body);
	initChangingContainer();
	window.onresize = whenWindowResized;
	graphsInitialization();
	var textInputs = document.getElementsByTagName('input');
	for (a = 0; a < textInputs.length; a++) {
		if (textInputs[a].type == "text") {
			textInputs[a].initialValue = textInputs[a].value;
			textInputs[a].onfocus = inputClear;
			textInputs[a].onblur = inputRestore;
			textInputs[a].style.display = 'none';
			textInputs[a].style.display = 'inline';
		}
	}
	done = 1;
//new
	if (arr = /#(.*)/.exec(document.location)) {
			if (arr[0]=="#addfunds") {name="changing1"; tabname="tab1";}
			if (arr[0]=="#payment") {name="changing2";  tabname="tab2";}
			if (arr[0]=="#withdrawfunds") {name="changing3";  tabname="tab3";}
			showInfo(getElement(tabname), name);
	}
//new end

	$("#tab1").click = function(e) {
	//	onClick="showInfo(this, 'changing1'); return false;"
		e.preventDefault();
		showInfo(this, 'changing1'); 
		return false;
	}
}

function whenWindowResized() {
	initChangingContainer();
	try {
		sIFR.rollback();
		hello();
	}
	catch(e) {}
}


function initChangingContainer() {
	if (!getElement('changingContainer'))
		return;
	var max_height = 0;
	var changingContainerWidth = getElement('changingContainer').offsetWidth - 18;
	for (a=0; a < displayedArray.length; a++) {
		displayedArray[a].style.width = changingContainerWidth + 'px';
		if (max_height < displayedArray[a].offsetHeight) {
			max_height = displayedArray[a].offsetHeight;
		}
	}
	if (!done) {
		try {
			displayed = displayedArray[0];
			displayed.style.position = 'absolute';
		}
		catch(e) {}
	}
	getElement('changingContainer').style.height = max_height + changingContainerMarginsVertical + 'px';
}

function graphsInitialization() {
	graphItemSelected = new Array();
	try {
		graphsImages = getElementsByClassName('graphChangingImg', document.body);
		graphItemsActive = getElementsByClassName('statsLeftItemActive', document.body);
		for (a=0; a < graphItemsActive.length; a++) {
			graphItemSelected[a] = graphItemsActive[a];
		}
	}
	catch(e) {
		return;
	}
}

function showGraph(item, graph, targetImage) {
	if (!done) {
		return;
	}
	if (targetImage == 'Graph1') {
		graphNumber = 0;
	}
	if (targetImage == 'Graph2') {
		graphNumber = 1;
	}
	if (item == graphItemSelected[graphNumber]) {
		return;
	}
	graphItemSelected[graphNumber].className = 'statsLeftItem';
	item.className = 'statsLeftItemActive';
	graphItemSelected[graphNumber] = item;
	try {
		graphsImages[graphNumber].filters[0].apply();
	}
	catch(e) {}
	graphsImages[graphNumber].src = graph.src;
	try {
		graphsImages[graphNumber].filters[0].play();
	}
	catch(e) {}
}


function showInfo(sourceTab, infoContainer) {
	if (done) {
		if (sourceTab != tabActive) {
			changingCurrent = getElement(infoContainer);
			tabActive.src =  tabsImages['inactive'][tabActive.id].src;
			sourceTab.src = tabsImages['active'][sourceTab.id].src;
			tabActive = sourceTab;
			changingCurrent.style.visibility = 'visible';
			displayed.style.visibility = 'hidden';
			displayed = changingCurrent;
			//new
			if (infoContainer=="changing1") document.location="#addfunds";
			if (infoContainer=="changing2") document.location="#payment";
			if (infoContainer=="changing3") document.location="#withdrawfunds";
			//new end

		}
	}
}

function inputClear() {
	if (this.value == this.initialValue) {
		this.value = "";
	}
}

function inputRestore() {
	if (this.value == "") {
		this.value = this.initialValue;
		this.style.display = 'none';
		this.style.display = 'inline';
	}
}


function getElement(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	}
	else if (document.all) {
		return document.all(id);
	}
}

function getElementsByClassName(strClassName, obj) {
	var ar = arguments[2] || new Array();
	var re = new RegExp("\\b" + strClassName + "\\b", "g");
	if (re.test(obj.className)) {
		ar.push(obj);
	}
	for ( var i = 0; i < obj.childNodes.length; i++ )
		getElementsByClassName(strClassName, obj.childNodes[i], ar);
	return ar;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
