if (window.console == null)
	window.console = {};
if (window.console.log == null)
	window.console.log = {};
if (window.console.info == null)
	window.console.info = {};
if (window.console.group == null)
	window.console.group = {};
if (window.console.groupEnd == null)
	window.console.groupEnd = {};

var recordSeparator = "@@##@@";
var fieldSeparator = "__%%__";
var window_targets = {};

function ui()
{
}

ui.initialize = function ()
{	
	if (window.is_ie)
		ui.initializeIE();

	DirectSearch.setup();
	Togglers.setup();
	Navigation.setup();
	Carrousel.setup();
	ComboSearch.setup();
	Buttons.setup();

	ui.initializeWindowOpeners();
	ui.initializePopupOpeners();
	ui.initializeSubmitButtons();
	ui.initializePrintButtons();
	ui.initializeClickables();
}

ui.initializeIE = function ()
{
	try
	{
		// Enable background-image cache for IE6 to prevent flicker on hover
		document.execCommand("BackgroundImageCache", false, true);
	}
	catch(err) { }
}

ui.initializeWindowOpeners = function ()
{
	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
	{
		var target = links[i].getAttribute("target");
		if (target && target != "" && window_targets[target] != null)
			$(links[i]).bind("click", ui.windowopener_onclick);
	}
}

ui.initializePopupOpeners = function ()
{
	$(".popup-open").bind("click", ui.popupopener_onclick);
	$(".popup-close").bind("click", ui.popupclose_onclick);
}

ui.initializeSubmitButtons = function ()
{
	$("a.submit-form, button.submit-form").bind("click", ui.submit_onclick);
}

ui.initializePrintButtons = function ()
{
	$("a.print").bind("click", function ()
	{
		if (typeof onPagePrint === "function")
			onPagePrint();

		window.print();
	});
}

ui.initializeClickables = function ()
{
	$(".clickable").bind("mouseover", function ()
	{
		$(this).addClass("clickable_hover");
	});
	$(".clickable").bind("mouseout", function ()
	{
		$(this).removeClass("clickable_hover");
	});

	$(".clickable").bind("click", function ()
	{
		if (this.className.match(/url=(\S+)/))
		{
			document.location = RegExp.$1;
			return false;
		}
		return true;
	});
}


ui.expandHref = function (href, addStatic)
{
	var baseHref = "";
	var base = document.getElementsByTagName("base");
	for (var i = 0; i < base.length; i++)
	{
		if (base[i].getAttribute("href"))
		{
			baseHref = base[i].getAttribute("href");
			break;
		}
	}

	if (addStatic == true)
	{
		var script = document.getElementById("jsglobal");
		var prefix = script.getAttribute("src").replace(/^(.*)basis.*$/, "$1");
		baseHref += prefix;
	}

	if (href.indexOf(baseHref) != 0)
		return baseHref + href;
	else
		return href;
}

ui.submit_onclick = function ()
{
	if (this.className.match(/form-([\S]+)/))
	{
		var form = $("form#" + RegExp.$1)[0];
		if (form != null)
			form.submit();
	}
	return false;
}


ui.openInNewWindow = function (url, target, width, height, attributes)
{
	var openUrl = url;
	var openTarget = target || "_blank";
	var openWidth = parseInt(width);
	var openHeight = parseInt(height);
	var openAttribs = attributes;

	if (window_targets[target] != null)
	{
		var def = window_targets[target];
		if (!openWidth)
			openWidth = parseInt(def.width) || parseInt(def.w) || 600;
		if (!openHeight)
			openHeight = parseInt(def.height) || parseInt(def.h) || 400;
		if (!openAttribs)
			openAttribs = def.attributes || def.attr || "status=yes,scrollbars=yes,resizable=yes";
	}

	if (navigator.userAgent.toLowerCase().indexOf("safari") != -1)
	{
		openWidth -= 2;
		openHeight += 15;
	}

 	var x= (screen.availWidth - openWidth) / 2;
 	var y= (screen.availHeight - openHeight) / 2;

	var propsArray = (openAttribs || "").split(",");
	var propsObject = new Object;
	for (var i = 0; i < propsArray.length; i++)
	{
		var pair = propsArray[i].split("=");
		propsObject[pair[0]] = pair[1];
	}
	propsObject.width = openWidth;
	propsObject.height = openHeight;

	propsArray = new Array;
	for (var prop in propsObject)
		propsArray.push(prop + "=" + propsObject[prop]);

	if (window.open_windows == null)
		window.open_windows = {};

 	window.open_windows[openTarget] = window.open(openUrl, openTarget, propsArray.join(","));
	if (window.open_windows[openTarget] != null)
		window.open_windows[openTarget].focus();
}


