
window.onload = loading;
var item;

var img_div;
var img_block;
var img_left, img_center, img_right, text_left, text_center, text_right;
var div_img_close;


var bnames = new Array('left', 'center', 'right');
var bitems = new Array();

var cur_block, cur_center, cur_cnt;


var flashlink, flashglass, flashimg;
function loading()
{


	num = aib_names.length;

	for(i = 0; i < num; i++)
	{
		
		snum = aib_nums[i];

		for(j = 0; j < snum; j++)
		{
			id = 'img_' + i + '_' + j;

			item = document.getElementById(id);
			item.onclick = showViewer;
		}

	}

	//createBack();
	img_div = document.getElementById('img_div');
	//showViewer();
	

	for(i = 0; i < bnames.length; i++)
	{
		id = 'border_' + bnames[i];
		item = document.getElementById(id);
		
			
		item.onmouseover = border_over;

		item.onmouseout = border_out;
		bitems[i] = item;
	}
	
	
	bitems[0].onclick = left_click;
	bitems[1].onclick = center_click;
	bitems[2].onclick = right_click;
	

	flashglass = document.getElementById('flashglass');
	flashlink = document.getElementById('flashlink');
	flashlink.style.visibility = 'visible';
	flashlink.onclick = flash_click;
	
	
	flashimg = document.getElementById('flashimg');
	flashimg.onmouseover = img_over;
	flashimg.onmouseout = img_out;
	
	if (window.projectScroll)
	{
		projectScroll();
	}
}


function img_over()
{
	isrc = this.src;
	isrc = str_replace('.jpg', '_over.jpg', isrc);
	this.src = isrc;
}

function img_out()
{
	isrc = this.src;
	isrc = str_replace('_over.jpg', '.jpg', isrc);
	this.src = isrc;
}


function link_over()
{
	this.style.color = '#036488';
	this.style.textDecoration = 'none';
}

function link_out()
{
	this.style.color = '#00aeef';
	this.style.textDecoration = 'underline';
}

function flash_click()
{

	var flashclose = document.getElementById('flashclose');
	flashclose.onclick = flashcloseclick;
	flashclose.onmouseover = link_over;
	flashclose.onmouseout = link_out;
	
	
	var so = new SWFObject("ModuleLoader.swf?xml=PanoSalado.xml", "pano", "800px", "600px", "9", "#ffffff"); 	
	so.addParam("allowFullScreen","true");
	so.addParam("allowScriptAccess","sameDomain");
	so.write("fullflashcontent");

	asizes = getDocumentSize();
	flashglass.style.width = gu(asizes[0]);
	flashglass.style.height = gu(asizes[1]);
	
	acenter = clientCenter();
	var flashblock = document.getElementById('flashblock');
	flashblock.style.display = 'inline';
	
	flashblock.style.left =  acenter[0] - parseInt(900/2);
	flashblock.style.top = acenter[1] - 300;
	
	
	flashglass.style.display = 'block';
}

function flashcloseclick()
{
	flashglass.style.display = 'none';
}

function left_click()
{
	if ((cur_center ) == 0)
	{
		cur_center = cur_cnt-1;
	}
	else
	{	
		cur_center--;
	}
	
	setImages(cur_block, cur_center, cur_cnt);
}

function center_click()
{
	if ((cur_center ) == (cur_cnt - 1))
	{
		cur_center = 0;
	}
	else
	{	
		cur_center++;
	}
	
	setImages(cur_block, cur_center, cur_cnt);
}


function right_click()
{
	if ((cur_center ) == (cur_cnt - 1))
	{
		cur_center = 0;
	}
	else
	{	
		cur_center++;
	}
	
	setImages(cur_block, cur_center, cur_cnt);
}


