// JavaScript Document
var max_per_col = 3;

var max_per_page = 6;

var active = "services";
var tabs_array = new Array("services","seafreight","airfreight","carshipment","artshipment","removals","valuablecargo");


function replaceHtml(el, html) {
	var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
	/*@cc_on // Puro innerHTML para IE (que es más rápido)
	oldEl.innerHTML = html;
	return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	return newEl;
};
function fill_photos (from) {
	if (from > 0) {
		var prev_page_index = from - max_per_page;
		if (prev_page_index < 0) { prev_page_index = 0;}
		
		replaceHtml("prevImgs",'<a href="#" onclick="fill_photos('+ prev_page_index +');">  <img src="images/previous_icon.jpg" border="0"/> </a>');
	} else {
		replaceHtml("prevImgs",'');
	}
	if (from + max_per_page  < pictures_array.length ) {
		var next_page_index = from + max_per_page;
		replaceHtml("nextImgs",'<a href="#" onclick="fill_photos('+ next_page_index +');">  <img src="images/next_icon.jpg" border="0" /> </a>');
	} else {
		replaceHtml("nextImgs",'');
	}

	var newHTML = "";
	var row_counter = 1;
	
	

	newHTML = '<table width="310" border="0">';
	for (i=from;i<pictures_array.length;i++) {
		if (i >= from + max_per_page) {
			break;
		}
		if ((row_counter == 0)) {
			newHTML = newHTML + '<tr>';
		}
		newHTML = newHTML + '<td><a href="images/automobil/' + pictures_array[i] + '" rel="lytebox" title="'+ info_array[i] +'"><img src="images/automobil/thumbnails/' + pictures_array[i] + '" width="122" height="90" hspace="0" vspace="0" border="0"/></a></td>';
	
		if ((row_counter == max_per_col) ) {
			newHTML = newHTML + '</tr>';
			row_counter = 0;
		}
		row_counter = row_counter + 1;
		
	}
	if ((row_counter < max_per_col) && (i > 0) ) {
		newHTML = newHTML + '</tr>';
	}
	newHTML = newHTML + ' </table>';
	replaceHtml("photodiv",newHTML);
	
	initLytebox();
}

function activateTab(tabName) {
	active = tabName;
	for (j=0;j<tabs_array.length;j++) {
		if (tabs_array[j] == tabName) {
			document.getElementById(tabName).setAttribute("className", tabName +"_on");
			document.getElementById(tabName).setAttribute("class", tabName +"_on");
		} else {
			document.getElementById(tabs_array[j]).setAttribute("className",  tabs_array[j] +"_off");
			document.getElementById(tabs_array[j]).setAttribute("class", tabs_array[j] +"_off");
		}
	} 
	return false;
}
function overtTab(tabName) {
	if (active != tabName) {
		document.getElementById(tabName).setAttribute("className", tabName +"_on");
		document.getElementById(tabName).setAttribute("class", tabName +"_on");
	}
	return false;
}
function outTab(tabName) {
	if (active != tabName) {
		document.getElementById(tabName).setAttribute("className", tabName +"_off");
		document.getElementById(tabName).setAttribute("class", tabName +"_off");
	}
	return false;
}

function writeAddress(user, site) {
	document.write('<a href=\"mailto:' + user + '@' + site + '\">');
	document.write(user + '@' + site + '</a>');
}