ui.windowopener_onclick = function ()
{
	ui.openInNewWindow(this.href, this.target);
	return false;
}

ui.popupopener_onclick = function ()
{
	if (this.className.match(/target-(\S+)/))
	{
		var popupElem = document.getElementById("popup_" + RegExp.$1);
		ui.showDialog(popupElem);
		if (window.is_ie6)
			ui.hideSelects();
	}
}

ui.popupclose_onclick = function ()
{
	if (this.className.match(/target-(\S+)/))
	{
		var popupElem = document.getElementById("popup_" + RegExp.$1);
		popupElem.style.visibility = "hidden";
		popupElem.style.display = "none";
		if (window.is_ie6)
			ui.showSelects();
	}
}

ui.showDialog = function (elem, top, left)
{
	if (elem == null)
		return;

	elem.style.visibility = "hidden";
	elem.style.display = "block";

	var html = document.getElementsByTagName("HTML")[0];
	var body = document.body;

	var width = elem.offsetWidth;
	var height = elem.offsetHeight;

	var scrollTop = html.scrollTop;
	var scrollLeft = html.scrollLeft;

	if (top == null)
		top = html.offsetHeight / 2 - height / 2;

	if (left == null)
		left = html.offsetWidth / 2 - width / 2;

	var bodyHeight = scrollTop + html.offsetHeight;
	var bodyWidth = scrollLeft + html.offsetWidth;
	var dialogBottom = top + height;
	var dialogRight = left + width;

	if (dialogBottom > bodyHeight)
		top = bodyHeight - height - 10;
	if (dialogRight > bodyWidth)
		left = bodyWidth - width - 10;

	elem.style.top = (top + scrollTop) + "px";
	elem.style.left = left + "px";

	elem.style.visibility = "visible";
}

ui.showSelects = function ()
{
	$("select").css("visibility", "visible");
}

ui.hideSelects = function ()
{
	$("select").css("visibility", "hidden");
}

function Carrousel()
{
}
Carrousel.ItemIndex = 0;
Carrousel.Cycling = false;
Carrousel.TimeoutInterval = 5000;

Carrousel.setup = function ()
{
	var elems = $(".portlet .browse-controls");
	for (var i = 0; i < elems.length; i++)
	{
		var banners = $(".banner", elems[i].parentNode);

		elems[i].index = i;
		elems[i].itemIndex = 0;
		elems[i].itemCount = banners.length;

		var back = $("a.back", elems[i]);
		var next = $("a.next", elems[i]);

		if (back && next)
		{
			back[0].carIndex = i;
			next[0].carIndex = i;

			$(back).bind("click", Carrousel.onprev);
			$(next).bind("click", Carrousel.onnext);

			Carrousel.startCycle();
		}
	}

	var elems = $(".carrousel .banner");
	for (var i = 0; i < elems.length; i++)
	{
		if (elems[i].className.match(/\bhide\b/))
		{
			$(elems[i]).removeClass("hide");
			$(elems[i]).hide();
		}
	}
}

Carrousel.startCycle = function ()
{
	if (Carrousel.Cycling)
		Carrousel.showNext();

	Carrousel.timeoutID =
		window.setTimeout(Carrousel.startCycle, Carrousel.TimeoutInterval);

	Carrousel.Cycling = true;
}

Carrousel.stopCycle = function()
{
	Carrousel.Cycling = false;
	if (Carrousel.timeoutID != null)
		window.clearTimeout(Carrousel.timeoutID);
}

Carrousel.onnext = function ()
{
	Carrousel.stopCycle();
	Carrousel.showNext();
}

Carrousel.onprev = function ()
{
	Carrousel.stopCycle();
	Carrousel.showPrev();
}

