$(document).ready(function(){    

    // Coda Slider 2 (www.ndoherty.biz/2009/10/coda-slider-2)
    // fuer Slideshow auf Homepage

    $('#sliderHome').codaSlider({
        autoHeight: false,
        autoSlide: true,
        autoSlideInterval:7000,
        dynamicArrows: false,
        dynamicTabs: false,
        slideEaseDuration: 1000,
        slideEaseFunction: "easeInOutQuart"
    });

	// Auskommentiert (Istvan)  21.4., damit der Pageslide nicht ausgefŸhrt wird.
	// $('.btBooking').smartPageSlide({'width': '750px'});

    mapInitialize();
});



// Google Maps

function mapInitialize() {
    var latlng = new google.maps.LatLng(48.15203,11.556327);
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
	  mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
	  navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL } 
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var marker = new google.maps.Marker({
		position:latlng,
		map: map,
		title: 'Hotel Europa, MŸnchen',
		icon: 'http://hotel-europa.iv-media.de/assets/images/sys/mapMarker.png'
	});
  }









/**
* jQuery smartPageSlide
*
* @name jquery-smartPageSlide-0.1.js
* @author Robert RoeÂšmer - robert.roemer@triplex.de
* @version 0.1
* @date September 6, 2010
* @category jQuery plugin
*
* original from: jQuery PageSlide
*
* This jQuery plugin was inspired by the UI designs of Aza Raskin (http://www.azarask.in/),
* in his Firefox mobile and Ubiquity mouse gesture prototypes, adapted for use as a jQuery lightBox-esque plugin.
*
* @name jquery-pageslide-0.2.js
* @author Scott Robbin - http://srobbin.com
* @author Ian Lewis - http://www.ianlewis.org/
* @version 0.2
* @date January 7, 2009
* @category jQuery plugin
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
**/

