document.write('<style type="text/css">.revealedDiv, .ui-tabs-hide, .content div.tabs h3 { display:none; } .content .left-side ul li:hover ul {display: none;} .content .left-side ul li.active:hover ul {display: block;}</style>');

String.prototype.startsWith = function(str) {
    return (this.match("^" + str) == str);
}

var $j = jQuery.noConflict();
var hotelsArray = new Array();

function activateBooking() {
    roomsChange();
    hotelMaxRoomUpdate();
	$j('.booking-form').find('.row-form span.button input').click( function() {
		$j(this).parents('form').submit(function() {
			pageTracker._linkByPost(this);
		});
	});
}

function roomsChange() {
    var currentRooms = $j('#rooms select').attr('selectedIndex');
    var parentform = $j('#book-form');
    for (var i = 0; i < parentform.find('.roomRow').length; i++) {
        if (i > currentRooms) {
            parentform.find('.roomRow:eq(' + i + ')').hide();
        } else {
            parentform.find('.roomRow:eq(' + i + ')').show();
        }
    }
    $j('.drop_body').each( function() {
		if(!$j(this).siblings('.drop_head').find('input').attr('checked'))
			$j(this).hide();
	});
}

function hotelMaxRoomUpdate() {
    var destSelect = $j('#DestinationSelection select:first').change(function() {

        var option = $j('option[value=' + destSelect.val() + ']', destSelect);

        $j('#promoContent').css('display', option.hasClass('nopromo') ? 'none' : 'block');

        if (option.attr('class').startsWith('maxRooms')) {
            var max = option.attr('class').substring(8, 9);
            var rooms = $j('#rooms select:first');

            var currentValue = rooms.val();
            rooms.empty();

            for (i = 0; i < max; i++) {
                rooms.append('<option value=' + (i + 1) + '>' + (i + 1) + '</option>');

                if (i == currentValue) {
                    rooms.selectedIndex = i;
                    rooms.val(i);
                }
            }

            roomsChange();
        }

    });


}

var menuItems = new Array();
var menuInterval;

function hideMenuItems() {
    clearTimeout(menuInterval);
    for (var i = 0; i < menuItems.length; i++) {
        menuItems[i].removeClass('over');
    }
    menuItems = new Array();
}

function setHotelEnquiry()
{
	var cal = $j('input[type=image]', '#enquiry-date');
	cal.remove();
	
	var now = new Date();	

	var dateInput = $j('input:first', '#enquiry-date');
		dateInput.datepicker({
        	numberOfMonths: 2,
        	showButtonPanel: true,
        	dateFormat: 'dd/mm/yy',
		minDate: now
		});

	var hotelID = getParameterByName('hotelid');
	if(hotelID != null)
	{
		var dropDown = $j("select:first", "#enquiry-hotelselector");
		dropDown.val(hotelID);
	}	
	
}

function setGuestBook()
{
	var hotelID = getParameterByName('hotelid');

	if(hotelID != null)
	{
		var dropDown = $j("select:first", "#guestbook-hotelselector");
		dropDown.val(hotelID);
	}	
}



function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS,"i");
  var results = regex.exec( window.location.href );
  if( results == null )
    return null;
  else
    return results[1];
}