Carrousel.showNext = function (e)
{
	var elems = $(".carrousel .banner");
	var index = Carrousel.ItemIndex;
	var item = elems[index];
	if (item)
	{
		var next = index < (elems.length - 1) ? index + 1 : 0;
		Carrousel.showItem(next);
	}
}

Carrousel.showPrev = function ()
{
	var elems = $(".carrousel .banner");
	var index = Carrousel.ItemIndex;
	var item = elems[index];
	if (item)
	{
		var prev = index > 0 ? index - 1 : elems.length - 1;
		Carrousel.showItem(prev);
	}
}

Carrousel.showItem = function (index)
{
	var elems = $(".carrousel .banner");
	var counter = $(".browse-controls .index")[0];
	var item = elems[index];

	if (counter != null)
		counter.innerHTML = (index + 1);

	var curr = elems[Carrousel.ItemIndex];
	var next = elems[index];

	if (window.is_ie_lt7)
	{
		$(curr).hide();
		$(next).show();
	}
	else
	{
		$(curr).fadeOut(1000);
		$(next).fadeIn(1000);
	}

	Carrousel.ItemIndex = index;
}

function ComboSearch()
{
}
ComboSearch.setup = function ()
{
	$("form.combosearch").bind("submit", ComboSearch.form_submit);
	$("a#combosearch_submit").bind("click", ComboSearch.form_submit);
}
ComboSearch.form_submit = function ()
{
	var form = $("form.combosearch")[0];
	if (form)
	{
		if (form.elements && form.elements.product)
		{
			var value = form.elements.product.value;
			if (ComboSearch.isValidProductNumber(value))
			{
				form.action = form.getAttribute("action2");
			}
		}

		form.submit();
	}
	return false;
}
ComboSearch.isValidProductNumber = function (value)
{
	if (value)
	{
		var test = String(value).replace(/(.*)\s*$/, "$1");
		test = test.substr(test.length - 2, 2);
		return !isNaN(test);
	}
	return false;
}



function DirectSearch()
{
}
DirectSearch.Index = -1;
DirectSearch.Terms = new Array;
DirectSearch.TimeoutID = null;
DirectSearch.TimeoutInterval = 5000;
DirectSearch.IsSetup = false;

DirectSearch.setup = function ()
{
	if (DirectSearch.IsSetup)
		return;

	var searchForm = document.getElementById("direct_book");
	var searchBox = document.getElementById("search_direct");
	var searchTerms = document.getElementById("search_terms");
	var searchSubmit = document.getElementById("search_submit");
	var searchSubmit2 = document.getElementById("directBookButton");

	if (searchBox && searchTerms)
	{
		DirectSearch.Terms = searchTerms.value.split('@@##@@');
		DirectSearch.Index = 0;

		DirectSearch.cycleSearchTerm();

		searchBox.onfocus = DirectSearch.input_onfocus;
		searchBox.onblur = DirectSearch.input_onblur;
		searchBox.onkeydown = DirectSearch.input_onfocus;
	}
	if (searchForm != null)
		$(searchForm).bind("submit", DirectSearch.form_onsubmit);

	if (searchSubmit != null)
		$(searchSubmit).bind("click", DirectSearch.submit_onclick);

	if (searchSubmit2 != null)
		$(searchSubmit2).bind("click", DirectSearch.submit_onclick);

	DirectSearch.IsSetup = true;
}

DirectSearch.stopCycle = function ()
{
	if (DirectSearch.TimeoutID != null)
		window.clearTimeout(DirectSearch.TimeoutID);
}

DirectSearch.currentValue = function ()
{
	return DirectSearch.Terms[DirectSearch.Index];
}

DirectSearch.incrementIndex = function ()
{
	if (DirectSearch.Index == DirectSearch.Terms.length - 1)
		DirectSearch.Index = 0;
	else
		DirectSearch.Index += 1;

	return DirectSearch.Index;
}

DirectSearch.nextValue = function ()
{
	DirectSearch.incrementIndex();
	return DirectSearch.Terms[DirectSearch.Index];
}

DirectSearch.cycleSearchTerm = function ()
{
	var searchBox = document.getElementById("search_direct");
	if (searchBox)
	{
		searchBox.value = DirectSearch.nextValue();

		DirectSearch.TimeoutID = window.setTimeout(
			DirectSearch.cycleSearchTerm,
			DirectSearch.TimeoutInterval);
	}
}

