
if(window.loadFirebugConsole) {
	window.loadFirebugConsole();
}

function DEBUG(string) {
	if(window.loadFirebugConsole) {
        console.log(string);
    }
} 	

function TravelInfoTicker() {

	var tickerHandel;
	
	var tickerList;

	this.SetList = function (string) {
		
		if(string.length<1) {
			return false;
		}

		tickerList = $('#tickerList');
		explode = new Array();
		explode = string.split(',');
		list = '';
		for(var i = 0; i < explode.length; i+=2) {
			list += '<p>+++&nbsp;&nbsp;<a target="_blank" href="http://www.thomascook.info/tck/Reisehinweise_Startseite.jsp#' + explode[i+1]  + '" onclick=\'s_objectID="http://www.thomascook.info/tck/Reisehinweise_Startseite.jsp#8' + explode[i+1]  + '_1";return this.s_oc?this.s_oc(e):true\'>' + explode[i] + '</a>&nbsp;&nbsp;</p>';	
		}
		list += list;
		$(tickerList).html(list);
		allWidth = 0;
		$(tickerList).find("p").each(function (i) {
			allWidth += $(this).width();
		});
		$(tickerList).css('width', allWidth);
		firstItem = $(tickerList).find('p:first');
		setTimeout(function() { scroll(firstItem, $(firstItem).width(), 0) }, 3000);
	}
	
	function scroll(currentItem, currentItemWidth, marginLeft) {
		if(currentItemWidth < Math.abs(marginLeft)) {
			marginLeft = 0;
			$(tickerList).find('p:last').after("<p>" + $(currentItem).html() + "</p>");
			$(currentItem).remove();
			currentItem = $(tickerList).find('p:first');
			currentItemWidth = $(currentItem).width();
		}
		$(tickerList).css('margin-left', marginLeft + 'px');
		marginLeft = marginLeft - 1;
		tickerHandel = setTimeout(function() { scroll(currentItem, currentItemWidth, marginLeft); }, 50 );
	}
	
	
	function stop() {
		clearTomeout(tickerHandel);
	}
	
}	



function openPopup() {
	$('#GrayOut').show();
	$('#InnerDimensions').show();
	//$('#InnerDimensions').height( $(window).height() );
	$('#InnerDimensions').css("left", $(document).scrollLeft() + 'px'); 
	$('#InnerDimensions').css("top", $(document).scrollTop() + 50 + 'px'); 
}

function openPopupIframe(theURL) {	
	//$('#HotelLayer').attr("src",theURL);
	//$('#HotelLayer').load(theURL);
	$('#HotelLayerContent').load(theURL);
	$('#GrayOut').show();
	$('#InnerDimensions').show();
	//$('#InnerDimensions').height( $(window).height() );
	$('#InnerDimensions').css("left", $(document).scrollLeft() + 'px'); 
	$('#InnerDimensions').css("top", $(document).scrollTop() + 50 + 'px'); 
}

function closePopup() {
	$('#InnerDimensions').hide();
	$('#GrayOut').hide();
}

function openWindow(inURL, inWidth, inHeight) {
	var theFeatures = "height=" + inHeight + ",width=" + inWidth + ",toolbars=0,scrollbars=1";
	var popup = window.open(inURL, "pop", theFeatures);
	popup.focus();
	if(popup)
		return false;
	else
		return true;
}



// Funktion um den jeweiligen Bereich zu highlighten
// nimmt den von CS �bergebenen Parameter und setzt den jeweiligen Bereich
function setNavHighlight(item) {
	$('#' + item).attr("id",item + "_active");
}

function addToWatchlist ( obj )  {
	with( $( obj ) ) {
		 text( text().replace(/merken/, 'gemerkt') );
		 removeAttr('href');
		 if( hasClass('memo') ) {
			 	addClass('memoed');
				removeClass('memo');
		 }
		 with( parents('.memo') ) {
				addClass('memoed');
				removeClass('memo');
		 }
	}	 
	return false; 
}

function popupPrint () {
	$('#Skyscraper, #LeftCol, #RightCol, #Header, #Footer, #Superbanner, #GrayOut').hide();
	$('#InnerDimensions').css("left", "0" ); 
	$('#InnerDimensions').css("top", "0" );
	window.print();
	window.setTimeout( function () {
		$('#InnerDimensions').css("left", $(document).scrollLeft() + 'px'); 
		$('#InnerDimensions').css("top", $(document).scrollTop() + 50 + 'px'); 	
		$('#Skyscraper, #LeftCol, #RightCol, #Header, #Footer, #Superbanner, #GrayOut').show();
	} , 1000)
}

function openLayer(selector, pageUrl) {
	  contentUpdater.get(selector, pageUrl);
		openPopup();
}


/* Austauschen des Inhalts eines DIVs */
var contentUpdater = {
	
	get: function(selector, pageUrl) {
		$.ajax ({
			url: pageUrl,
			cache: false,
			success: function(html){
				$(selector).html(html);
			}
		});
	},
	post: function(selector, pageUrl) {
		var str = $(selector + " form").serialize();
		$.ajax ({
			url: pageUrl,
			cache: false,
			type: "POST",
			data: str,
			success: function(html){
				$(selector).html(html);
			}
		});
		return false; // testweise ergaenzt gback 18.09.2009 
	},
	
	copy: function(sourceSelector, destinationSelector) {
		$(destinationSelector).html($(sourceSelector).html());
	}
	
}


//
$(document).ready(function() {
	$('table.striped tbody tr:odd').addClass('odd');
	$('table.striped tbody tr:even').addClass('even');
	$('table.gewinnspiel tbody tr:even').addClass('gray');
	
	//Navigation highlighten wenn in die Ergebnislisten gesprungen wird
	if(typeof BOOKING_MAIN_NAV != "undefined")
		setNavHighlight(BOOKING_MAIN_NAV);	
});