$j(document).ready(function() {
	var destSelect = $j('#DestinationSelection select:first');
	var destselectedIndex = destSelect.attr('selectedIndex');
	var destselectedIndexChange = 0;
	var newHtml = "";
	var associates = false;
	for(var i = 0;i < destSelect.find('option').length;i++) {
		var thisOption = destSelect.find('option:eq('+i+')');
		if(thisOption.html() == "Associate Hotels") {
			newHtml += "<optgroup label='Associate Hotels'>";
			associates = true;
			if(destselectedIndex >= i) {
				 destselectedIndexChange--;
			}
		} else {
			newHtml += "<option class='"+thisOption.attr('class')+"' value='"+thisOption.attr('value')+"' selected='"+thisOption.attr('selected')+"'>" + thisOption.html() + "</option>";
		}
		if(i + 1 >= destSelect.find('options').length && associates) {
			newHtml += "</optgroup>";
		}
	}
	destSelect.html(newHtml)
	destSelect.attr('selectedIndex', destselectedIndex + destselectedIndexChange);
	
	setHotelEnquiry();
	setGuestBook();
    $j('#book-form .calendar input').datepicker({
        numberOfMonths: 2,
        showButtonPanel: true,
        dateFormat: 'dd/mm/yy',
		firstDay: 1,
		minDate: new Date(),
        onSelect: function(dateText, inst) {
            if($j('.ui-datepicker-group:eq(0)').find('.ui-state-hover').length > 0) {
				$j("input[id*='ArrivalDate']").datepicker('option', 'showCurrentAtPos', 0);
				$j("input[id*='DepartureDate']").datepicker('option', 'showCurrentAtPos', 0);
			} else {
				$j("input[id*='ArrivalDate']").datepicker('option', 'showCurrentAtPos', 1);
				$j("input[id*='DepartureDate']").datepicker('option', 'showCurrentAtPos', 1);
			}
			var selectedDate = $j('input[id*=ArrivalDate]').datepicker('getDate');
            selectedDate.setDate(selectedDate.getDate() + 1);
			if (this.id.indexOf('ArrivalDate') != -1){ // == 'plc_lt_zoneBooking_BizForm_viewBiz_ctl00_ArrivalDate') {
                $j("input[id*='DepartureDate']").datepicker('option', 'minDate', selectedDate);
            }
            if ($j("input[id*='DepartureDate']").datepicker('getDate') < $j("input[id*='ArrivalDate']").datepicker('getDate')){
				$j("input[id*='DepartureDate']").datepicker('setDate', selectedDate);
            }
			var newDate = new Date();
			newDate.setDate(selectedDate.getDate() +5);
			if(newDate.getDate() < selectedDate.getDate()) {
				$j("input[id*='DepartureDate']").datepicker('option', 'showCurrentAtPos', 0);
			}
        }
    });
    $j('#book-form .calender:eq(0) input').datepicker('option', 'minDate', 0);
    $j('#book-form .calender:eq(1) input').datepicker('option', 'minDate', 0);
    $j('#rooms select').change(roomsChange);
    $j('.drop_body').hide();
    $j('.drop_head').click(function() {
        var sibling = $j(this).siblings('.drop_body');
        if (sibling.css('display') == 'block') {
            sibling.stop(true, true).animate({ height: 'hide' }, 'slow');
            $j(this).find('input').attr('checked', false);
        } else {
            sibling.stop(true, true).animate({ height: 'show' }, 'slow');
            $j(this).find('input').attr('checked', true);
        }
    });
	$j('.offer_detail_body').hide();
    $j('.offer_detail_head').click(function() {
        var sibling = $j(this).parents('.offerSection').find('.offer_detail_body');
        if (sibling.css('display') == 'block') {
            sibling.stop(true, true).animate({ height: 'hide' }, 'slow');
			$j(this).find('img').attr('src',$j(this).find('img').attr('src').replace("up.gif" , "down.gif"));
        } else {
            sibling.stop(true, true).animate({ height: 'show' }, 'slow');
			$j(this).find('img').attr('src',$j(this).find('img').attr('src').replace("down.gif" , "up.gif"));
        }
    });
	$j('.available_body').hide();
    $j('.available_head').click(function() {
        var sibling = $j(this).parents('.offerSection').find('.available_body');
        if (sibling.css('display') == 'block') {
            sibling.stop(true, true).animate({ height: 'hide' }, 'slow');
        } else {
            sibling.stop(true, true).animate({ height: 'show' }, 'slow');
        }
    });
    $j('.main-menu li').mouseover(function() {
        clearTimeout(menuInterval);
        menuItems = new Array();
        $j(this).siblings().removeClass("over");
        $j(this).children().removeClass("over");
        $j(this).addClass("over");
    });
    $j('.main-menu li').mouseleave(function() {
        menuItems.push($j(this));
        menuInterval = setTimeout(hideMenuItems, 500);
    });

    $j('.menu li').hover(function() {
        $j(this).find('ul:eq(0)').show();
    }, function() {
        $j(this).find('ul:eq(0)').hide();
    });
    $j('.menu-m li').hover(function() {
        $j(this).find('ul:eq(0)').show();
    }, function() {
        $j(this).find('ul:eq(0)').hide();
    });
	
	var destIdea = getParameterByName('destTitle');
	if(destIdea) {
			location.hash = $j('table td.first[innerHTML*='+unescape(destIdea)+']').parents('.tabcontent').attr('id');
	}
    $j(".tabs").tabs({ fx: { opacity: 'toggle' }, selected: 0 });
	if(destIdea) {
			var targetTab = $j('table td.first[innerHTML*='+unescape(destIdea)+']').parents('.tabcontent').attr('id');
			$j(".tablinks").find('a[href=#'+targetTab+']').click();
	}
    if ($j('.offerSearch').length > 0) {
        var hotelBox = $j("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneLeftMenu_BizForm_viewBiz_ctl00_Hotel");
        hotelBox.find('option[value=""]').html('Select a Hotel');
        var regionBox = $j("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneLeftMenu_BizForm_viewBiz_ctl00_Region");
		regionBox.change(regionChange);
        //regionBox.change(regionChange).find('option[value=""]').html('Select a Region');
		//regionBox.change(regionChange).prepend('<option value="">Select a Region</option>').attr('selectedIndex',0);
        var offerBox = $j("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneLeftMenu_BizForm_viewBiz_ctl00_OfferType");
		offerBox.change(regionChange);
        offerBox.find('option[value="/Special-Offers"]').html('All offer types');

        var sGet = window.location.search;
        if (sGet) // if has a value...
        {
            sGet = sGet.substr(1);
            var sNVPairs = sGet.split("&");
            for (var i = 0; i < sNVPairs.length; i++) {
                var sNV = sNVPairs[i].split("=");
                var sName = sNV[0];
                var sValue = unescape(sNV[1]);

                if (sName == "hotel") {
                    hotelBox.attr('selectedIndex', hotelBox.find('option:contains("' + unescape(sValue) + '")').attr('index'));
                }
                if (sName == "region") {
                    regionBox.attr('selectedIndex', regionBox.find('option:contains("' + unescape(sValue).replace('Select a Region','') + '")').attr('index'));
                    regionChange();
                }
                if (sName == "offertype") {
                    var index = 0;
                    for (i = 0; i < offerBox.attr('length'); i++) {
                        var opString = offerBox.find('option:eq(' + i + ')').attr('value');
                        if (unescape(opString) == unescape(sValue)) {
                            index = i;
                        }
                    }
                    offerBox.attr('selectedIndex', index);
                }
            }
        }
        $j('.offerSearch select').each(function() {
            selectBoxReplacement(this);
        });
    }
    $j('.hoverImage').each(function() {
        $j(this).prepend('<span><span><img src="' + $j(this).attr('href') + '" alt="" /></span></span>');
    });
    $j('.newwindow').find('a').click(function() {
        window.open($j(this).attr('href'), 'NewWindow');
        return false;
    });
	$j('a.newwindow').click(function() {
        window.open($j(this).attr('href'), 'NewWindow');
        return false;
    });
    $j('.virtualTourItem').find('a').click(function() {
        popIframe(this); return false;
    });
	var locat = location.href;
	$j('.left-side ul li').each(function()
	{
		var oldHtml = $j(this).html();
		if(locat.indexOf($j(this).find('a').attr('href')) >= 0)
		{
			this.className += " active";
		}
	});
	$j('span.popupSpanHolder a').mouseleave( function() {
		layerClose($j(this).find('.popupSpan').attr('id'));
	});
	if(document.all && !window.opera) {
		$j('#DestinationSelection').find('select').each( function() {
			$j(this).wrap('<span class="selectboxContainer" />');
			$j(this).parent().attr('forceWidth', $j(this).attr('offsetWidth'));
			$j(this).parent().css( { 'width':$j(this).attr('offsetWidth')+'px', 'height':$j(this).attr('offsetHeight')+'px', 'padding':0, 'margin':0, 'border':0, 'display':'block', 'clear':'both' });
			$j(this).css( { 'position':'absolute','width':$j(this).attr('offsetWidth')+'px'});
			$j(this).mousedown(function() { $j(this).css('width','auto') });
			$j(this).focus(function() { $j(this).css('width','auto') });
			$j(this).blur(function() { $j(this).css('width',$j(this).parent().attr('forceWidth')+'px') });
			$j(this).change(function() { $j(this).css('width',$j(this).parent().attr('forceWidth')+'px') });
		});
	}
});