DirectSearch.input_onfocus = function ()
{
	if (this.value == DirectSearch.currentValue())
		this.value = "";

	$(this).addClass("focus");
	DirectSearch.stopCycle();
}

DirectSearch.input_onblur = function ()
{
	if (this.value == "")
	{
		DirectSearch.cycleSearchTerm();
		$(this).removeClass("focus");
	}
}

DirectSearch.form_onsubmit = function ()
{
 	var searchBox = document.getElementById("search_direct");
	var searchValue = searchBox.value.trim().replace(/-/, "");
	if (searchValue.length == 0 || searchValue == DirectSearch.currentValue())
		return false;

//	if (!searchValue.match(/^[a-z]{4}\d{4}$/i))
//	{
		this.action = this.getAttribute("action2");
		searchBox.name = "param1";
//	}
//	else
//		searchBox.value = searchValue;

	return true;
}

DirectSearch.submit_onclick = function ()
{
	var searchForm = document.getElementById("direct_book");
	if (searchForm)
	{
		if (DirectSearch.form_onsubmit.apply(searchForm))
			searchForm.submit();
	}

	return false;
}

function Togglers()
{
}

Togglers.setup = function ()
{
	var togglers = $(".toggler");
	if (togglers.length != 0)
	{
		for (var i = 0; i < togglers.length; i++)
		{
			$(togglers[i]).bind("click", Togglers.toggle_onclick);
		}
	}
}

Togglers.toggle_onclick = function ()
{
	var speed = window.is_ie_lt7 ? 0 : 100;

	if (this.id.match(/toggle_(once_)?(.*)/))
	{
        var toggleOnce = RegExp.$1 == "once_";
		var targetID = RegExp.$2;

		var targetElem = document.getElementById(targetID);
		var parentElem = this.parentNode;
		if (targetElem != null)
		{
			if (targetElem.offsetHeight)
			{
				//$(targetElem).hide(speed);
				$(targetElem).hide();
				$(parentElem).removeClass("open");
			}
			else
			{
				//$(targetElem).show(speed);
				$(targetElem).show();
				$(parentElem).addClass("open");
			}
			
			if (toggleOnce)
			    $(this).hide();
		}
	}
}

function Navigation()
{
}
Navigation.showOnClick = false;
Navigation.showOnMouseOver = true;
Navigation.currentMenu = null;
Navigation.previousMenu = null;
Navigation.anchorElement = "visual";
Navigation.preferSide = "left";
Navigation.autoHideTimeout = 50;
Navigation.autoHideTimeoutID = null;
Navigation.settingsID = "navigation_settings";
Navigation.offsetX = 0;
Navigation.offsetY = 0;
Navigation.minLinkWidth = 0;

Navigation.setup = function ()
{
	Navigation.parseSettings();

	var elems = $("ul.navigation > li");

	for (var i = 0; i < elems.length; i++)
	{
		var subnav = $(".subnavigation", elems[i])[0];
		if (subnav)
		{
			elems[i].removeChild(subnav);
			elems[i].isSubNav = true;

			document.body.insertBefore(subnav, document.body.childNodes[0]);

			Navigation.initSubnavigation(subnav);

			$(elems[i]).bind("click", Navigation.menuitem_click);
			$(elems[i]).bind("mouseover", Navigation.menuitem_mouseover);
			$(elems[i]).bind("mouseout", Navigation.menuitem_mouseout);

			$(subnav).bind("mouseover", Navigation.menu_mouseover);
			$(subnav).bind("mouseout", Navigation.menu_mouseout);

			$(document).bind("mousedown", Navigation.document_mousedown);

			elems[i].setAttribute("hidefocus", "true");
		}
		else
			$(elems[i]).bind("mouseover", Navigation.menuitem2_mouseover);

	}
}

