addEvent(window, "load", addPriceExampleEvents, false);
var isClicked;
/* Used by the Table Builder property to enable tab navigation. Called from ContentBlock "/BlueSites/Templates/ContentBlocks/DynamicTable.ascx" */
function addEventsForInnerTabNavigation() {
    $("div.inner-sub-tab-navigation").each(function() {
        $(this).find("li").each(function(j) {
            $(this).attr("tabnavindex", "tabnavindex-" + j).click
            (
                function() {
                    var 
                        $this = $(this),
                	    $tables = $this.parent().parent().find('table'),
	                    intTabIndex = this.getAttribute("tabnavindex").replace(/tabnavindex-/, "");

                    $this.parent().find('li').removeAttr('class');
                    $this.addClass('selected');

                    if (intTabIndex === 0) {
                        $this.addClass('first-tab-selected');
                    }

                    $tables.attr('class', 'dynamic-table display-none');
                    $tables.eq(parseInt(intTabIndex)).attr('class', 'dynamic-table display-table');
                }
            );
        });
    });
}
/* Print the panel on Blue concept pages. Called from ContentBlock "/BlueSites/Templates/ContentBlocks/ExpandablePanel.ascx"
* and "hosturl/Xslt/BlueSites/City.xslt". */
function addPrintExpandBlock(){
    
	$(".print-expand-panel-JS").click(function (){	
			openElementAndPrint(this.parentNode);
	});
	$(".open-expand-panel-JS").click(function () {	
			openElementAndPrint(this.parentNode, null, true);
	});
}

