/////////////////////////////////////////////////////////////////////////////////////
// global view

function showhide(id) {
	document.getElementById(id).style.display = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
	return false;
}

function expand_basket() {
	var e = document.getElementById('expanded_basket');
	e.style.position = 'absolute';
	var offset = $('smallbasket').cumulativeOffset();
	e.style.top = offset.top + $('smallbasket').getHeight() + 'px';
	e.style.left = offset.left + 'px';
	e.style.width = -4 + $('smallbasket').getWidth() + 'px';
	e.style.display = 'block';
}

function hide_basket() {
	document.getElementById('expanded_basket').style.display = 'none';
}

function show_selectbox(e, callback) {
	callback = callback || function(){};
	e = $(e);
	e.addClassName('open');
	var options = e.select('.options')[0];
	var offset = e.positionedOffset();
	options.style.position = 'absolute';
	options.style.top = offset.top + e.getHeight() + 'px';
	options.style.left = offset.left + 'px';
	options.style.width = -2 + e.getWidth() + 'px';
	options.style.display = 'block';
	options.style.zIndex = 9999;

	if(!e.initialized_selectbox) {
		e.initialized_selectbox = true;
		var links = e.select('.option');
		links.each(function(a) {
			a.onclick = function() {
				e.select('.value').each(function(value) { value.innerHTML = a.innerHTML; });
				links.each(function(el) { el.removeClassName('selected'); });
				a.addClassName('selected');
				hide_selectbox(e);
				callback(a.innerHTML);
				return false;
			}
		});
	}
}

function hide_selectbox(e) {
	e = $(e);
	e.removeClassName('open');
	var options = e.select('.options')[0];
	options.style.display = 'none';
}


/////////////////////////////////////////////////////////////////////////////////////
// product view

/*function select_property(id, value) {
	selected_properties[id] = value;
	for(var i = 0; i < variants.length; i++) {
		var found = true;
		for(var j = 0; j < variants[i].properties.length; j++) {
			if(variants[i].properties[j] != selected_properties[j]) {
				found = false;
				break;
			}
		}
		if(found) {
			$('product_number').innerHTML = variants[i].number;
			$('product_image').src = variants[i].image;
			$('product_image_link').href = variants[i].large_image;
			return;
		}
	}
}*/

Element.addMethods({
	setMaxHeight: function(element, height) {
		element = $(element);
		if(element.getHeight() > height) {
			element.style.height = height + 'px';
			element.style.overflow = 'scroll';
		}
		return element;
	}
});


var Tabs = Class.create({
	initialize: function(e) {
		this.navigation = $(e);
		this.tabs = [];
		this.activeTab = -1;
	},

	add: function(label, e) {
		e = $(e);
		var tab = new Element('li');
		tab.insert(new Element('a', { href: '#' + e.id }).update(label));
		tab.onclick = function(event, tab) {
			this.activate(tab);
			return false;
		}.bindAsEventListener(this, this.tabs.length);
		if(this.tabs.length == 0) {
			tab.className = 'active';
			this.activeTab = 0;
		}
		else
			e.hide();
		this.navigation.insert(tab);
		this.tabs.push({ tab: tab, e: e });
		//this.activate();
	},

	activate: function(tab) {
		if(tab == undefined)
			tab = window.location.href.replace(/.*#/, '');
		if(typeof tab == 'string') {
			for(var i = 0; i < this.tabs.length; i++) {
				if(this.tabs[i].e.id == tab) {
					tab = i;
					break;
				}
			}
		}
		if(typeof tab != 'number')
			tab = 0;

		if(tab != this.activeTab) {
			if(this.activeTab != -1) {
				this.tabs[this.activeTab].e.hide();
				//new Effect.BlindUp(this.tabs[this.activeTab].e, { duration: 0.5, queue: 'end'});
			}
			this.activeTab = tab;
			if(!this.tabs[this.activeTab].e.visible()) {
				this.tabs[this.activeTab].e.show();
				//new Effect.BlindDown(this.tabs[this.activeTab].e, { duration: 0.5, queue: 'end'});
			}
		}

		for(var i = 0; i < this.tabs.length; i++)
			this.tabs[i].tab.className = (i == this.activeTab) ? 'active' : '';
			
		document.getElementById("googlemapsreload").src = document.getElementById("googlemapsreload").src;
	}
});