Navigation.parseSettings = function ()
{
	var settingsElem = $("#" + Navigation.settingsID)[0];
	if (settingsElem)
	{
		if (settingsElem.className.match(/showonclick_(0|1)/i))
			Navigation.showOnClick = RegExp.$1 == "1" ? true : false;

		if (settingsElem.className.match(/showonmouseover_(0|1)/i))
			Navigation.showOnMouseOver = RegExp.$1 == "1" ? true : false;

		if (settingsElem.className.match(/prefer_(left|right)/i))
			Navigation.preferSide = RegExp.$1 == "right" ? "right" : "left";

		if (settingsElem.className.match(/offsetx_(-?\d+)/i))
			Navigation.offsetX = parseInt(RegExp.$1);

		if (settingsElem.className.match(/offsety_(-?\d+)/i))
			Navigation.offsetY = parseInt(RegExp.$1);

		if (settingsElem.className.match(/minwidth_(\d+)/i))
			Navigation.minLinkWidth = parseInt(RegExp.$1);

		if (settingsElem.className.match(/alignto_(\w+)/i))
		{
			var elemID = RegExp.$1;
			if (document.getElementById(elemID) != null)
				Navigation.anchorElement = elemID;
		}
	}
}

Navigation.document_mousedown = function (e)
{
	if (Navigation.currentMenu != null)
	{
		var srcElement = evt.srcElement(e);
		var isSubNav = false;
		var testElem = srcElement;
		while (testElem && !isSubNav)
		{
			isSubNav = testElem.isSubNav;
			testElem = testElem.parentNode;
		}
		if (isSubNav)
			return;

		if (!dom.elementContains(Navigation.currentMenu, srcElement))
			Navigation.hideSubnavigation(Navigation.currentMenu);
	}
}

Navigation.menuitem_click = function ()
{
	var subnav = document.getElementById(this.id + "_sub");
	if (Navigation.showOnClick)
	{
		Navigation.toggleSubnavigation(subnav, this);
		return false;
	}
}

Navigation.menuitem_mouseover = function ()
{
	Navigation.cancelAutoHide();

	var subnav = document.getElementById(this.id + "_sub");
	if (subnav != null)
	{
		var show_onm = Navigation.showOnMouseOver;
		var show_onc = Navigation.showOnClick;
		var menu = Navigation.currentMenu;

		if (show_onm || (show_onc && menu != null))
			Navigation.showSubnavigation(subnav, this);
	}
}

Navigation.menuitem2_mouseover = function ()
{
	if (Navigation.showOnClick)
	{
		Navigation.hideSubnavigation(Navigation.currentMenu);
		return false;
	}
}

Navigation.menuitem_mouseout = function ()
{
	var subnav = document.getElementById(this.id + "_sub");
	if (subnav != null)
	{
		var show_onm = Navigation.showOnMouseOver;
		if (show_onm)
		{
			Navigation.setupAutoHide(subnav);
		}
	}
}

Navigation.menu_mouseover = function ()
{
	Navigation.cancelAutoHide();
}

Navigation.menu_mouseout = function ()
{
	Navigation.setupAutoHide(this);
}

Navigation.setupAutoHide = function (submenu)
{
	Navigation.previousMenu = submenu;
	Navigation.autoHideTimeoutID =
		window.setTimeout(Navigation.autoHideSubnavigation, Navigation.autoHideTimeout);
}

Navigation.autoHideSubnavigation = function ()
{
	Navigation.hideSubnavigation(Navigation.previousMenu);
}

Navigation.cancelAutoHide = function ()
{
	if (Navigation.autoHideTimeoutID != null)
		window.clearTimeout(Navigation.autoHideTimeoutID);
}

Navigation.toggleSubnavigation = function (subnav, menuitem)
{
	try
	{
		if (subnav)
		{
			if (subnav.offsetHeight)
				Navigation.hideSubnavigation(subnav, menuitem);
			else
				Navigation.showSubnavigation(subnav, menuitem);
		}
	}
	catch(e) { console.log(e.message) }

	return false;
}

Navigation.showSubnavigation = function (subnav, menuitem)
{
	if (menuitem == null || menuitem.nodeName == null)
		return;

	if (subnav == null || subnav.nodeName == null)
		return;

	if (Navigation.currentMenu != null)
		Navigation.hideSubnavigation(Navigation.currentMenu);

	subnav.style.visibility = "hidden";
	subnav.style.display = "block";

	var pos = Navigation.getTargetPos(subnav, menuitem);

	subnav.style.top = pos.top + "px";
	subnav.style.left = pos.left + "px";
	subnav.style.visibility = "visible";
	//$(menuitem).addClass("open");

	Navigation.currentMenu = subnav;

	return false;
}