var oDropDown = null;
var oDropDownToFill = null;
function addDynamicDropDownEvents(oParentElem){
	oParentElem = (oParentElem) ? oParentElem : document;
	var arrAllDynamicDropDowns = getElementsByClassName(oParentElem, "select", "dynamic-dropdown");
	for (var i=0; i<arrAllDynamicDropDowns.length; i++){
	    arrAllDynamicDropDowns[i].onchange = function() {
	        var strClassName = this.className;
	        var strType = strClassName.replace(/.*type-(\w+)(\b.*|$)/i, "$1");
	        var strDat = strClassName.replace(/.*dat-(\w+)(\b.*|$)/i, "$1");
	        var strId = this.options.selectedIndex != '-1' ? this.options[this.options.selectedIndex].value : '';
	        var oSelectedBookingType = document.getElementById("selected-booking-type");
	        var oHidden = document.getElementById(this.id + "-hidden");
	        if (oHidden) {
	            oHidden.value = strId;
	        }

	        if (strId !== null && strId.length > 0) {
	            var 
	                depCode,
	                strURL;

	            if (strType == 'resort') {
	                //Depcodes always in first dropdown
	                depCode = arrAllDynamicDropDowns[0].value;
	                strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?type=" + strType + "&id=" + strId + "&dep=" + depCode;
	            }
	            else if (strType == 'resortStart') {
	                depCode = arrAllDynamicDropDowns[0].value;
	                strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?strBookingType=" + oSelectedBookingType.value + "&type=" + strType + "&id=" + strId + "&dep=" + depCode;
	            }
	            else if (strType == 'cat_entry') {
	                strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?type=" + strType + "&id=" + strId;
	            }
	            else if (strType == 'cat_resort' || strType == 'cat_hotel') {
	                strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?type=" + strType + "&id=" + strId;
	            }
	            else {
	                strURL = "/BlueSites/Templates/DynamicContent/GetDropDownItems.aspx?strBookingType=" + oSelectedBookingType.value + "&type=" + strType + "&id=" + strId;
	                //Save in global variable
	                oDropDown = this;
	                var sec = getElementsByClassName(document, "select", "element-to-fill-return-date");
	                if (sec !== null && sec.length > 0 && strClassName.indexOf("element-to-fill-return-date") == -1) {
	                    setTimeout("SetSec()", 100);
	                }
	            }
	            var strIdOfElementToFill = strClassName.replace(/.*element-to-fill-([\w\d\-]+)(\b.*|$)/i, "$1");
	            getJavaScriptArrayWithIdentifier(strIdOfElementToFill, strURL, "fillDropDownWithIdentifier");

	            var stringToSave = document.getElementById("postbackXml");
	            if (stringToSave) {
	                var PickedTd = document.getElementById("PickedTd");
	                var array = this.options[this.options.selectedIndex].value.split("_");
	                var destinationName = this.options[this.options.selectedIndex].text.replace("-", "");

	                if (destinationName.indexOf(" ") === 0) {
	                    destinationName = destinationName.substring(1, destinationName.length);
	                }

	                stringToSave.value = array[1] + "|" + destinationName;
	                PickedTd.innerHTML = destinationName;
	            }
	        }
	    };
		arrAllDynamicDropDowns[i].onkeyup = arrAllDynamicDropDowns[i].onchange;
	}
}
function GetDaysInMonth(month, year) {
    var selMonth = parseInt(month, 10);
    var dayArray = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    var days = dayArray[selMonth]
    if (selMonth == 2 && ((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0))
        days = 29;

    return days;
}
function SetSec(){
	var strDateForward = 4;
	var	sec = getElementsByClassName(document, "select", "element-to-fill-return-date");		
	
	if(sec !== null && sec.length > 0){
		//oDropDown is set in onChange function
		sec[0].value = oDropDown.options[oDropDown.options.selectedIndex].value;
		sec.onChange;
		//get control to update
		var srcDepDays = document.getElementById('departure-date');
		//get control to update
		var srcArrDays = document.getElementById('return-date');
		var year = oDropDown.options[oDropDown.options.selectedIndex].value.substring (0,4);
		var month = oDropDown.options[oDropDown.options.selectedIndex].value.substring (5,7);
		var daysInMonth = GetDaysInMonth (month, year);
		var nextIdx = parseInt(srcDepDays.value) + strDateForward;
		if (nextIdx > daysInMonth)	{
			// set new value in month
			sec[0].selectedIndex++;

			if (sec[0].onChange) {
			    sec[0].onChange();
			}
			
			//get no of days in new month
			var month = sec[0].value.substring (5,7);
			var daysInMonth2 = GetDaysInMonth (month, year);
			// returnDay must be reloades with days in month for new month
			// first "empty" the control
			for (var i = (srcArrDays.options.length-1); i >= 0; i--){
				srcArrDays.options[i]=null;
			}
			// fill control with new values
			//then fill returnMonth with values
			for (var j = 1 ; j<=daysInMonth2; j++){
				srcArrDays.options[j-1]=new Option (j, j);
			}
			// calculate new index
			var stepForward = nextIdx - daysInMonth;// - srcDepDays.value);
			// set new index in returnDay							
			srcArrDays.value = stepForward;
		}
		else{
			//set next index
			srcArrDays.value = nextIdx;
		}
	}
}
function fillDropDownWithIdentifier(strId, arrOptions){
	if(arrOptions !== null){
	    var oDropDownToFill = document.getElementById(strId);
		if (oDropDownToFill) {
			var selectedOption = oDropDownToFill.value;
			var oHidden = document.getElementById(oDropDownToFill.id + "-hidden");
			if (oHidden) {
			    selectedOption = oHidden.value;
			}

			var oOption;
			var arrayOption;
			oDropDownToFill.options.length = 0;
			
			for(var j=0; j<arrOptions.length; j++){
				arrayOption = arrOptions[j];
				if( arrayOption !== null ) {
					oDropDownToFill.options.length++;
					oDropDownToFill.options[j].value = arrayOption.value;
					oDropDownToFill.options[j].text = arrayOption.text;
					if (arrayOption.value == selectedOption) {
					    oDropDownToFill.options[j].selected = true;
					}
				}
			}			
			oDropDownToFill.onchange();
		}
	}
}
/** addQuickPoll - Loads Quick-Poll In Div Note. Calls addQuickPollInner() via the Ajax-load function getXML */
function addQuickPoll (){
	var oPollDiv = document.getElementById("divPollContent-isFunctionPointer");
	if (oPollDiv){
		var toGetFrom = oPollDiv.getAttribute ("src");
		getXML (toGetFrom, oPollDiv, addQuickPollInner);
	}
}
/* findVoteItem - tries to find a selected input tags with value "PollAltValue__XX" (XX is int) returns XX if found returns null otherwise */
function findVoteItem(){
	var options = new Array();
	var options = document.getElementsByTagName("input");
	for (var i = 0; i < options.length; i++){
		if (options[i].type && options[i].type=="radio"){
			var option = options[i];
			var value = option.value;
			var rexfindPollAlt = /^PollAltValue__/;
			
			if (value.match (rexfindPollAlt)){
			    if (option.checked) {
			        return String(option.value).replace(/PollAltValue__/, "");
			    }
			}
		}
	}
}
/** addQuickPollInner add events to inner content of loaded quick poll dev	called from addQuickPoll()*/
function addQuickPollInner (){
	var oPollDiv = document.getElementById("divPollContent-isFunctionPointer");
	var oPollSubmitButton = document.getElementById("quickpoll-vote-button-isFunctionPointer");
	if (oPollSubmitButton && oPollDiv){
		oPollSubmitButton.onclick = function () {
			var selectedItem = findVoteItem();
			if (selectedItem){
				var toGetFrom = oPollDiv.getAttribute ("src");
				toGetFrom += "&vote=" + selectedItem;
				getXML (toGetFrom, oPollDiv, addQuickPollInner);
			}
			return false;
		}
	}	
	var oPollSwitchViewLink = document.getElementById("quickpoll-swith-view-link-isFunctionPointer");
	if (oPollSwitchViewLink && oPollDiv){
		oPollSwitchViewLink.onclick = function () {
			var toGetFrom = oPollDiv.getAttribute ("src");
			toGetFrom += "&pollact=switch";
			getXML (toGetFrom, oPollDiv, addQuickPollInner);
			return false;
		}
	}
	var oPollHideLink = document.getElementById ("quickpoll-hide-poll-isFunctionPointer");
	if (oPollHideLink){
		var hdnIdHolder = document.getElementById ("hdnPollId");
		var pollCookieId = "quickpoll-hide-poll-isFunctionPointer-pollHidden" + hdnIdHolder.getAttribute ("value");

		oPollHideLink.onclick = function() {
		    setCookie(pollCookieId, true, 100); // Set hide-cookie and hide poll
		    oPollDiv.className = 'display-none';
		    return false;
		}
	}
}
/*** getCookie - returns cookie value for named cookie
  * @param c_name - cookie name
  */
function getCookie(c_name){
	if (document.cookie.length>0){
	    var c_start = document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
		    c_start = c_start + c_name.length + 1;
			var c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) {
			    c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return null;
}
/*** setCookie - sets cookie value
 * @param c_name		- cookie name
 * @param value			- value for cookie
 * @param expiredays	- days to live for cookie (optional, default = 30days)
  */
function setCookie(c_name, value, expiredays){
    if (!expiredays) {
        expiredays = 30;
    }
	var exdate = new Date();
	exdate.setDate (exdate.getDate() + expiredays);
	document.cookie= c_name + "=" + escape(value) + ";expires=" + exdate;
}

/* Site Feedback*/
function ShowAnotherPageForm(display){
	var AnotherPageDiv = document.getElementById('AnotherPage');	
	AnotherPageDiv.className = display;
}
function printPageAndSubPages(){
	$("a#page-print-button").click(function(){	
		openElementAndPrint(this.parentNode);		
		return;
	});
}

function addPriceExampleEvents(){
	var arrAllPriceExamples = getElementsByClassName(document, "a", "price-example-link");
		for(var j=0; j<arrAllPriceExamples.length; j++){
			arrAllPriceExamples[j].onclick = function (oEvent){
				var oEvent = (typeof oEvent != "undefined")? oEvent : event;
				displayPriceExampleInfo(oEvent, this);
			};
		}
}
function displayPriceExampleInfo(oEvent, oElm){
	var intHotelId = oElm.getAttribute("id").replace(/price-example-/g, "");
	var strId = "price-example-details-" + intHotelId;
	var oPriceExampleInfo = document.getElementById("price-example-details-" + intHotelId);
	if(oPriceExampleInfo){
		oEvent.returnValue = false;
		if(oEvent.preventDefault){
			oEvent.preventDefault();
		}
		var bShow = (oPriceExampleInfo.className.search(/display-block/) == -1)? true : false;
		oPriceExampleInfo.className = "price-example-details " + ((bShow)? "display-block" : "display-none");			
	}
	var srcElement = oEvent.target ? oEvent.target : oEvent.srcElement;
	var bSelected = (srcElement.className.search(/selected/) != -1)? true : false;
	if (bSelected) {
	    srcElement.className = srcElement.className.replace("selected", "");
	}
	else {
	    srcElement.className = srcElement.className + " selected";
	}
}
function addRedirectDropDownPusher(){
	$("select.drop-down-pusher").change(function(){			
		var val = this.value;				
		var url = val.split(",");	
		if(this.selectedIndex !== 0) {	
			if(url[1] == "_blank"){				
				window.open(url[0]);
			}
			else{		
				location.href = url[0];
			}
		}
		return false;
   });      
}
$(document).ready(function() {
    $("a.expand-panel-list-JS2").click(function() {

        var containerDiv = $("#box_container_" + $(this).attr("id").replace("expand_listItem_", ""));

        if ($(containerDiv).hasClass("display-block")) {
            $(containerDiv).removeClass("display-block").addClass("display-none");
        }
        else {
            $(containerDiv).removeClass("display-none").addClass("display-block");
        }

        if ($(this).hasClass("selected")) {
            $(this).removeClass("selected");
        }
        else {
            $(this).addClass("selected");
        }

        return false;
    });
    $("a.close-expand-JS").click(function() {
        var currentId = $(this).attr("id").replace("expand_close_", "");
        $("#box_container_" + currentId).removeClass("display-block").addClass("display-none");
        $("#expand_listItem_" + currentId).removeClass("selected");
    });


    $("#add-hotel-container #select-catalogue,#add-hotel-container #select-entry,#add-hotel-container #select-resort,#add-hotel-container #select-hotel").change(function() {
        if ($(this).val() == "0") {
            return false;
        }

        var 
            array = $(this).val().split('|'),
            inputData = "{catalogueId: " + $(this).val() + "}",
            url = "/BlueSites/Templates/AjaxHandlers/GetJson.asmx/GetEntries",
            $nextList = $("#select-entry"),
            $submitButton = $("#btnAddHotel");

        $submitButton.attr("disabled", "disabled").attr("src", $submitButton.attr("src").replace("add.gif", "add-disabled.gif"));

        switch ($(this).attr("id")) {
            case "select-entry":
                inputData = "{catalogueId: " + array[0] + ", entryId : " + array[1] + ", entryName: '" + array[2] + "'}";
                url = "/BlueSites/Templates/AjaxHandlers/GetJson.asmx/GetResorts";
                $nextList = $("#select-resort");
                $("#select-resort, #select-hotel").empty();
                break;
            case "select-resort":
                inputData = "{catalogueId: " + array[0] + ", cityId : " + array[2] + ", enokType: '" + array[1] + "'}";
                url = "/BlueSites/Templates/AjaxHandlers/GetJson.asmx/GetHotels";
                $nextList = $("#select-hotel");
                break;
            case "select-hotel":
                $submitButton.removeAttr("disabled").attr("src", $submitButton.attr("src").replace("-disabled", ""));
                return;
            default:
                $("#select-entry, #select-resort, #select-hotel").empty();
                break;
        }

        $.ajax({
            type: "POST",
            url: url,
            data: inputData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data) {
                var jsonItems = (typeof data.d) == 'string' ? eval('(' + data.d + ')') : data.d;
                $nextList.empty();
                for (var i = 0, il = jsonItems.Items.length; i < il; i++) {
                    $($nextList).append(
                        $("<option></option>").val(jsonItems.Items[i].Value).html(jsonItems.Items[i].Text)
                    );
                }
            }
        });
    });

    $('#hotel-menu a[href*=#], .our-hotels a[href*=#]').click(function() {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
               && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');

            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({ scrollTop: targetOffset }, 1000);
                return false;
            }
        }
    });


    $("div.new-price-container").find("a.lms-price-link").click(function() {
        window.location = $(this).attr("rel");
        return false;
    });

    $('.concept-listning li').click(function() {
        window.location = $(this).find('a:first').attr('href');
    });


    hotelListHelper = new HotelListHelper($("#hotel-list-container"));

    var videoContainer = $("#video-player-container");

    if (videoContainer.length !== 0) {
        videoContainer.load("/BlueSites/Templates/DynamicContent/Media/EmbedCode.aspx?epiId=" + hotelListHelper.EpiId);
    }

    // TODO: kanske ladda lite bättre
    hotelListHelper.Holder.find("#hotel-container").load(hotelListHelper.RequestUrl($("#first-available-catalogue").val(), hotelListHelper.HotelType, 0, 'resort') + "&page=0", function() {
        hotelListHelper.BuildPaging();
    });
    hotelListHelper.Holder.find('input:radio[name=radio-season-selector]').change(function() {

        var countryId = $("#country-selector").val();
        $.ajax({
            type: "POST",
            url: "/BlueSites/Templates/AjaxHandlers/GetJson.asmx/GetValidEntriesForHotelType",
            data: "{type: '" + $("#hotel-type-hidden").val() + "', cat: " + $(this).val() + ", epiId: " + hotelListHelper.EpiId + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data) {
                var jsonItems = (typeof data.d) == 'string' ? eval('(' + data.d + ')') : data.d;
                // TODO Sätta tillbaka det valda landet
                hotelListHelper.Holder.find("#country-selector").empty().append($("<option></option>").val("0").text(strAllCountries));
                for (var i = 0, il = jsonItems.Items.length; i < il; i++) {
                    hotelListHelper.Holder.find("#country-selector").append($("<option></option>").val(jsonItems.Items[i].Value).html(jsonItems.Items[i].Text));
                }
                hotelListHelper.Holder.find("#country-selector").val(countryId);
            }
        });

        hotelListHelper.Holder.find("#hotel-container").html(hotelListHelper.AjaxLoaderImage);
        var 
            season = $(this).val(),
            sortOrder = hotelListHelper.Holder.find('#sorting-selector').val();

        hotelListHelper.Holder.find("#hotel-container").load(hotelListHelper.RequestUrl(season, hotelListHelper.HotelType, countryId, sortOrder), function() {
            hotelListHelper.BuildPaging();
        });
    });

    hotelListHelper.Holder.find('#country-selector').change(function() {
        hotelListHelper.Holder.find("#hotel-container").html(hotelListHelper.AjaxLoaderImage);
        var 
            season = $('input:radio[name=radio-season-selector]:checked').val(),
            countryId = $(this).val(),
            sortOrder = hotelListHelper.Holder.find('#sorting-selector').val();

        hotelListHelper.Holder.find("#hotel-container").load(hotelListHelper.RequestUrl(season, hotelListHelper.HotelType, countryId, sortOrder), function() {
            hotelListHelper.Holder.find("#select-season").find("input").removeAttr("disabled");
            hotelListHelper.Holder.find("#select-season").find("label").removeClass("not-valid");

            var seasonsToHide = $(".season-to-hide").val().split(',');
            for (i = 0; i < seasonsToHide.length; i++) {
                hotelListHelper.Holder.find("#select-season").find("#value-" + seasonsToHide[i]).attr("disabled", "disabled").parents().filter("label").addClass("not-valid");
            }
            hotelListHelper.BuildPaging();
        });
    });

    hotelListHelper.Holder.find('#sorting-selector').change(function() {
        hotelListHelper.Holder.find("#hotel-container").html(hotelListHelper.AjaxLoaderImage);
        var 
            season = $('input:radio[name=radio-season-selector]:checked').val(),
            countryId = $("#country-selector").val(),
            sortOrder = hotelListHelper.Holder.find('#sorting-selector').val();

        hotelListHelper.Holder.find("#hotel-container").load(hotelListHelper.RequestUrl(season, hotelListHelper.HotelType, countryId, sortOrder), function() {
            hotelListHelper.SortOrder = $('#sorting-selector').val();
            hotelListHelper.BuildPaging();
        });
    });

    hotelListHelper.Holder.find('.paging-links-ajax a, .paging-results-ajax a.previous-page, .paging-results-ajax a.next-page').live('click', function() {
        var 
            season = $('input:radio[name=radio-season-selector]:checked').val(),
            countryId = $("#country-selector").val(),
            page = $(this).attr("rel"),
            currentSelectedLink = hotelListHelper.Holder.find('a.selected'),
            firstItemText = hotelListHelper.Holder.find('#top-paging a:first').text(),
            lastItemText = hotelListHelper.Holder.find('#top-paging a:last').text(),
            sortOrder = hotelListHelper.Holder.find('#sorting-selector').val();

        if ($(this).hasClass('next-page')) {
            page = parseInt(currentSelectedLink.attr('rel'), 10) + 10;
            $('.previous-page').show();
        }
        else if ($(this).hasClass('previous-page')) {
            page = parseInt(currentSelectedLink.attr('rel'), 10) - 10;
            $('.next-page').show();
        }

        hotelListHelper.Holder.find("#hotel-container").html(hotelListHelper.AjaxLoaderImage);

        hotelListHelper.Holder.find("#hotel-container").load(hotelListHelper.RequestUrl(season, hotelListHelper.HotelType, countryId, sortOrder) + "&page=" + page);
        hotelListHelper.Holder.find('.paging-links-ajax a').removeClass("selected");

        if ($(this).hasClass('next-page')) {
            hotelListHelper.Holder.find('[rel=' + page + ']').addClass('selected');
            if ($('#top-paging').find('[rel=' + page + ']').text() === lastItemText) {
                $('.next-page').hide();
            }
        }
        else if ($(this).hasClass('previous-page')) {
            hotelListHelper.Holder.find('[rel=' + page + ']').addClass('selected');
            if ($('#top-paging').find('[rel=' + page + ']').text() === firstItemText) {
                $('.previous-page').hide();
            }
        }
        else {
            hotelListHelper.Holder.find('[rel=' + page + ']').addClass('selected');
            if ($('#top-paging').find('[rel=' + page + ']').text() === firstItemText) {
                $('.previous-page').hide();
                $('.next-page').show();
            }
            else if ($('#top-paging').find('[rel=' + page + ']').text() === lastItemText) {
                $('.next-page').hide();
                $('.previous-page').show();
            }
            else {
                $('.next-page').show();
                $('.previous-page').show();
            }
        }
    });

    $("a.images,a.map,a.video, a.open-movie, a.open-images").live('click', function(event) {
        event.preventDefault();

        var 
            showLarge = (screen.height > hotelListHelper.LargeScreenSize),
            dialogClass = (showLarge) ? "div.media-large" : "div.media-medium",
            type = $(this).attr("class"),
            hotelId = $(this).attr("rel"),
            catalouge = $('input:radio[name=radio-season-selector]:checked').val(),
            queryString = "?hotel=" + hotelId + "&cat=" + catalouge + "&type=" + type + "&showLarge=" + showLarge;

        if ($(this).hasClass("open-movie")) {
            queryString = "?epiid=" + $(this).attr("rel") + "&showLarge=" + 'true' + "&type=" + type;
            dialogClass = "div.media-large";
        }

        var mapsUrl = "/BlueSites/Templates/DynamicContent/Media/MediaViewer.aspx" + queryString;
        var dialogControl = TUI.Web.UI.WebControls.Dialog.createNewGlobalDialog({ 'innerHtmlCenter': '<iframe frameborder="0" style="overflow: hidden;" scrolling="no" allowTransparency="true" backgroundColor="transparent" src="' + mapsUrl + '"></iframe>', 'showOverlay': false, 'isDraggable': true }, dialogClass.replace('div.', ''));
        $("div#light-box").css("height", $(document).height() + 100 + "px").show();
        $(dialogClass).css({ zIndex: "100", position: "absolute" }).find("a.dialog-top-close-link").click(function() {
            $(dialogClass).remove();
            $("div#light-box").hide();
        });
        dialogControl.show();

        return false;
    });

});

