var currentSection = "page1-pane";
var tabTag = "-tab";
var paneTag = "-pane";
var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};
var scrollanim2 = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function ScrollSection(link, scrollArea, offset){
	if (currentSection == link)return;
	lastSection = currentSection;
	currentSection = link;

    sectionTab = currentSection.split("-")[0] + tabTag;
    document.getElementById(sectionTab).className = "active";
    if (lastSection) {
	    lastTab = lastSection.split("-")[0] + tabTag;
	    document.getElementById(lastTab).className = "inactive";
	}

	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));

	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	scrollStart(theScroll, theScroll.scrollLeft, position[0], 25);
}









function ScrollSectionProd(link, scrollArea, offset){
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));

	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[1] = position[1] - offsetPos[1];
	}
	scrollStartV(theScroll, theScroll.scrollTop, position[1], 25);
}







function findElementPos(elemFind){
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )
	return Array(elemX, elemY);
}

function scrollStart(elem, start, end, duration){
	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = duration;
	scrollanim.element = elem;
	scrollanim.timer = setInterval("scrollHorizAnim();", 15);
}

function scrollStartV(elem, start, end, duration){
	if (scrollanim2.timer != null) {
		clearInterval(scrollanim2.timer);
		scrollanim2.timer = null;
	}
	scrollanim2.time = 0;
	scrollanim2.begin = start;
	scrollanim2.change = end - start;
	scrollanim2.duration = duration;
	scrollanim2.element = elem;
	scrollanim2.timer = setInterval("scrollVertAnim();", 15);
}

function scrollHorizAnim(){
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}

function scrollVertAnim(){
	if (scrollanim2.time > scrollanim2.duration) {
		clearInterval(scrollanim2.timer);
		scrollanim2.timer = null;
	}
	else {
		move = sineInOut(scrollanim2.time, scrollanim2.begin, scrollanim2.change, scrollanim2.duration);
		scrollanim2.element.scrollTop = move;
		scrollanim2.time++;
	}
}


function sineInOut(t, b, c, d){return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;}

function ScrollArrow(direction, toolbar, scrollArea, offset){
	toolbarElem = document.getElementById(toolbar);
	toolbarNames = new Array();

	if (toolbarElem.hasChildNodes()){
		var children = toolbarElem.childNodes;
		for (var i = 0; i < children.length; i++) 
		{
			if (toolbarElem.childNodes[i].tagName == "A") {
				toolbarNames.push(toolbarElem.childNodes[i].id.split("-")[0]);
			}
		}
	}
	for (var i = 0; i < toolbarNames.length; i++) {
		if (toolbarNames[i] == currentSection.split("-")[0]) {
			if (direction == "left") {
				if (i - 1 < 0) {
					gotoTab = toolbarNames[toolbarNames.length - 1];
				} else {
					gotoTab = toolbarNames[i - 1];
				}
			} else {
				if ((i + 1) > (toolbarNames.length - 1)) {
					gotoTab = toolbarNames[0];
				} else {
					gotoTab = toolbarNames[i + 1];
				}
			}
		}
	}
	ScrollSection(gotoTab+paneTag, scrollArea, offset);
}


function init(){
	scrollStart(document.getElementById('scroller'), 2253, 3004, 1);
	//scrollStart(document.getElementById('scroller'), 4500, 3750, 1);
}

