/* -------------------------------------------------------------------------- */
/*  TT-Line - country sites javascript                                        */
/* -------------------------------------------------------------------------- */
var activeTab = "tabDepartures";
var isIE6 = navigator.userAgent.indexOf("MSIE 6") >= 0;
var hoverLang;

function showBookingTab(e) {
	// get source element of the event
	if (!e) var e = window.event;
	target = (e.target) ? e.target : e.srcElement;
	if (!target) return;

	// check if target element is child of A element
	if (target.tagName != "A") target = target.parentNode;

	if (elm = document.getElementById(activeTab + "Content")) elm.style.display = "none";
	if (elm = document.getElementById(activeTab)) elm.className = "linkTab";
	if (elm = document.getElementById(target.id + "Content")) elm.style.display = "block";
	if (elm = document.getElementById(target.id)) elm.className = "selected linkTab";
	activeTab = target.id;

	return false;
}

function printPage() {
	window.print();

	return;
}



function hideLayer(layerid) 
{
    if (elm = document.getElementById(layerid)) 
    {
	    elm.style.visibility = "hidden";
    	if (isIE6) {
    		if (elm = document.getElementById("travelbox")) {
			    elm.style.visibility = "visible";
		    }
	    }
    }
    return;
}

function hideEmergencyLayer() 
{
    return hideLayer("emergencyContent");
    /*
	if (elm = document.getElementById("emergencyContent")) {
		elm.style.visibility = "hidden";
		if (isIE6)
		{
			if (elm = document.getElementById("travelbox")) 
			{
				elm.style.visibility = "visible";
			}
		}
	}
	return;*/
}

function doOnLoad() {
	var elm, i, s;
	// attach event handlers
	if (elm = document.getElementById("tabDepartures")) elm.onclick = showBookingTab;
	if (elm = document.getElementById("tabOnboardPackage")) elm.onclick = showBookingTab;
	if (elm = document.getElementById("tabTravelPackage")) elm.onclick = showBookingTab;

	// print icon
	if (elm = document.getElementById("printIcon")) elm.onclick = printPage;

	// emergency page
	if (elm = document.getElementById("emergencyCloseButton1")) elm.onclick = hideEmergencyLayer;
	if (elm = document.getElementById("emergencyCloseButton2")) elm.onclick = hideEmergencyLayer;

	// only necessary for IE6
	if (isIE6) {
		if (elm = document.getElementById("emergencyContent")) {
			if (elm = document.getElementById("travelbox")) elm.style.visibility = "hidden";
		}
	}

	if (isIE6) {
		for (i = 1; i <= 2; i++) {
			if (elm = document.getElementById("teaserBorder" + i)) {
				elm.onmouseover = function() {
					this.style.cursor = "pointer";
				}
			}
		}
	}

	return;
}

window.onload = doOnLoad;

$(document).ready(function() {
    $.fn.qtip.styles.ttlinestyle = { // Last part is the name of the style
        background: '#fff',
        color: 'black',
        textAlign: 'left',
        border: {
            width: 1,
            radius: 3,
            color: '#0077bd'
        },
        tip: 'bottomLeft',
        name: 'dark' // Inherit the rest of the attributes from the preset dark style
    }

    $('span.texthover').each(function() {
        $(this).qtip({
            content: { 
             method: 'GET',
             url: '/Templates/DynamicContent/ajax.aspx?phrase=' + $(this).html() + '&lang=' + hoverLang,
             text: '<div class="ttline-loading"><img class="throbber" src="/images/ajax_loading.gif" alt="Loading..." /></div>' 
           },
            position: {
                corner: {
                    target: 'topRight',
                    tooltip: 'bottomLeft'
                }
            },
            style: {
                name: 'ttlinestyle',
                padding: '4px 7px',
                width: {
                    max: 255,
                    min: 0
                },
                tip: true
            }
        });
    });
});

