
var gm_header = null;
var portal_slider = null;
var offers_teaser = null;
var gm_header = null;
var widecalendar = null;
var spslider = null;
var accoslider = null;
var quicksearch = null;
var portal_flash = null;
var pos_x = null;
var init_portal_flash = null;

var template = '<div class="tooltip"><div class="tooltip_text"><div class="tooltip_text_first"></div><div class="tip">${text}</div><div class="tooltip_text_last"></div></div></div>';

// block right click event
var zeit = null;
function click0() {
	if (event.button != 1) { 
		popup();
		return false;
	}
}
function nsc(e) {
	if (e.which != 1) keinkontext();
}
function popup() {
	return false;
}
function nichts(e) {
	if (e.which != 1) return false;
}
function keinkontext() {
	clearTimeout(zeit);
	zeit = setTimeout("kontext()",1);
}
function kontext() {
	clearTimeout(zeit);
	popup();
}

function setupRightClickBlocker () {
	if (document.all)
	if (document.getElementById) document.oncontextmenu=popup;
	else document.onmousedown=click0;
	if (!(document.all) && document.getElementById)
	document.oncontextmenu=popup;
	if (document.layers) {
	document.captureEvents(Event.MOUSEUP | Event.MOUSEDOWN);
	document.onmousedown=nichts;
	document.onmouseup=nsc;
	}
}


function onDocumentLoad () {
	// main navigation
	try {
		new at.steiermark.main_navigation.hover( [$$('#main_nav li')], [$$('#main_nav li ul li')], [$$('#main_nav li ul li ul li')] );
		
		/*
		$$('#main_nav ul')[0].observe('mouseover', function () { 
			var size = GetWindowSize();
			$('bodyshade').setStyle({ 
				height: size[1] + 'px',
				display: 'block' ,
				opacity: 0.2
			});
			/* doesn't work in ie6
			if ($("bodyshade").getStyle('opacity') == 0) {
				ex66 = new Animator({duration: 800}).addSubject(new NumericalStyleSubject(
					$("bodyshade"), 'opacity', 0, 0.25
				));
				ex66.play();
			}
			
		});
		
		$$('#main_nav ul')[0].observe('mouseout', function () { 
			$('bodyshade').setStyle({ 
				display: 'none'
			}); 
		});
		*/
	
	} catch (e) {}
	
	// interest popup
	try {
		if($('interest_button') != null) {
			new at.steiermark.popup.popup($('interest_button'), $('interest_open'));
		}
	} catch (e) {}
	
	// interest popup
	try { 
		if($('languages_button') != null) {
			new at.steiermark.popup.popup($('languages_button'), $('languages_open'));
		}
	} catch (e) {}
	
	// portal teaser slider
	try {
		if($('portal_teaser') != null) {
			portal_slider = new at.steiermark.portalslider.teaserslider($('portal_teaser'));
		}
	} catch (e) {}
	
	// content teaser slider
	try {
		if($('offers_teaser') != null) {
            if($('content_teaser').select('.teaser').length > 1) {
			    offers_teaser = new at.steiermark.contentslider.teaserslider($('offers_teaser'));
            }
		}
	} catch (e) {}
	
	// google maps header
	try {
		if($('gm_header') != null) {
			gm_header = new at.steiermark.gmaps.gmapsheader($('gm_header'));
		}
	} catch (e) {}
	
	// custom calendar
	try {
		if($('widecalendar') != null) {
			widecalendar = new at.steiermark.widecalendar.hover($('widecalendar'));
		}
	} catch (e) {}
	
	// special slider map
	try {
		if($('spslider') != null) {
			spslider = new at.steiermark.special.slider($('spslider'));
		}
	} catch (e) {}
	
	// special slider content
	try {
		if($('accoslider') != null) {
			accoslider = new at.steiermark.special.slider($('accoslider'));
		}
	} catch (e) {}
	
	// quicksearchbox
	try {
		if($('quicksearchbox') != null) {
			quicksearch = new at.steiermark.quicksearch.slider($('quicksearchbox'));
		}
	} catch (e) {}
	
	// fix ie selectboxes
	try {
		if (Prototype.Browser.IE6 || Prototype.Browser.IE7 || Prototype.Browser.IE8) {
			for (i=1; i<6; i++) {
				if($('fix_select_' + i) != null) {
					new IEDropdown('fix_select_' + i);
				}
			}
		}
	} catch (e) {}
	
	// tooltips
	try {
		spa_container = $$('.icons .use_entry');
		toolTips(spa_container);
	} catch (e) {}
	
	try {
		barrierfree_container = $$('.bf_icons .bf_img');
		toolTips(barrierfree_container);
	} catch (e) {}

	// initialisierung calendar
	try {
		if($('packagesearch') != null) {
			new at.elements.calendar.init({
				button : 'duration_from',
				output : "input",
				dayInput: 'fromDay',
				monthInput: 'fromMonth',
				yearInput: 'fromYear',
				updateFieldOnStartup : false
			});
			new at.elements.calendar.init({
				button : 'duration_to',
				output : "input",
				dayInput: 'toDay',
				monthInput: 'toMonth',
				yearInput: 'toYear',
				updateFieldOnStartup : false
			});
		}
	} catch (e) {}
	
	// initialisierung calendar
	try {
		if($('form_packages') != null) {
			new at.elements.calendar.init({
				button : 'duration_from',
				output : "input",
				dayInput: 'fromDay',
				monthInput: 'fromMonth',
				yearInput: 'fromYear',
				updateFieldOnStartup : false
			});
			new at.elements.calendar.init({
				button : 'duration_to',
				output : "input",
				dayInput: 'toDay',
				monthInput: 'toMonth',
				yearInput: 'toYear',
				updateFieldOnStartup : false
			});
		}
	} catch (e) {}
	
	// set accommodation events for ajax results preview
	try {
		if($('form_unterkuenfte') != null) {
			setEventListeners();
			getResults();
		}
	} catch (e) {}
	
	// set packages ajax results preview
	try {
		if($('form_packages') != null) {
			setPackageEventListeners();
			getPackageResults();
		}
	} catch (e) {}

	// portal background resize
	try {
		if($('portal') != null) {
			window.setTimeout(function () {
				resizeFlashBackground();
			},250);	
			window.onresize = resizeFlashBackground;
		}
	} catch (e) {}
	
	try {
		initLightbox();
	} catch (e) {}
	
	try {
		if($('backgroundFlash') != null) {
			init_portal_flash = window.setInterval("setPortalFlash()", 250);
		}
	} catch (e) {}
	
	
	if($('logo_subportal_head') != null && $('logo_subportal_sub') != null) {
		var site_class = $$('#site.pois');
		if (site_class.length > 0) {
			$('logo_subportal_head').setStyle({ 
				display: 'block'
			});
		}
		else {
			$('logo_subportal_sub').setStyle({ 
				display: 'block'
			});
		}
	}
	
}