function load_img(){

document.getElementById('img_1_1').src="_data/txt_img/identyfikacja/inex_co_small.jpg";
document.getElementById('img_1_2').src="_data/txt_img/identyfikacja/polanka_small.jpg";
document.getElementById('img_1_3').src="_data/txt_img/identyfikacja/spray_small.jpg";
document.getElementById('img_1_4').src="_data/txt_img/identyfikacja/stencel_small.jpg";
document.getElementById('img_1_5').src="_data/txt_img/identyfikacja/teczka_ros_small.jpg";
document.getElementById('img_1_6').src="_data/txt_img/identyfikacja/teczka_wiph_small.jpg";
document.getElementById('img_1_7').src="_data/txt_img/identyfikacja/weba_small.jpg";

document.getElementById('img_2_1').src="_data/txt_img/reklamowe/aquagen_small.jpg";
document.getElementById('img_2_2').src="_data/txt_img/reklamowe/groe_small.jpg";
document.getElementById('img_2_3').src="_data/txt_img/reklamowe/koldry_small.jpg";
document.getElementById('img_2_4').src="_data/txt_img/reklamowe/meble_kasia_small.jpg";
document.getElementById('img_2_5').src="_data/txt_img/reklamowe/sempler_small.jpg";

document.getElementById('img_4_1').src="_data/txt_img/ilustracje/kot_small.jpg";
document.getElementById('img_4_2').src="_data/txt_img/ilustracje/labedz_small.jpg";
document.getElementById('img_4_3').src="_data/txt_img/ilustracje/lalka_small.jpg";
document.getElementById('img_4_4').src="_data/txt_img/ilustracje/last_fm_small.jpg";
document.getElementById('img_4_5').src="_data/txt_img/ilustracje/lew_small.jpg";
document.getElementById('img_4_6').src="_data/txt_img/ilustracje/lisek_small.jpg";
document.getElementById('img_4_7').src="_data/txt_img/ilustracje/pommidor_small.jpg";
document.getElementById('img_4_8').src="_data/txt_img/ilustracje/sentinel_small.jpg";
document.getElementById('img_4_9').src="_data/txt_img/ilustracje/sluchawki_small.jpg";
document.getElementById('img_4_10').src="_data/txt_img/ilustracje/smok_small.jpg";
document.getElementById('img_4_11').src="_data/txt_img/ilustracje/smok_blue_small.jpg";

document.getElementById('img_6_1').src="_data/txt_img/web/palatyn_web_small.jpg";
document.getElementById('img_6_2').src="_data/txt_img/web/diana_small.jpg";
document.getElementById('img_6_3').src="_data/txt_img/web/pol_trade_small.jpg";
document.getElementById('img_6_4').src="_data/txt_img/web/argedo_small.jpg";
document.getElementById('img_6_5').src="_data/txt_img/web/floorpol_small.jpg";
document.getElementById('img_6_6').src="_data/txt_img/web/geebee_small.jpg";
document.getElementById('img_6_7').src="_data/txt_img/web/adventure_small.jpg";
document.getElementById('img_6_8').src="_data/txt_img/web/budda_small.jpg";
document.getElementById('img_6_9').src="_data/txt_img/web/telemaniak_small.jpg";
document.getElementById('img_6_10').src="_data/txt_img/web/web_peper_small.jpg";

document.getElementById('img_7_1').src="_data/txt_img/soft/gddkia_small.jpg";
document.getElementById('img_7_2').src="_data/txt_img/soft/palatyn_small.jpg";


}


function preload(alpha){
	if(alpha>20){
		if(alpha==100){
			document.getElementById('preload_txt').innerHTML='';
			setTimeout("preload(99)",50);
		}else{
			if(alpha>80)alpha-=2;
			else if(alpha>60)alpha-=3
			else if(alpha>40)alpha-=4
			else alpha-=5;
			document.getElementById('preload').style.filter="Alpha(Opacity="+alpha+")";
			setTimeout("preload("+alpha+")",25);
		}
	}else{
		document.getElementById('preload').style.display='none';
		if(document.getElementById('flowers'))setTimeout("flowers(0);",2000);
	}
}

function flowers(alpha){
	if(alpha==0)document.getElementById('flowers').style.backgroundImage="url(_data/img/flowers2.gif)"; 
	alpha+=5;
	document.getElementById('flowers').style.filter="Alpha(Opacity="+alpha+")";
	//var alpha1=60-alpha;
	//document.getElementById('flowers_l').style.filter="Alpha(Opacity="+alpha1+")";
	if(alpha<=60)setTimeout("flowers("+alpha+");",200);
	//else setTimeout("flowers_l(0);",30000);
}

function flowers_l(alpha){
	if(alpha==0)document.getElementById('flowers_l').style.backgroundImage="url(_data/img/flowers_l.gif)"; 
	alpha+=5;
	document.getElementById('flowers_l').style.filter="Alpha(Opacity="+alpha+")";
	var alpha1=60-alpha;
	document.getElementById('flowers').style.filter="Alpha(Opacity="+alpha1+")";
	if(alpha<=60)setTimeout("flowers_l("+alpha+");",200);
	else setTimeout("flowers(0);",30000);
}