function regionChange() {
    if (hotelsArray.length > 0) {
        var hotelBox = $j("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneLeftMenu_BizForm_viewBiz_ctl00_Hotel");
        var regionBox = $j("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneLeftMenu_BizForm_viewBiz_ctl00_Region");
		var offerBox = $j("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneLeftMenu_BizForm_viewBiz_ctl00_OfferType");
        var thisValue = regionBox.find('option:eq(' + regionBox.attr('selectedIndex') + ')').attr('value').replace('Select a Region','');
		if (thisValue == "") {
            hotelBox.html('<option value="">Select a Hotel</option>');
        } else {
            hotelBox.html('<option value="">All hotels in region</option>');
        }
		
		var offerValue = offerBox.attr('selectedIndex');
		
        for (var i = 0; i < hotelsArray.length; i++) {
            if ((hotelsArray[i].region == thisValue || thisValue == "") && ((hotelsArray[i].associate == "True" && offerValue < 3) || hotelsArray[i].associate == "False")) {
                hotelBox.append('<option value="' + hotelsArray[i].name + '">' + hotelsArray[i].name + '</option>');
            }
        }
        selectBoxReplacement(hotelBox);
    }
}

function selectBoxReplacement(jqSelect) {
    mySelect = $j(jqSelect);
    mySelect.hide();
    parentDiv = $j(jqSelect).parent();
    var myHTML = '';
    var selected = '';
    thisonChange = mySelect.onchange;
    mySelect.find('option').each(function() {
        var thisItem = $j(this);
        //thisItem.attr('value')
        myHTML += '<div>' + thisItem.html() + '</div>'
        if (thisItem.attr('selected') || selected == '') {
            selected = thisItem.html();
        }
    });
    myHTML = '<div class="selectBox"><div class="selected">' + selected + '</div><div class="options">' + myHTML + '</div></div>';
    parentDiv.find('.selectBox').remove();
    parentDiv.append(myHTML);
    var iereg = new RegExp('MSIE [^7-9]', 'g');
    parentDiv.find('.selected').click(function() {
        var selectWidth = $j(this).attr('offsetWidth');
        if ($j(this).siblings('.options').css('display') == 'block') {
            $j(this).siblings('.options').stop(true, true).css('width', 'auto').css('min-width', '100%').animate({ height: 'hide' }, 'slow',iewidthCheck);
            if (selectWidth > 0) {
                $j(this).siblings('.options').css('min-width', selectWidth);
            }
            if (iereg.exec(navigator.appVersion) && selectWidth <= 0) {
                $j(this).siblings('.options').css('_width', '100%');
            }

            $j('body').click(function() { })
        } else {
            $j('.bookingbox .options').hide();
            $j(this).siblings('.options').stop(true, true).css('width', 'auto').css('min-width', '100%').animate({ height: 'show' }, 'slow',iewidthCheck);
            if (selectWidth > 0) {
                $j(this).siblings('.options').css('min-width', selectWidth);
            }
            if (iereg.exec(navigator.appVersion) && selectWidth <= 0) {
                $j(this).siblings('.options').css('_width', '100%');
            }
            $j(this).siblings('.options')
            $j('body').click(function() { $j('.options').hide(); })
        }
    });
    parentDiv.find('.options').css('min-width', $j(jqSelect).parent().attr('offsetWidth') + "px").css('_width', $j(jqSelect).parent().attr('offsetWidth') + "px").find('div').hover(function() {
        $j(this).addClass("overoption");
    }, function() {
        $j(this).removeClass("overoption");
    });
    parentDiv.find('.options div').click(function() {
        var parentSection = $j(this).parents('.selectBox');
        parentSection.find('.selected').html($j(this).html());
        var mySelect = parentSection.siblings('select');
        for (var i = 0; i < mySelect.find('option').length; i++) {
            var thisOption = mySelect.find('option:eq(' + i + ')');
            if (thisOption.html() == $j(this).html()) {
                mySelect.attr('selectedIndex', i);
            }
        }
        mySelect.trigger('change');
        $j(this).parents('.options').hide();
    });
}

