
String.prototype.SUI_getVar = function(p){
    return (match = this.match(new RegExp("[?|&]?" + p + "=([^&]*)"))) ? match[1] : false;
}

var SUI_BookingBox = Class.create();
SUI_BookingBox.prototype = {
	isOpen: false,
	initialize: function(){
		var thisObj = this;
		toggle = function(){
			if(!thisObj.isOpen || arguments[0] == 'close'){
				thisObj.isOpen = !thisObj.isOpen;
				new Effect.toggle('bookingbox');
			}
			return false;
		}
		if($('submitexpress')){Event.observe($('submitexpress'), 'click',function(){toggle();});}
		if($('closeexpress')){Event.observe($('closeexpress'), 'click',function(){toggle('close');});
		}
	}
}


/**
* ClassName : SUI_OverBox
* Description : Class which performs the speach balloons into 'shortlinks' element. they appear when the user is on the links.
 */
var SUI_OverBox = Class.create();
SUI_OverBox.prototype = {
	shortLinks: $('shortlinks'),
	overBox: $('overbox'),
	lastItem: null,
	isBlocked: false,
	initialize: function() {
		var thisObj = this;
		if(thisObj.shortLinks){
			thisObj.shortLinks.getElementsBySelector('li').each(function(item){
				/*Event listener*/
				Event.observe(item, 'mouseover',function(){
					if(thisObj.overBox){
						/*Performs Close button*/
						if(item.firstChild.getAttribute('rel')){
							if(closeButton = thisObj.overBox.down('.'+item.firstChild.getAttribute('rel')+' .close')){
								Event.observe(closeButton, 'click',function(){
									thisObj.fadeItem(this.up('li'), null);
									thisObj.lastItem = null;
								});
							}
						}
						/*Performs Appear/Hide Behaviours*/
						callbackFunction = function(){
							if(!thisObj.isBlocked){
								thisObj.isBlocked = true;
								if(item.firstChild.getAttribute('rel')){
									Effect.Appear(thisObj.overBox.down('.'+item.firstChild.getAttribute('rel')), {duration: .1, afterFinish:function(){thisObj.isBlocked = false;}});
									thisObj.lastItem = item;
								}
								else thisObj.isBlocked = false;
							}
						}
						/*One balloon case*/
						if(thisObj.lastItem == null){
							callbackFunction();
						/*Hide the last box to appear the new box*/
						}else if(thisObj.lastItem.firstChild.getAttribute('rel') != item.firstChild.getAttribute('rel')){
							if(item.firstChild.getAttribute('rel'))
								thisObj.fadeItem(thisObj.overBox.down('.'+thisObj.lastItem.firstChild.getAttribute('rel')), callbackFunction);
						}
					}
				});
			});
		}
	},
	/*Method which hides box */
	fadeItem:function(item, callBackOnFinish){
		if(item != null) Effect.Fade(item, {duration: .1, afterFinish: callBackOnFinish});
	}
}

/**
* ClassName : SUI_Tabs
* Description : 
 */
var SUI_Tabs = Class.create();
SUI_Tabs.prototype = {
	tabsArea : $('tabs'),
	lastItem: $('searchboxcontenttabs') ? $('searchboxcontenttabs').getElementsBySelector('li')[0] : null,
	isBlocked: false,
	initialize: function(){
		var thisObj = this;
		$('searchboxcontenttabs').getElementsBySelector('li').each(function(item){
			Event.observe(item.firstChild, 'click',function(){
				thisObj.moveOnClass(item);
				if(thisObj.tabsArea){
					if(!thisObj.isBlocked){
						thisObj.isBlocked = true;
						if(item.firstChild.getAttribute('rel')){
							callbackFunction = function(){
								if(item != null) Effect.Appear(thisObj.tabsArea.down('.'+item.firstChild.getAttribute('rel')), {duration: .1, afterFinish: function(){thisObj.isBlocked = false;thisObj.lastItem = item;}});
							}
							Effect.Fade(thisObj.tabsArea.down('.'+thisObj.lastItem.firstChild.getAttribute('rel')), {duration: .1, afterFinish: callbackFunction});
						}
						else thisObj.isBlocked = false;
					}
				}
				return false;
			});
		});
	},
	moveOnClass:function(item){
		item.className = item.className+' on';
		if(this.lastItem.className.startsWith('last')) this.lastItem.className = 'last';
		else this.lastItem.className = '';
	}
}

/**
* ClassName : SUI_Popup
* Description : 
 */