this.imagePreview = function() {
    xOffset = 150;
    yOffset = 30;

    xConceptOffset = 70;
    yConceptOffset = 30;

    $("a.lms-img-preview").click(function() {
        document.location.href = $(this).parent().find("div a").attr("href");
        return false;
    });

    $("a.lms-img-preview").hover(function(e) {
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br />" + this.t : "";
        $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' /><span id='img-title'>" + c + "</span></p>");
        $("#preview")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function() {
	    this.title = this.t;
	    $("#preview").remove();
	});
    $("a.lms-img-preview").mousemove(function(e) {
        $("#preview")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px");
    });

    $("#hotel-menu a").hoverIntent(function(e) {
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br />" + this.t : "";
        var pageId = this.rel;

        if (!pageId) {
            return false;
        }

        $("body").append("<div id='preview' class='concept-label-preview'></div>");
        $('#preview').load('/BlueSites/Templates/DynamicContent/ConceptAndLabels.aspx?epiid=' + pageId + ' #epi-content');
        $("#preview")
			.css("top", (e.pageY - xConceptOffset) + "px")
			.css("left", (e.pageX + yConceptOffset) + "px")
			.delay(500)
			.fadeIn("fast");
    },
    function() {
        this.title = this.t;
        $("#preview").remove();
    });
    $("#hotel-menu a").mousemove(function(e) {
        $("#preview")
			.css("top", (e.pageY - xConceptOffset) + "px")
			.css("left", (e.pageX + yConceptOffset) + "px");
    });
};

this.setSeasonSelectorWidth = function() {
    var totalWidth = 0;
    $(".concept-and-labels #select-season label").each(function(index) {
        totalWidth += $(this).width();
    });
    $(".concept-and-labels #select-season").find(".season-labels").eq(0).width(totalWidth);
}

$(document).ready(function() {
    imagePreview();
    //IE7 fix, set a fixed width for the season-labels div
    if (jQuery.browser.msie && jQuery.browser.version == 7) {
        setSeasonSelectorWidth();
    }
});

// TODO: Fixa obaseSettings så det funkar
var tempInc = "/includes";
HotelListHelper = function(oParent) {
    this.Holder = oParent;
    //this.AjaxLoaderImage = "<img src=\"" + oBaseAppSettings.IncludeSiteDirectory + "/Images/Layout/HotelItem/icon-load-66x66.gif\"' id=\"hotel-loader-icon\" />";
    this.AjaxLoaderImage = "<img src=\"" + tempInc + "/Images/Layout/HotelItem/icon-load-66x66.gif\"' id=\"hotel-loader-icon\" />";
    this.LargeScreenSize = 899;
    this.HotelType = $('#hotel-type-hidden').val();
    this.NumOfPages = parseInt($('.nr-of-pages').val(), 10);
    this.EpiId = $('#epi-id').val();    
    this.RequestUrl = function(season, hotelType, countryId, sortOrder) {
        return "/BlueSites/Templates/DynamicContent/ConceptAndLabelsHotelList.aspx?cat=" + season + "&type=" + hotelType + "&entry=" + countryId + "&epiId=" + this.EpiId + "&searchFilter=" + sortOrder;
    };
    this.BuildPaging = function() {
        var 
            listItems = "",
            relNum = 10,
            numOfPages = $(".nr-of-pages").val();

        if (numOfPages < 2) {
            $(".paging-results-ajax").hide();
            return;
        }
        else {
            $(".paging-results-ajax").show().find("ul").html("");
            $('.next-page').show();
        }

        for (i = 0; i < numOfPages; i++) {
            if (i === 0) {
                listItems = listItems + '<li class="first"><a href="javascript:void(0);" rel="0">1</a></li>';
            }
            else {
                listItems = listItems + String.format('<li><a href="javascript:void(0);" rel="{0}">{1}</a></li>', relNum, (i + 1));
                relNum = relNum + 10;
            }
        }
        $(".paging-links-ajax").append(listItems);
        hotelListHelper.Holder.find('.paging-links-ajax a:first').addClass("selected");
    };
};