function iewidthCheck() {
	var iereg = new RegExp('MSIE [1-7]', 'g');
    if (iereg.exec(thisBrowser)) {
		var parentHeight = $j(this).attr('offsetHeight');
		var maxHeight = $j(this).css('max-height');
		maxHeight = maxHeight.replace('px',"");
		if(parentHeight > maxHeight) {
			$j(this).css('width', ($j(this).attr('offsetWidth') + 15) + "px");
		}
	}
}

function popIframe(link) {
    if ($j('#popupIframe').length < 1) {
        $j('body').append('<div class="hiddenDiv" id="popupIframe"></div>');
    }
    $j('#popupIframe').html('<div class="closelink"><a href="javascript:layerClose(\'popupIframe\');">Close <img src="/app_themes/akkeronhotels/interface/btn_x.gif" alt="X" /></a></div><iframe src="' + link.href + '" width="931" height="850" frameborder="0"></iframe>');
    displayCenterDiv('popupIframe');
}

var msec = 400;
var appearingDiv;
var windowHeight;
var thisBrowser = navigator.appVersion;
var centering;

function displayDiv(hiddenDiv) {
    $j('#' + hiddenDiv).hide();
    $j('#backingDiv').hide();
    var iereg = new RegExp('MSIE [^7-9]', 'g');
    if (iereg.exec(thisBrowser)) {
        document.getElementById('backingDiv').style.height = document.body.offsetHeight + "px";
    }
    else {
        document.getElementById('backingDiv').style.position = "fixed";
    }
    appearingDiv = hiddenDiv;
    $j('#backingDiv').show().css('opacity', 0);
    $j('#backingDiv').stop(true, true).animate({ opacity: .3 }, 'slow');
    $j('#' + hiddenDiv).stop(true, true).animate({ opacity: 'show' }, 'slow');
}