function setImages(iblock, icenter, icnt)
{

	src_center = aib_src[iblock][icenter];
	numpos = src_center.indexOf('_small', 0);
	if (numpos > 0)
	{
		src_center = str_replace('_small', '_base', src_center);
	}
	else
	{
		src_center = str_replace('_exsmall', '_base', src_center);
	}
	
	img_center.src = src_center;
	text_center.innerHTML = aib_names[iblock][icenter];
	
	if (icenter > 0)
	{
		index = icenter-1;
	}
	else
	{
		index = icnt-1;	
	}
	
	src_left = aib_src[iblock][index];
	src_left = str_replace('_ex', '_', src_left);
	img_left.src = src_left;

	text_left.innerHTML = aib_names[iblock][index];
	
	
	if (icenter < (icnt-1))
	{
		index = icenter + 1;
	}
	else
	{
		index = 0;
	}	
	src_right = aib_src[iblock][index];
	src_right = str_replace('_ex', '_', src_right);
	img_right.src = src_right;		

	text_right.innerHTML = aib_names[iblock][index];
}
	
function border_over()
{

	this.style.backgroundColor = '#e0f8ff';
}

function border_out()
{

	this.style.backgroundColor = '#ffffff';
}

function showViewer()
{
	wid = this.id;

	awid = wid.split('_');
	var bnum = awid[1] * 1;
	var inum = awid[2] * 1;
	var item_cnt = aib_src[bnum].length;

	var width_sum = 0;
	
	cur_block = bnum;
	cur_center = inum;
	cur_cnt = item_cnt;


	asizes = getDocumentSize();
	img_div.style.width = gu(asizes[0]);
	img_div.style.height = gu(asizes[1]);
	img_div.style.display = 'block';
	
	div_img_close = document.getElementById('div_img_close');
	div_img_close.onclick = closeClick;
	div_img_close.onmouseover = link_over;
	div_img_close.onmouseout = link_out;

	acenter = clientCenter();
	img_block = document.getElementById('img_frame');
	img_block.style.display = 'inline';
	
	img_left = document.getElementById('img_left');
	img_center = document.getElementById('img_center');
	img_right = document.getElementById('img_right');

	text_left = document.getElementById('text_left');
	text_center = document.getElementById('text_center');
	text_right = document.getElementById('text_right');
	
	width_sum = 180;
	width_sum = width_sum + 180;
	
	setImages(bnum, inum, item_cnt);

	
	
	
	width_sum = width_sum + 600;
	width_sum = width_sum + (8*6) + (20*3) + 4 + 20;

	
	img_block.style.left =  acenter[0] - parseInt(width_sum/2);
	img_block.style.top = acenter[1] - 300;
	
	return false;
}

function str_replace(search, replace, subject) 
{
	return subject.split(search).join(replace);
}

function closeClick()
{
	img_div.style.display = 'none';
}

function createBack()
{
	if(this.Glass==null)
	{
		this.Glass=document.createElement('DIV');
		this.Glass.id ='img_div';
		with(this.Glass.style)
		{
			display='none'; position='absolute'; height=0; width=0; zIndex=1;
			//if(this.isIE)
			{
				backgroundColor = '#000';
				filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=60, Style=0)";
			}
			//else backgroundImage = 'url('+this.Dir+'alfa40.png)';
		}
		document.body.appendChild(this.Glass);
	}
	
	var sizes = this.getDocumentSize();
	with(this.Glass.style)
	{
		left = 0; top = 0;
		width = gu(sizes[0]);
		height = gu(sizes[1]);
	}
	
	//this.Glass.style.display = show ? 'block' : 'none';
}


function getClientSize(){
	var w = 0;
	var h = 0;
	if(document.compatMode=='CSS1Compat'/* && !window.opera*/){
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else{
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return [w, h];
}

function getDocumentSize()
{
	var w = document.body.scrollWidth > document.body.offsetWidth ? document.body.scrollWidth : document.body.scrollWidth;
	var h = document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight;
	return [w, h];
}

function getDocumentScroll()
{
	var l = self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
	var t = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	return [l, t];
}

function clientCenter()
{
	var sizes = getClientSize();
	var scroll = getDocumentScroll();

	
	
	x = parseInt(sizes[0]/2)+scroll[0];
	y = parseInt(sizes[1]/2)+scroll[1];

	return [x, y];
}


function gu(num)
{ 
	return parseInt(num)+'px'; 
}
	