SUI_Popup = {
	toggled: true,
	items : [
	{id:'phonebooking', height:400, width:400},
	{id:'toolprint', height:600, width:550},
	{id:'print', height:600, width:550},
	{id:'lnk_fav', height:550, width:550},
	{id:'factsheet', height:550, width:550}
	],
	load : function(){
		this.items.each(function(item){
			if($(item.id)){
				var href = $(item.id).getAttribute('href');
				$(item.id).setAttribute('href','#');
				Event.observe($(item.id), 'click', function() {
					var popup = window.open(href, this.getAttribute('title'), 'height='+item.height+'px, width='+item.width+'px, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
					if(item.callback)
						item.callback(popup);
					return false;
				});
			}
		});
		this.loadGallery();
	},
	loadGallery: function(){
		this.toggled = true;
		if($('dialogcontent')){
			var flashObj = new SWFObject("/flash/fichehotel/galerie_sui.swf", "dialogcontent", "810", "555", "8", "");
			var lang =  $$('html')[0].getAttribute('xml:lang') == 'en' ? 'gb' : $$('html')[0].getAttribute('xml:lang');
			var rid =  document.getElementsByName('X-Accor-rid')[0].content; 
			if(flashObj){
				flashObj.addVariable("lang", lang);
				flashObj.addVariable("idHotel", rid);
				flashObj.addVariable("cat", document.getElementsByName('X-Accor-mediatype')[0].content.toLowerCase());
				flashObj.addVariable("Domain", window.location.href.toString());
				if(arguments[0]){
					flashObj.addVariable("media", arguments[0]);
				}

				flashObj.addParam("wmode", "transparent");
				flashObj.write('dialogcontent');
			}
			new SUI_Dialog.Box('dialog');
			if(!arguments[1]){
				if($('closegallery')) Event.observe($('closegallery'), 'click', function(){this.toggleIframe(); $('dialog').hide();}.bind(this));
				if($('dialog_overlay')) Event.observe($('dialog_overlay'), 'click', function(){this.toggleIframe();}.bind(this));
			}
			
		}
	},
	openGallery: function(){
		$('dialog').show();
		this.toggleIframe();
	},
	toggleIframe: function(){
		$$('#iframe_resa, #iframe_oas').each(function(item){
			if(this.toggled){
				item.setStyle({display:'none'});
			}else{
				item.setStyle({display:'block'});	
			}
		}.bind(this));
		this.toggled = !this.toggled;
	}
}

SUI_External = {
	brand : 'suitehotel.com',
	load : function(){
		var regex = new RegExp(this.brand);
		if(!regex.test(window.document.URL))
			$$('body')[0].className = $$('body')[0].className + ' external';
	}
}

var SUI_Dialog = {};
SUI_Dialog.Box = Class.create();
Object.extend(SUI_Dialog.Box.prototype, {
  initialize: function(id) {
    this.createOverlay();

    this.dialog_box = $(id);
    this.dialog_box.show = this.show.bind(this);
    this.dialog_box.hide = this.hide.bind(this);

    this.parent_element = this.dialog_box.parentNode;

    var e_dims = Element.getDimensions(this.dialog_box);
    var b_dims = Element.getDimensions(this.overlay);
	
	this.dialog_box.style.position = "absolute";
	this.dialog_box.style.left = ((b_dims.width/2) - (e_dims.width/2)) + 'px';
	this.dialog_box.style.top = '12px';
	this.dialog_box.style.zIndex = this.overlay.style.zIndex + 1;

	
  },

  createOverlay: function() {
    if($('dialog_overlay')) {
      this.overlay = $('dialog_overlay');
    } else {
      this.overlay = document.createElement('div');
      this.overlay.id = 'dialog_overlay';
      Object.extend(this.overlay.style, {
      	position: 'absolute',
      	top: 0,
      	left: 0,
      	zIndex: 90,
      	width: '100%',
      	backgroundColor: '#000',
      	display: 'none'
      });
      document.body.insertBefore(this.overlay, document.body.childNodes[0]);
    }
  },

  moveDialogBox: function(where) {
    Element.remove(this.dialog_box);
    if(where == 'back')
      this.dialog_box = this.parent_element.appendChild(this.dialog_box);
    else
      this.dialog_box = this.overlay.parentNode.insertBefore(this.dialog_box, this.overlay);
  },

  show: function() {
    this.overlay.style.height = $$('body')[0].getHeight()+'px';
    this.moveDialogBox('out');
    this.overlay.onclick = this.hide.bind(this);
    this.selectBoxes('hide');
    new Effect.Appear(this.overlay, {duration: .5, from: 0.0, to: 0.8});
    this.dialog_box.style.display = ''
  },

  hide: function() {
    this.selectBoxes('show');
    new Effect.Fade(this.overlay, {duration: .5});
    this.dialog_box.style.display = 'none';
    this.moveDialogBox('back');
    $A(this.dialog_box.getElementsByTagName('input')).each(function(e){if(e.type!='submit')e.value=''});
  },

  selectBoxes: function(what) {
    $A(document.getElementsByTagName('select')).each(function(select) {
      Element[what](select);
    });

    if(what == 'hide')
      $A(this.dialog_box.getElementsByTagName('select')).each(function(select){Element.show(select)})
  }
});