(function($){
	
	$.fn.smartPageSlide = function(options) {
		// define the default configuration and update them with the custom configuration in "options"
		_setSettings( $.extend( {}, _getDefaults(), options) );

		/**
		* save informations to the configuration variable
		* if you want to save multiple informations, provide them as object an leave the second parameter undefined
		* otherwise if you want to modify one information, provide the name of the entry as second parameter
		*/
		function _setSettings(data, key) {
			var result = false;
			if ( key == undefined ) {
				for ( var dkey in data ) {
					if ( dkey != undefined ) _setSettings(data[dkey], dkey);
				}
				result = true;
			} else if ( _getSettings(key) != undefined ) {

				if ( (key.indexOf('WrapperId') > 0 || key.indexOf('FallbackId') > 0 ) && data.substring(0, 1) != '#' ) {
					var first_char = data.substring(0, 1);
					if ( first_char == '.' ) {
						data = '#' + data.substring(1);
					} else {
						data = '#' + data;
					}
				} else if ( key.indexOf('includeInline') == 0 && typeof(data) != 'Boolean' ) {
					data = _getDefaults(key);
				}
				$.fn.smartPageSlide.settings[key] = data;
				result = true;
			}
				
			return result;
		}

		/**
		* return saved configuration informations
		* if you want only one information, provide the name of the entry
		*/
		function _getSettings(key) {
			if ( key == undefined ) {
				return $.fn.smartPageSlide.settings;
			} else if ( $.fn.smartPageSlide.settings[key] != undefined ){
				return $.fn.smartPageSlide.settings[key];
			} else {
				return undefined;
			}
		}

		/**
		* return default configuration informations
		* if you want only one information, provide the name of the entry
		*/
		function _getDefaults(key) {
			if ( key == undefined ) {
				return $.fn.smartPageSlide.defaults;
			} else {
				return $.fn.smartPageSlide.defaults[key];
			}
		}

		/**
		* function for debugging (firebug logs)
		*/
		function _debug(obj, comment) {
			if (window.console && window.console.log) {
				var group_title = 'smartPageSlide';
				if ( comment != undefined ) group_title += ': '+comment;
				window.console.group(group_title);
				window.console.log(obj);
				window.console.groupEnd();
			}
		};

		function _initialize() {
			settings = _getSettings();
			
			// Create and prepare elements for pageSlide
			var psSlideContent = document.createElement("div");
			$(psSlideContent).attr("id", settings.contentWrapperId.substring(1));
		
			var psSlideWrap = document.createElement("div");
			$(psSlideWrap).attr("id", settings.slideWrapperId.substring(1)).append( psSlideContent );
				
			// Wrap and append so that we have the slide containers
			$("body").append( psSlideWrap );
		
			// If a user clicks the document, we should hide the pageslide
			// and override that click functionality for the slide pane itself
			$(document).click(function() {
				$.fn.smartPageSlide.closeSlide();
			});


			$(settings.slideWrapperId).click(function(){ return false; });
		
			settings.initialized();

			return true;
		};
		
		/**
		* open the slide, validate the defined request and start the content processing
		*/
		function _openSlide(el) {
			if ( $(settings.slideWrapperId).hasClass('open') == true ) {
				_debug('cannot open slide, because it is open');
				return false;
			}

			settings = _getSettings();
			
			settings.beforeOpen();
			$(settings.slideWrapperId).addClass('open');
			var halfWidth = (parseInt(settings.width)/2) +'px';
			$('body').animate({
					'margin-left': '-'+halfWidth,
					'padding-right': halfWidth
				}, settings.duration);
			$(settings.slideWrapperId).animate({width: settings.width}, settings.duration, function() {
				$(settings.slideWrapperId).css('overflow', 'visible');
				_resizeFallbackIframe();
				settings.afterOpen();
			});

			var tag_name = $(el).get(0).tagName.toLowerCase();
			
			var request_url = '';
			var request_method = 'GET';
			var request_data = {};

			if ( tag_name == 'input' ) {
				var formEl = $(el).parents('form');
				var form_method = formEl.attr('method');
				var form_action = formEl.attr('action');
				request_data = formEl.serialize();
				
				if ( form_method.toUpperCase() == 'POST' ) request_method = 'POST';
				
				if ( form_action.substring(0,1) == '/' ) {
					request_url = document.location.protocol+'//'+document.location.hostname + form_action;
				} else if ( form_action.substring(0, 4) != 'http' && form_action.substring(0, 1) != '#') {
					request_url = location.href.substring(0,location.href.lastIndexOf("/")+1) + form_action;
				} else {
					request_url = form_action;
				}
			} else {
				request_url = $(el).attr("href");
			}

			return processSlideContent(request_method, request_url, request_data);
		};

		/**
		* process the given request and start the content insertion
		*/
		function processSlideContent(request_method, request_url, request_data) {
			settings = _getSettings();

			$.fn.smartPageSlide.lastRequest('target',	request_url);
			$.fn.smartPageSlide.lastRequest('method',	request_method);
			$.fn.smartPageSlide.lastRequest('data',		request_data);
			$.fn.smartPageSlide.lastRequest('success',	false);

			if ( request_url.substring(0,1) == '#' ) {
				$.fn.smartPageSlide.lastRequest('success', true);
				// get the element with the defined id and call method which set the content
				return insertSlideContent($(request_url));
			}

			// slide content for the iframe version and iframe fallback
			var iframeVersion = '<iframe id="'+settings.iframeFallbackId.substring(1)+'" src="'+request_url+'?'+request_data+'" width="100%"></iframe>';

			if ( settings.method == 'iframe' ) {
				return insertSlideContent(iframeVersion);
			}
			

			$.ajax({
					type: request_method,
					url: request_url,
					data: request_data,
					async: true,
					'success': function (data) {
						$.fn.smartPageSlide.lastRequest('success', true);
						if ( data == '' && settings.iframeFallback == true ) {
							_debug('response data is empty, use iframe fallback');
							return insertSlideContent(iframeVersion); // set iframe fallback
						} else {
							return insertSlideContent(data); // set the requested data
						}
					}
			});
			
			return null;
		}

		/**
		* insert the content into the slide
		*/
		function insertSlideContent ( data ) {
			settings = _getSettings();

			if ( settings.includeInlineScripts === true ) {
				includeInlineScripts = true;
			} else {
				includeInlineScripts = false;
			}
			
			if ( settings.includeInlineStyles === true ) {
				includeInlineStyles = true;
			} else {
				includeInlineStyles = false;
			}

			/*
			* find css and js tags they whould only include files
			* if there are some tags found, test if they were already included - if not append the required lines to the head part of the current document
			*/
			var newRemoteScripts = '';
			var newRemoteScriptsDefer = '';
			var re = new RegExp("(<script[^>]*><\/script>|<script[^>]*\/>|<link[^>]*><\/link>|<link [^>]*\/>)", "g");
			var remoteScriptArray = data.match(re);
			if ( remoteScriptArray != null) {
				var linkAttr = false;
				var tagName = false;
				var headHtml = $('head').html();
				for ( var i = 0; i < remoteScriptArray.length; i++ ) {
					var element = remoteScriptArray[i];
					if (element.indexOf('<script ') == 0) {
						linkAttr = 'src';
						tagName = 'script';
					}
					else if (element.indexOf('<link ') == 0) {
						linkAttr = 'href';
						tagName = 'link';
					} else {
						continue;
					}
					var beginLink	= element.indexOf(linkAttr)+linkAttr.length+2;
					var endLink		= element.indexOf('"', beginLink);
					var linkAddress	= element.substring(beginLink, endLink).replace(window.location.protocol+'//'+window.location.hostname, '');
					var testSelector= tagName+'['+linkAttr+'='+linkAddress+']';
					
					if ( headHtml.indexOf(linkAttr+'="'+linkAddress+'"') > 0 || headHtml.indexOf(linkAttr+'=\''+linkAddress+'\'') > 0) {
						_debug('file already loaded: "'+linkAddress+'"');
					} else {
						if (element.toLowerCase().indexOf('defer') > 0) {
							newRemoteScriptsDefer += element;
							_debug('add address: "'+linkAddress+'"');
						} else {
							newRemoteScripts += element;
							_debug('add address: "'+linkAddress+'" (defer)');
						}								
					}
				}
			}
			
			var newLocalScripts = '';
			var newLocalScriptsStartTag = '<script type="text/javascript">';
			var newLocalScriptsEndTag = '</script>';
			var newRemoteScriptsBeginPos = data.indexOf(newLocalScriptsStartTag);
			
			if ( newRemoteScriptsBeginPos !== false && newRemoteScriptsBeginPos > 0 ) {
				var newRemoteScriptsEndPos = data.indexOf(newLocalScriptsEndTag, newRemoteScriptsBeginPos);
				if ( newRemoteScriptsEndPos !== false && newRemoteScriptsEndPos > newRemoteScriptsBeginPos + newLocalScriptsStartTag.length ) {
					newLocalScripts += data.substring(newRemoteScriptsBeginPos, newRemoteScriptsEndPos + newLocalScriptsEndTag.length);
				}
				
				if ( newLocalScripts !== '' ) {
					_debug('new local scripts: should be appended');
				} else {
					_debug('new local scripts: none');
				}
			}

			var beginBodyOpenTag	= data.indexOf('<body');
			var endBodyOpenTag		= data.indexOf('>', beginBodyOpenTag)+1;
			var beginBodyCloseTag	= data.indexOf('</body>');
			var content				= data.substring(endBodyOpenTag, beginBodyCloseTag);

			$('head').append(newRemoteScripts);
			$('head').append(newRemoteScriptsDefer);
			$('head').append(newLocalScripts);

			$(settings.contentWrapperId).html(content)
			.queue( function() {
				settings.loaded();
				$('.pageslide-close').unbind('click').bind('click', function(){ $.fn.smartPageSlide.closeSlide(); return false; });
				_resizeFallbackIframe();
				$(this).dequeue();
			});

			return true;
		}
		
		function _resizeFallbackIframe(width, height) {
			settings = _getSettings();
			if ( width == undefined ) width = $(settings.slideWrapperId).width();
			if ( height == undefined ) height = $(settings.slideWrapperId).height();

			$(settings.iframeFallbackId).height( height )
			$(settings.iframeFallbackId).width( width );
		}
		
		settings = _getSettings();
		
		// Initalize pageslide
		if( $(settings.slideWrapperId).length == 0) {
			_initialize(this);
			return this.each(function(){
				var thisObj = $(this);
				
				console.log(this);
				if ( thisObj.attr('href') != '' ) {
					thisObj.unbind("click").bind("click", function(){
						_openSlide(this);
						return false;
					});
				} else if ( this.tagName.toLowerCase() == 'input' ) {
					if ( thisObj.attr('type') == 'submit' ) {
						thisObj.parents('form:eq(0)').unbind('submit');
					}
					thisObj.unbind("click").bind("click", function(){
						_openSlide(this);
						return false;
					});
				}
			});
		}
	};


	/**
	* close a open slide
	*/
	$.fn.smartPageSlide.closeSlide = function() {
		settings = $.fn.smartPageSlide.settings;
		settings.beforeClose();
		
		if ( $(settings.slideWrapperId).hasClass('open') == true ) {
			$('body').animate({
					'margin-left': 0,
					'padding-right': 0
				}, settings.duration);

			$(settings.slideWrapperId).animate({width: "0"}, settings.duration, function() {
				$(settings.contentWrapperId).empty();
				settings.afterClose();
				$(settings.slideWrapperId).removeClass('open');
				$(settings.slideWrapperId).css('overflow', '');
			});
			return false;
		} else {
			return true;
		}
	}

	// plugin defaults
	if ( $.fn.smartPageSlide.settings == undefined ) {
		$.fn.smartPageSlide.defaults = {
			width:					"500px",		// Accepts fixed widths
			duration:				"normal",		// Accepts standard jQuery effects speeds (i.e. fast, normal or milliseconds)
			method:					"inline",		// should we load a external source and paste the data as inline content or should we create a iframe
			beforeOpen:				function(){},	// called before slide in
			afterOpen:				function(){},	// called after slide in
			loaded:					function(){},	// called when the load process is complete
			beforeClose:			function(){},	// called before slide out
			afterClose:				function(){},	// called after slide out
			initialized:			function(){},	// called after the intial action
			slideWrapperId:			"#pageslide-slide-wrap",
			contentWrapperId:		"#pageslide-content",
			iframeFallbackId:		"#pageslide-iframe",
			iframeFallback:			true,
			includeInlineScripts:	true,
			includeInlineStyles:	true
		};

		$.fn.smartPageSlide.settings = $.fn.smartPageSlide.defaults;
	}

	$.fn.smartPageSlide.lastRequest = function(key, value) {
		if ( key == undefined ) {
			return undefined;
		}
		
		if ( value != undefined ){
			window.smartPageSlideLastRequest[key] = value;
		}

		return window.smartPageSlideLastRequest[key];
	}

	if ( window.smartPageSlideLastRequest == undefined ) {
		window.smartPageSlideLastRequest = {target: null, method: null, data: null, success: false };
	}

})(jQuery);