Navigation.hideSubnavigation = function (subnav)
{
	if (subnav == null || subnav.nodeName == null)
		return;

	subnav.style.display = "none";
	subnav.style.visibility = "hidden";

	var menuItemID = subnav.id.replace(/(.*)_sub$/, "$1");
	var menuItemObj = document.getElementById(menuItemID);

	if (menuItemObj != null)
		$(menuItemObj).removeClass("open");

	Navigation.currentMenu = null;
}

Navigation.getTargetPos = function (subnav, menuitem)
{
	var alignElem = document.getElementById(Navigation.anchorElement);

	if (alignElem != null)
	{
		var alignTop = dom.getTop(alignElem);
		var alignLeft = dom.getLeft(alignElem);
		var alignRight = alignLeft + alignElem.offsetWidth;
	}
	else
	{
		var alignTop = dom.getTop(menuitem);
		var alignLeft = dom.getLeft(menuitem);
		var alignRight = alignLeft + menuitem.offsetWidth;
	}

	var itemLeft = dom.getLeft(menuitem);
	var itemRight = itemLeft + menuitem.offsetWidth;

	var subnavWidth = subnav.offsetWidth;
	var subnavHeight = subnav.offsetHeight;

	var subnavTop = alignTop;
	var subnavLeft;

	subnavLeft = itemLeft;
	if ((subnavLeft + subnavWidth) > alignRight)
		subnavLeft = alignRight - subnavWidth;

	var left = subnavLeft + Navigation.offsetX;
	var top = subnavTop + Navigation.offsetY;

	return { left: left, top: top };
}

Navigation.initSubnavigation = function (subnav)
{
	if (subnav == null || subnav.nodeName == null)
		return;

	subnav.style.visibility = "hidden";
	subnav.style.display = "block";

	var lists = subnav.getElementsByTagName("ul");

	var maxWidth = Number.NEGATIVE_INFINITY;
	var maxHeight = Number.NEGATIVE_INFINITY;
	var totalWidth = 0;

	for (var i = 0; i < lists.length; i++)
	{
		var itemWidth = lists[i].offsetWidth;
		if (itemWidth > maxWidth)
			maxWidth = itemWidth;
	}
	if (lists.length == 1 && maxWidth < Navigation.minLinkWidth)
		maxWidth = Navigation.minLinkWidth;

	for (var i = 0; i < lists.length; i++)
	{
		lists[i].style.width = maxWidth + "px";
		totalWidth += lists[i].offsetWidth;
		var links = lists[i].getElementsByTagName("a");
		for (var j = 0; j < links.length; j++)
		{
			var padding =
				(parseInt(dom.currentStyleProp(links[j], "paddingLeft")) || 0) +
				(parseInt(dom.currentStyleProp(links[j], "paddingRight")) || 0);

			links[j].style.width = (maxWidth - padding) + "px";
		}
	}
	for (var i = 0; i < lists.length; i++)
	{
		var itemHeight = lists[i].offsetHeight;
		if (itemHeight > maxHeight)
			maxHeight = itemHeight;
	}

	var wrapper = $(".wrapper", subnav)[0];
	if (wrapper != null)
	{
		wrapper.style.height = maxHeight + "px";
		wrapper.style.width = totalWidth + "px";
	}

	subnav.style.width = totalWidth + "px";
	subnav.style.display = "none";
}

function Buttons()
{
}

Buttons.startWidth = 30;
Buttons.defaultHeight = 15;
Buttons.patternHover = "100% -{0}px";
Buttons.patternNormal = "0% -{0}px";
Buttons.settingsID = "css_settings";
Buttons.active = false;

Buttons.setup = function ()
{
	Buttons.parseSettings();

	if (Buttons.active)
	{
		var buttons = $("a.button");
		buttons.each(Buttons.setupInstance);
		buttons.bind("mouseover", Buttons.onmouseover);
		buttons.bind("mouseout", Buttons.onmouseout);
	}
}