function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function setPortalFlash () {
	clearInterval(init_portal_flash);
	portal_flash = swfobject.getObjectById("backgroundFlash");
	resizeFlashBackground();
	
	/*
	Event.observe(window, 'scroll', function() {
		resizeFlashBackground();
	});
	*/
}

function GetWindowSize (w) {
    w = window;
    var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
    var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
    return [width, height]
}

function resizeFlashBackground () {
	var size = GetWindowSize();
	
	// background flash
	$("backgroundFlash").setAttribute("width",size[0]);
	$("backgroundFlash").setAttribute("height",size[1]);
	
	//var scrolloffset = Element.cumulativeScrollOffset($("portal"));
	
	// portal container
	var portal_size = (size[1]-(329+95));
	//pos_x = 0;
	//pos_y = portal_size+67;
	if (portal_size < 300) {
		portal_size = 300;
		/*
		pos_y = 367-scrolloffset.top;
		ie_explorer = navigator.userAgent.indexOf("MSIE");
		if (ie_explorer == -1) {
			pos_x = -8;
		}
		*/
	}

	$("portal").setStyle({ top: portal_size + 'px' });
	
	/*
	try {
		if (portal_flash != null) {
			portal_flash.teaserpos( pos_x, pos_y );
		}
	} catch (e) {}
	*/
}


function gotoLink (htmlElement) {
	var destinationURL = "";
	var target = "";
	
	if(htmlElement.href) {
		destinationURL = htmlElement.href;
		target = htmlElement.getAttribute("target");
	}
	else {
		if(htmlElement.childNodes) {
			if(htmlElement.getElementsByTagName("a")) {
				destinationURL = htmlElement.getElementsByTagName("a")[0].href;
				target = htmlElement.getElementsByTagName("a")[0].getAttribute("target");
			}
		}
	}
	
	if(target == "_blank") {
		window.open(destinationURL);
	}
	else {
		location.href = destinationURL;
	}
}


function toolTips (spa_container) {
	try {
		if(spa_container.length > 0) {
			for(i=0; i<spa_container.length; i++) {
				var data = {
					text: spa_container[i].getElementsBySelector(".tooltiptext")[0].innerHTML
				};         
				new at.elements.tooltip(spa_container[i].getElementsBySelector(".name")[0],{
					offsetY: -45,
					offsetX: 10,
					template: template,
					data: data 
				});
			}
		}
	}
	catch (e) {}
}


function str_replace (search, replace, subject, count) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'

    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}


function utf8_decode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'

    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }

    return tmp_arr.join('');
}


function base64_decode (data) {
    // http://kevin.vanzonneveld.net
    // +   original by: Tyler Akins (http://rumkin.com)
    // +   improved by: Thunder.m
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Pellentesque Malesuada
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_decode
    // *     example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
    // *     returns 1: 'Kevin van Zonneveld'

    // mozilla has this native
    // - but breaks in 2.0.0.12!
    //if (typeof this.window['btoa'] == 'function') {
    //    return btoa(data);
    //}

    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];

    if (!data) {
        return data;
    }

    data += '';

    do {  // unpack four hexets into three octets using index points in b64
        h1 = b64.indexOf(data.charAt(i++));
        h2 = b64.indexOf(data.charAt(i++));
        h3 = b64.indexOf(data.charAt(i++));
        h4 = b64.indexOf(data.charAt(i++));

        bits = h1<<18 | h2<<12 | h3<<6 | h4;

        o1 = bits>>16 & 0xff;
        o2 = bits>>8 & 0xff;
        o3 = bits & 0xff;

        if (h3 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1);
        } else if (h4 == 64) {
            tmp_arr[ac++] = String.fromCharCode(o1, o2);
        } else {
            tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
        }
    } while (i < data.length);

    dec = tmp_arr.join('');
    dec = this.utf8_decode(dec);

    return dec;
}


function getRealMl (data) {
	data = base64_decode(data);
	data = str_replace("BeGiNN", "", data);
	data = str_replace("EEnD", "", data);
	data = str_replace("$", "@", data);
	return data;
}


