/**
 *
 * @access private
 * @return void
 **/
var cursors_folder = './pliki_graficzne/';
if(document.images) {
	loaderek = new Image(32,32);
	loaderek.src = cursors_folder+"lightbox/loading.gif";
	prev_img = new Image(12,120);
	prev_img.src = cursors_folder+"arr_left.gif";
	prev_img_n = new Image(12,120);
	prev_img_n.src = cursors_folder+"arr_left_n.gif";
    next_img = new Image(12,120);
	next_img.src = cursors_folder+"arr_right.gif";
    next_img_n = new Image(12,120);
	next_img_n.src = cursors_folder+"arr_right_n.gif";
    p_prev_img = new Image(25,13);
	p_prev_img.src = cursors_folder+"prev-g-n-a.gif";
    p_prev_img_n = new Image(25,13);
	p_prev_img_n.src = cursors_folder+"prev-g-n.gif";
    p_next_img = new Image(25,13);
	p_next_img.src = cursors_folder+"next-g-n-a.gif";
    p_next_img_n = new Image(25,13);
	p_next_img_n.src = cursors_folder+"next-g-n.gif";
}
function updateElnavi(index) {
	all = imageArray.length;
	if (index != 1 && index != 0) {
		prev = '&nbsp;<img onmouseover="this.style.cursor=\'pointer\';" onclick="shiftImg(-1)" src="'+p_prev_img.src+'" alt="" />&nbsp;';
	} else {
		prev = '&nbsp;<img src="'+p_prev_img_n.src+'" alt="" />&nbsp;';
	}
	info = '&nbsp;zdjęcie '+index+'/'+all+'&nbsp;';
	if (index < all) {
		next = '&nbsp;<img onmouseover="this.style.cursor=\'pointer\';" onclick="shiftImg(1)" src="'+p_next_img.src+'" alt="" />&nbsp;';
	} else {
		next = '&nbsp;<img src="'+p_next_img_n.src+'" alt="" />&nbsp;';
	}
	document.getElementById('prod-elnavi').innerHTML = prev+info+next;
}
function updateMainImg(index) {
	if ( imageDir != "" && imageDir.charAt(imageDir.length - 1) != "/" ) { imageDir = imageDir + "/" }
	if (imageArray != '') {
		width = imageArray[index][1];
	    height = imageArray[index][2];
	    document.getElementById('prod-img').innerHTML = '<div><img src="'+loaderek.src+'" alt="" /></div>';
		//document.getElementById('prod-img').innerHTML = '&nbsp;<img onmouseover="this.style.cursor=\'pointer\';" onclick="myLightbox.start(\''+imageArray[index][0]+'\'); return false;" width="'+width+'" height="'+height+'" src="'+imageDir + imageArray[index][0]+'_m.jpg" id="main" alt="" />&nbsp;';
		document.getElementById('prod-img').style.backgroundImage = "url("+imageDir + imageArray[index][0]+"_m.jpg)";
		updateElnavi(index+1);
		url = imageArray[index][0];
		elem_a = '<a onclick="myLightbox.start(url); return false;" href="'+imageDir + imageArray[index][0]+'.jpg" title="Powiększenie"></a>';
		setTimeout('document.getElementById(\'prod-img\').innerHTML =\''+elem_a+'\';', 500);
	} else {
		document.getElementById('prod-img').innerHTML = '&nbsp;<img width="150" height="150" src="'+imageDir + 'brak_m.jpg" id="main" alt="" />&nbsp;';
		updateElnavi(index);
	}
}
function initViewer() {
	updateMainImg(currentImage);
	nextImage = '';
}

function shiftImg(amount) {
	if ( currentImage + amount < imageArray.length && currentImage + amount >= 0 ) {
		currentImage = currentImage + amount;
		updateMainImg(currentImage);
	}
}
////////////////////////// Promo
function updatepromoElnavi(index) {
	if (index != 0) {
		prev = '<img onclick="moveImg(-5); return false;" src="'+prev_img.src+'" alt="" style="cursor: pointer;" />';
	} else {
		prev = '<img src="'+prev_img_n.src+'" alt="" />';
	}
	if (index + numOfThumbs < promoimageArray.length) {
		next = '<img onclick="moveImg(5); return false;" src="'+next_img.src+'" alt="" style="cursor: pointer;" />';
	} else {
		next = '<img src="'+next_img_n.src+'" alt="" />';
	}
	document.getElementById('nthdiv-l').innerHTML = prev;
	document.getElementById('nthdiv-r').innerHTML = next;
}
function getImgParams(index) {
	if ( index >= promoimageArray.length) {
		imgName = navDir + "/blank.png";
		prodCena = '';
		highlight = 0;
		prodUrl = '';
		prodName = '';
	} else {
		imgName = imageDir + promoimageArray[index][0]+'_k.jpg';
		prodUrl = promoimageArray[index][2];
		prodName = promoimageArray[index][3];
		prodCena = promoimageArray[index][1];
		highlight = 1;
	}
	imgParams = imgName+' | '+prodCena+' | '+highlight+' | '+prodUrl+' | '+prodName;
	return imgParams;
}
function updateThumbnails(centerImage) {
	for ( count = 1; count <= numOfThumbs; count++ ) {
		thumbIndex = centerImage + count - center;
		imgParams = getImgParams(thumbIndex).split(" | ");
		imgName = imgParams[0];
		prodCena = imgParams[1];
		prodUrl = imgParams[3];
		prodName = imgParams[4];
		if (imgParams[2] == 1) {
			document.getElementById('lthdiv'+count).innerHTML = '<div><img src="'+loaderek.src+'" alt="" /></div>';
			document.getElementById('thdiv'+count).style.backgroundImage = "url('"+imgName+"')";
			document.getElementById('pthdiv'+count).innerHTML = '<div style="margin-top: 12px;"><h5>'+prodCena+'</h5><h4>'+prodCena+'</h4></div>';
			elem_a = '<a href="'+prodUrl+'" title="'+prodName+'"></a>';
			setTimeout('document.getElementById(\'lthdiv'+count+'\').innerHTML =\''+elem_a+'\';', 500);
		} else {
			document.getElementById('pthdiv'+count).style.backgroundImage = 'none';
			document.getElementById('thdiv'+count).style.background = '#ECECEC';
		}

	}
	updatepromoElnavi(centerImage);
}
function moveImg(amount) {
	var obj = document.getElementById('thdiv'+center);
	if(obj.currentStyle) {
		string = obj.currentStyle.backgroundImage;
	} else {
		string = getComputedStyle(obj,'').getPropertyValue('background-image');
	}
	for ( count = 0; count < promoimageArray.length; count++ ) {
		if ( string.indexOf(promoimageArray[count][0]) != -1 ) {
			firstThumb = count;
			//alert(count);
			break;
		}
	}
	if ( firstThumb + amount < 0 ) {
		amount = 0 - firstThumb
	}
	if (firstThumb + amount > promoimageArray.length - numOfThumbs ) {
		amount = promoimageArray.length - (firstThumb + numOfThumbs);
	}
	if ( firstThumb + amount >= 0 && firstThumb + amount < promoimageArray.length) {
		updateThumbnails(firstThumb + amount);
	}
}
function initPromocjeViewer() {
	updateThumbnails(currentImage);
}