Buttons.setupInstance = function (button)
{
	var width = this.offsetWidth;
	var height = Buttons.defaultHeight;

	this.offset = Math.ceil((width - Buttons.startWidth) / 2) * height;
	this.style.backgroundPosition = Buttons.patternNormal.format(this.offset);
}

Buttons.onmouseover = function ()
{
	this.style.backgroundPosition = Buttons.patternHover.format(this.offset);
}

Buttons.onmouseout = function ()
{
	this.style.backgroundPosition = Buttons.patternNormal.format(this.offset);
}

Buttons.parseSettings = function ()
{
	var settingsElem = document.getElementById(Buttons.settingsID);
	if (settingsElem)
	{
		if (settingsElem.className.match(/hover_buttons_(0|1)/i))
			Buttons.active = RegExp.$1 == "1" ? true : false;
	}
}

function CallmeNow()
{
}

CallmeNow.call = function (button, id)
{
	var field = document.getElementById(id);
	if (field)
	{
		field.value = $.trim(field.value);
		var valid = field.value.match(/^\d+(\s*-\s*\d+)?$/) != null;
		$(field).next("p").text(valid
			? "U wordt zo spoedig mogelijk gebeld."
			: "Het ingevulde telefoonnummer is ongeldig."
		);
		if (valid)
			StartFreecall(id);
	}
}

// Google maps
var maps = [];
var layer = [];

function map(target, kml, properties) {
    this.kml = kml;
    this.properties = properties;
    this.m = new GMap2(document.getElementById(target));
    
    this.setMaptype();
    this.setControltype();
    this.setBounds();
    this.setLayers();
}

map.prototype.setMaptype = function(){
    switch(this.properties['maptype']){
		case 'normal':
			this.m.setMapType(G_NORMAL_MAP);
			break;
		case 'satellite':
			this.m.setMapType(G_SATELLITE_MAP);
			break;
		case 'hybrid':
			this.m.setMapType(G_HYBRID_MAP);
			break;
		case 'psysical':
			this.m.setMapType(G_PHYSICAL_MAP);
			break;
		default:
			this.m.setMapType(G_NORMAL_MAP);
    }
}

map.prototype.setControltype = function(){
    switch(this.properties['controltype']){
		case 'small':
			this.m.addControl(new GSmallZoomControl3D());
			break;
		case 'large':
			this.m.addControl(new GLargeMapControl3D());
			break;
	}
    
    switch(this.properties['mapcontroltype']){
    	case 'buttons':
    		this.m.addControl(new GMapTypeControl());
    		break;
    	case 'menu':
    		this.m.addControl(new GMenuMapTypeControl());
    		break;
    }
}

map.prototype.setBounds = function(){
    switch(this.properties['boundstype']){
		case 'center':
			var LatLng = new GLatLng(parseFloat(this.properties['lat']),parseFloat(this.properties['lng']));
			this.m.setCenter(LatLng, parseInt(this.properties['level']));
			break;
		case 'bounds':
			var ne = new GLatLng(parseFloat(this.properties['nelat']),parseFloat(this.properties['nelng']));
			var sw = new GLatLng(parseFloat(this.properties['swlat']),parseFloat(this.properties['swlng']));
			var bounds = new GLatLngBounds(sw, ne);
			this.m.setCenter(bounds.getCenter(), this.m.getBoundsZoomLevel(bounds));
			break;
    }
}

map.prototype.setLayers = function(){
    for(i in this.kml){
        layer[i] = new GGeoXml(this.kml[i]);
        layer[i].visible = true;
        this.m.addOverlay(layer[i]);
    }
}

$(document).ready(function(){
	ui.initialize();
	
    $('.toggleLayer').click(function(){
        var currentbutton = $(this);
        var currentlayer = layer[$(this).attr('id')];
        
        if(currentlayer.visible){
        	currentlayer.hide();
        	currentlayer.visible = false;
        }
        else{
        	currentlayer.show();
        	currentlayer.visible = true;
        }
    });
    
    
    //kaart reisdetail pagina (meer info: http://groups.google.com/group/Google-Maps-API/browse_thread/thread/e55b00d61b834cdc)
    $('#tabswitch_kaart').click(function(){
    	maps['reisdetail'].m.checkResize();
    	maps['reisdetail'].setBounds();
    });
});