function quickdisplayDiv(hiddenDiv) {
    $j('#' + hiddenDiv).hide();
    $j('#backingDiv').hide();
    appearingDiv = hiddenDiv;
	
		$j('#' + hiddenDiv).stop(true, true).animate({ opacity: 'show' }, 'slow');
}


function layerClose(hiddenDiv) {
    $j('#backingDiv').stop(true, true).animate({ opacity: 'hide' }, 'slow');
    $j('#' + appearingDiv).stop(true, true).animate({ opacity: 'hide' }, 'slow');
    clearInterval(centering);
}

var movedtotop = false;

function scrollingDIV(scrollingID) {
    var currentScrollY;
    var currentDiv = document.getElementById(scrollingID)
    var currentTop = currentDiv.style.top;
    currentTop.replace(/px/, "");
    currentTop = parseInt(currentTop);
    var currentLeft = currentDiv.style.left;
    currentLeft.replace(/px/, "");
    currentLeft = parseInt(currentLeft);
    var currentDivHeight = currentDiv.offsetHeight;
    var currentDivWidth = currentDiv.offsetWidth;
    var currentHeight;
    var currentWidth;
    if (typeof window.innerWidth != 'undefined') {
        currentWidth = window.innerWidth,
		currentHeight = window.innerHeight
    }
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        currentWidth = document.documentElement.clientWidth,
		currentHeight = document.documentElement.clientHeight
    }
    else {
        currentWidth = document.getElementsByTagName('body')[0].clientWidth,
		currentHeight = document.getElementsByTagName('body')[0].clientHeight
    }
    var centerY = (currentHeight - currentDivHeight) / 2;
    var centerX = (currentWidth - currentDivWidth) / 2;

    if (typeof (window.pageYOffset) == "undefined") {
        currentScrollY = document.documentElement.scrollTop;
        currentScrollX = document.documentElement.scrollLeft;
    }
    else {
        currentScrollY = window.pageYOffset;
        currentScrollX = window.pageXOffset;
    }

    centerX += currentScrollX;
    centerY += currentScrollY;

    if (isNaN(currentTop)) {
        currentDiv.style.top = centerY + "px";
        currentTop = centerY;
        currentDiv.style.marginTop = "0px";
    }
    else {
        var nextStep = (centerY - currentTop) / 2;
        if (!isNaN(nextStep) && centerY != currentTop && currentHeight > currentDiv.offsetHeight) {
            if (nextStep > 3 || nextStep < -3) {
                currentDiv.style.top = currentTop + nextStep + "px";
            }
            else {
                currentDiv.style.top = centerY + "px";
            }
            movedtotop = false;
        }
        else if (currentHeight < currentDiv.offsetHeight) {
            if (!movedtotop) {
                currentDiv.style.top = currentScrollY + "px";
                movedtotop = true;
            }
        }
    }
    if (isNaN(currentLeft)) {
        currentDiv.style.left = centerX + "px";
        currentLeft = centerX;
        currentDiv.style.marginLeft = "0px";
    }
    else {
        var nextStep = (centerX - currentLeft) / 2;
        if (!isNaN(nextStep) && centerX != currentLeft && currentWidth > currentDiv.offsetWidth) {
            if (nextStep > 3 || nextStep < -3) {
                currentDiv.style.left = currentLeft + nextStep + "px";
            }
            else {
                currentDiv.style.left = centerX + "px";
            }
        }
    }
}

function displayCenterDiv(hiddenDiv) {
    var scrollingDiv = document.getElementById(hiddenDiv);
    scrollingDiv.style.marginTop = "0px";
    scrollingDiv.style.marginLeft = "0px";
    centering = setInterval("scrollingDIV('" + hiddenDiv + "')", 100);
    displayDiv(hiddenDiv);
}

document.write('<style type="text/css">.popupSpanHolder a:hover span.popupSpan { display:none; }</style>');

function popupSection(linked, displaySection) {
	var myPosition = $j(linked).position();
	if($j('#'+displaySection).css('display') == "none") {
		$j('#'+displaySection).css('top',myPosition.top + "px");
		$j('#'+displaySection).css('left',myPosition.left + "px");
		quickdisplayDiv(displaySection);
	}
}