cms.RootPath = '';
/* WebFilter 0x10100064000000E0 */
if ($.browser.msie) {
	try { document.execCommand("BackgroundImageCache", false, true); }
	catch(e) { }
}
local.bannerIdx = 0;
local.bannerLock = false;

local.StartBanner = function() {
	var bm = $('#banner-img-main');
	$('#banner-img-parent').css('background','url(\'' + bm.attr('src') + '\') top left no-repeat');
	bm.load(local.NextBannerComplete);
	local.NextBanner();
}
local.nbNext = 0;
local.nbDefer = 0;
local.NextBanner = function() {
	if(local.bannerLock == true) {
		if (local.nbDefer == 0) local.nbDefer = setTimeout(local.NextBanner,5000);
	} else {
		if (local.nbDefer != 0) clearTimeout(local.nbDefer);
		local.nbDefer = 0;
		local.nbNext = 0;
		var oldIdx = local.bannerIdx;
		local.bannerIdx++;
		if (local.bannerIdx > 4) local.bannerIdx = 0;
		$('#banner-button-master').animate({backgroundColor: local.bannerList[local.bannerIdx].colour},1000);
		var ta = $('#banner-button-' + local.bannerIdx );
		ta.find('img').stop().animate({opacity: 1},1000,null,function(){ta.addClass('active');});
		var tb = $('#banner-button-' + oldIdx);
		tb.find('img').stop().animate({opacity: 0},1000,null,function(){tb.removeClass('active');});
		var bm = $('#banner-img-main');
		bm.stop().animate({opacity:0},0).attr('src','/f.ashx?i=' + local.bannerList[local.bannerIdx].banner);
	}
}
local.nbcDefer = 0;
local.NextBannerComplete = function() {
	if(local.bannerLock == true) {
		if (local.nbcDefer == 0) local.nbcDefer = setTimeout(local.NextBannerComplete,2500);
	} else {
		if (local.nbcDefer != 0) clearTimeout(local.nbcDefer);
		local.nbcDefer = 0;
		if (local.nbNext != 0) clearTimeout(local.nbNext);
		local.nbNext = setTimeout(local.NextBanner,5000);
		var bm = $('#banner-img-main');
		bm.stop().animate({opacity:1},500,null,function(){
			$('#banner-img-parent').css('background','url(\'' + bm.attr('src') + '\') top left no-repeat');
		});
	}
}
local.LastForceId = -1;
local.ForceSetBanner = function(forceId) {
	local.LastForceId = forceId;
	setTimeout(function() {
		if (local.bannerLock == true && local.LastForceId == forceId) {
			var oldIdx = local.bannerIdx;
			if (forceId != oldIdx) {
				local.bannerIdx = forceId;
				$('#banner-button-master').css('background-color',local.bannerList[local.bannerIdx].colour);
				var ta = $('#banner-button-' + local.bannerIdx );
				ta.find('img').stop().animate({opacity: 1},0,null,function(){ta.addClass('active');});
				var tb = $('#banner-button-' + oldIdx);
				tb.find('img').stop().animate({opacity: 0},0,null,function(){tb.removeClass('active');});
				var bm = $('#banner-img-main');
				bm.stop().animate({opacity:1},0).attr('src','/f.ashx?i=' + local.bannerList[local.bannerIdx].banner);
			}
		}
	}, 100);
}
/* WebFilter 0x10100064000000E7 */
local.SlideshowIndex = -1;
local.SlideshowCurrent = null;
local.SlideshowData = null;
local.SlideshowTimeout = -1;
local.SlideshowPaused = false;
local.PauseSlideshow = function() {
	local.SlideshowPaused = true;
	$('.gallery-slideshow-state .play').removeClass('active');
	$('.gallery-slideshow-state .pause').addClass('active');
	return false;
}
local.UnpauseSlideshow = function() {
	local.SlideshowPaused = false;
	$('.gallery-slideshow-state .pause').removeClass('active');
	$('.gallery-slideshow-state .play').addClass('active');
	return false;
}
local.SlideshowExecute = function(data) {
	if (local.SlideshowPaused == true) {
		clearTimeout(local.SlideshowTimeout);
		local.SlideshowTimeout = setTimeout(function(){local.SlideshowExecute(data);},2500);
	} else {
		local.UnpauseSlideshow();
		if (local.SlideshowIndex == -1) local.SlideshowPrepare(data);
		local.SlideshowChangeTo(local.SlideshowIndex + 1,data);
	}
}
local.SlideshowPrepare = function(data) {
	local.SlideshowData = data;
	$('#gallery-slideshow-img-standby').load(local.SlideshowStandbyLoad);
	$('#gallery-slideshow-img-main').load(local.SlideshowStandbyReset);
	for(var i=0; i < data.length; i++) {
		if (parseInt(data[i].ss_id) == local.SlideshowStartId) {
			local.SlideshowIndex = i;
		}
		if (data[i].ss_id > 0) {
			data[i].cacheImg = new Image();
			data[i].cacheImg.src = '/f.ashx?v=' + parseInt(data[i].img_tgt,10);
		}
	}
}
local.SlideshowChangeTo = function(newIdx,data) {
	if (local.SlideshowIndex == -1) local.SlideshowPrepare(data);
	clearTimeout(local.SlideshowTimeout);
	var oldIdx = local.SlideshowIndex;
	local.SlideshowIndex = newIdx;
	if (local.SlideshowIndex >= data.length - 1) local.SlideshowIndex = 0;
	if (local.SlideshowIndex < 0) local.SlideshowIndex = data.length - 2;

	var t = data[local.SlideshowIndex];
	local.SlideshowCurrent = t;
	$('#gallery-slideshow-img-standby').attr('src',t.cacheImg.src);
}
local.SlideshowStandbyReset = function() {
	$('#gallery-slideshow-img-standby').parent().css('top','-20000px');
}
local.SlideshowStandbyLoad = function() {
	var t = local.SlideshowCurrent;
	if (t == null) return;

	var wrap = $('#gallery-slideshow-wrap');
	var standby = $('#gallery-slideshow-img-standby');
	var main = $('#gallery-slideshow-img-main');

	standby.css('opacity',0).parent().css('top','0');

	standby.animate({opacity: 1},500);
	wrap.animate({height: standby.height()}, 500, function() {
		main.attr('src',standby.attr('src'));
	});

	$('#gallery-slideshow-title').text(t.title);

	var cap = $('#gallery-slideshow-caption');
	var sbCap = $('#gallery-slideshow-caption-standby');
	sbCap.text(t.caption);
	if (t.caption == '' || t.caption == null) {
		cap.parent().animate({height: 0},500,function() { cap.text(''); cap.parent().css('display','none'); });
	} else {
		cap.parent().css('display','block').animate({height: sbCap.parent().height()},500,function() { cap.text(t.caption); });
	}

	local.SlideshowActivateThumbnail(t.ss_id);
	local.SlideshowTimeout = setTimeout(function(){local.SlideshowExecute(data);},5000);
}

local.ThumbOffset = -1;
local.ThumbListWidth = -1;
local.ThumbBoxWidth = -1;
local.ThumbMinPos = 0;
local.SlideshowPrepareThumbnails = function() {
	var row = $('#gallery-slideshow-thumbs');
	var inner = row.find('.thumb_row_inner');

	row.css('overflow','hidden');
	local.ThumbBoxWidth = row.width();

	inner.css('position','absolute').css('left','0');

	var curPos = 0;
	var curIdx = 0;
	inner.find('div').each(function() {
		var t = $(this);
		t.css('position','absolute').css('padding',0).css('left',curPos);
		this._position = curPos;
		this._idx = curIdx++;
		curPos += 92; //t.outerWidth();
		curPos += 9;
	});
	inner.find('a').click(function() {
		local.SlideshowChangeTo(parseInt($(this).closest('div')[0]._idx),local.SlideshowData);
		return false;
	});
	local.ThumbListWidth = curPos;
	local.ThumbMinPos = local.ThumbBoxWidth - local.ThumbListWidth;
	
	$('.nav.back a').click(function(){local.SlideshowChangeTo(local.SlideshowIndex - 1,local.SlideshowData);return false;});
	$('.nav.next a').click(function(){local.SlideshowChangeTo(local.SlideshowIndex + 1,local.SlideshowData);return false;});
}
local.SlideshowActivateThumbnail = function(thmId) {
	$('#gallery-slideshow-nav-parent').find('.gallery-slideshow-item-active').removeClass('gallery-slideshow-item-active');
	var thm = $('#gallery-slideshow-item-' + parseInt(thmId));
	thm.addClass('gallery-slideshow-item-active');
	var ntPos = (local.ThumbBoxWidth / 2) - (thm[0]._position + (thm.width() / 2));
	if (ntPos > 0) ntPos = 0;
	if (ntPos < local.ThumbMinPos) ntPos = local.ThumbMinPos;
	$('#gallery-slideshow-thumbs div.thumb_row_inner').animate({left: ntPos},500);
}
/* WebFilter 0x101000640000018E */
var MONTH_LIST= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"];

function DateSelectControl(initialDate, maxDate, minDate, dayElement, monthElement, yearElement, onChangeFunction) {
  return {
     "dayElement": dayElement,
     "monthElement": monthElement,
     "yearElement": yearElement,
     "maxDate": maxDate,
     "minDate": minDate,
     "ocf": onChangeFunction,
     "years": [minDate.getFullYear()], 
     date: initialDate,

     "getUpdateFunction": function(){
        var hubba = this;
        return function(){
           hubba.update();
        } 

     },

     "redrawDays": function(){
       //* Make sure the correct amount of days show for that month on load
       //* when a user selects a departure date in a month that has 30 days, make sure the return day list has 31 days
       //* when a user selects a month with 31 days, make sure the return days list has the right amount of days for the next month
       var daysInMonth = 32 - new Date(this.date.getFullYear(), this.date.getMonth(), 32).getDate();
       var startDay = 0;
       // this probably needs a rethink but will do for now; maybe we can use a pre-built calendar
       if(this.maxDate.getFullYear() == this.date.getFullYear() && this.maxDate.getMonth() == this.date.getMonth())
       {
          daysInMonth = this.maxDate.getDate();
		  
       }
       this.dayElement.options.length = 0;
       for(var i = startDay; i < daysInMonth; i++)
       {
         this.dayElement.options[this.dayElement.options.length]=new Option(i+1, i+1);
         if(i == (this.date.getDate()-1))
         {
              this.dayElement.options[this.dayElement.options.length-1].selected = true;
         }
       }
       
     },
     "redrawMonths": function(){
        var monthCount = 12;
        var startMonth = 0;    
        this.monthElement.options.length = 0;
		for(var i = startMonth; i < monthCount; i++)
        {
          this.monthElement.options[this.monthElement.options.length]=new Option(MONTH_LIST[i], i+1);
          if(this.date.getMonth() == i)
          {
            this.monthElement.options[this.monthElement.options.length-1].selected = true;
          }
        }

     },
     "redrawYears": function(){

        this.yearElement.options.length = 0;
	for(var i = 0; i < this.years.length; i++)
        {
          this.yearElement.options[i]=new Option(this.years[i], this.years[i]);
          if(this.years[i] == this.date.getFullYear())
          {
             this.yearElement.options[i].selected = true;
          }
        }
        
     },

     "redraw": function(){
        this.redrawDays();
        this.redrawMonths();
		this.redrawYears();
      },

     "showDate": function(theNewDate){
		this.date = theNewDate;
        this.redraw();
        if(this.ocf)
          this.ocf();
     },   

     "getAsDate": function(){

        return this.date;
     },
	
	"update": function(){
		 this.date.setDate(1);
         //use the values instead of the indicies
         this.date.setMonth(this.monthElement.options[this.monthElement.selectedIndex].value-1);
         this.date.setFullYear(this.yearElement.options[this.yearElement.selectedIndex].value);
         var daysInMonth = 32 - new Date(this.date.getFullYear(), this.date.getMonth(), 32).getDate();
         var day = this.dayElement.options[this.dayElement.selectedIndex].value;
         //build a test date
         var tmpDate = new Date();
         tmpDate.setDate(1);
         tmpDate.setFullYear(this.date.getFullYear());
         tmpDate.setMonth(this.date.getMonth());
         if(day <= daysInMonth)
         {
         	tmpDate.setDate(day);
         }
         else
         {
            tmpDate.setDate(daysInMonth);
         }
         
         // if the tmpdate is later than the max date, set the date to the max date
		 if(tmpDate > this.maxDate)
         {
            this.date.setTime(this.maxDate.getTime());
			friendlyMaxDate = flightMaxD.getDate() + " " + MONTH_LIST[(flightMaxD.getMonth())] + " " + flightMaxD.getFullYear();
			document.getElementById('error_flights').innerHTML = "This date is not yet available for sale. You may book up to 330 days in advance, ie. no later than "+friendlyMaxDate;
			document.getElementById('error_hotels').innerHTML = "This date is not yet available for sale. You may book up to 330 days in advance, ie. no later than "+friendlyMaxDate;
			document.getElementById('error_cars').innerHTML = "This date is not yet available for sale. You may book up to 330 days in advance, ie. no later than "+friendlyMaxDate;
         }else{
            //if the tmpdate is earlier than today, set the date to today
            if(tmpDate < this.minDate)
            {
			  this.date.setTime(this.minDate.getTime());
			  friendlyMinDate =  minDate.getDate() + " " + MONTH_LIST[(minDate.getMonth())] + " " + minDate.getFullYear();
              document.getElementById('error_flights').innerHTML = "You cannot choose a date earlier than "+friendlyMinDate;
              document.getElementById('error_hotels').innerHTML = "You cannot choose a date earlier than "+friendlyMinDate;
              document.getElementById('error_cars').innerHTML = "You cannot choose a date earlier than "+friendlyMinDate;
            }
            else
            {
               this.date.setTime(tmpDate.getTime());
			   document.getElementById('error_flights').innerHTML = '';
			   document.getElementById('error_hotels').innerHTML = '';
			   document.getElementById('error_cars').innerHTML = '';
			   //perform a full redraw
				this.redraw();
					if(this.ocf)
						this.ocf();
					}
			}	
     },
     "init": function(){

        this.dayElement.onchange = this.getUpdateFunction();
        this.monthElement.onchange = this.getUpdateFunction();
        this.yearElement.onchange = this.getUpdateFunction();
        if(this.maxDate.getFullYear() > this.minDate.getFullYear())
        {
           for(var i = this.minDate.getFullYear() + 1; i <= this.maxDate.getFullYear(); i++)
           {
              this.years[this.years.length] = i;
           }
        }
		this.redraw();
     return this;
	     }
 
  }.init();
}

function addEvent(obj, evType, fn){ 
	 if (obj.addEventListener){ 
	   obj.addEventListener(evType, fn, false); 
	   return true; 
	 } else if (obj.attachEvent){ 
	   var r = obj.attachEvent("on"+evType, fn); 
	   return r; 
	 } else { 
	   return false; 
	 } 
}

Date.prototype.addDays = function(num) {
   var ONE_DAY_IN_MS = 1000*60*60*24;
   this.setTime(this.getTime() + (ONE_DAY_IN_MS*num));
}

//flights
var flightDaysInAdvance = 4;//change this value to be in accordance with the customer's choice for the first possible day to make a booking.
var daysInTrip = 31;
var flightMinD = new Date();
flightMinD.addDays(flightDaysInAdvance);
var flightMaxD = new Date(flightMinD.getTime());
flightMaxD.addDays(330);

//hotels
var hotelDaysInAdvance = 4;//change this value to be in accordance with the customer's choice for the first possible day to make a reservation.
var hotelDaysInTrip = 31;
var hotelMinD = new Date();
hotelMinD.addDays(hotelDaysInAdvance);
var hotelMaxD = new Date(hotelMinD.getTime());
hotelMaxD.addDays(330);

//cars
var carDaysInAdvance = 4;//change this value to be in accordance with the customer's choice for the first possible day to make a reservation.
var carDaysInTrip = 31;
var carMinD = new Date();
carMinD.addDays(carDaysInAdvance);
var carMaxD = new Date(carMinD.getTime());
carMaxD.addDays(330);

function setupDates()
{
	//* When page loads, show current date 
	//* Make return date a month later

	//flights
	var departDate = new Date();
	  departDate.addDays(flightDaysInAdvance);
	var returnDate = new Date(departDate);
	  returnDate.addDays(daysInTrip);

	//hotels
	var hotelDepartDate = new Date();
	  hotelDepartDate.addDays(hotelDaysInAdvance);
	var hotelReturnDate = new Date(hotelDepartDate);
	  hotelReturnDate.addDays(hotelDaysInTrip);

 	//cars
	var carDepartDate = new Date();
	  carDepartDate.addDays(carDaysInAdvance);
	var carReturnDate = new Date(carDepartDate);
	  carReturnDate.addDays(carDaysInTrip);

	//flights
	flightDepartDateControl = new DateSelectControl(departDate, flightMaxD, flightMinD, document.getElementById('searchAir.segments[0].departDate.day'),document.getElementById('searchAir.segments[0].departDate.month'),document.getElementById('searchAir.segments[0].departDate.year'), updateReturnFlight);
	flightReturnDateControl = new DateSelectControl(returnDate, flightMaxD, flightMinD, document.getElementById('searchAir.segments[1].departDate.day'),document.getElementById('searchAir.segments[1].departDate.month'),document.getElementById('searchAir.segments[1].departDate.year'));
	
	//hotels
	hotelDepartDateControl = new DateSelectControl(hotelDepartDate, hotelMaxD, hotelMinD, document.getElementById('searchHotel.segments[0].checkinDate.day'),document.getElementById('searchHotel.segments[0].checkinDate.month'),document.getElementById('searchHotel.segments[0].checkinDate.year'), updateReturnHotel);
	hotelReturnDateControl = new DateSelectControl(hotelReturnDate, hotelMaxD, hotelMinD, document.getElementById('searchHotel.segments[0].checkoutDate.day'),document.getElementById('searchHotel.segments[0].checkoutDate.month'),document.getElementById('searchHotel.segments[0].checkoutDate.year'));
	
	//cars
	carDepartDateControl = new DateSelectControl(carDepartDate, carMaxD, carMinD, document.getElementById('searchCar.segments[0].pickupDate.day'),document.getElementById('searchCar.segments[0].pickupDate.month'),document.getElementById('searchCar.segments[0].pickupDate.year'), updateReturnCar);
	carReturnDateControl = new DateSelectControl(carReturnDate, carMaxD, carMinD, document.getElementById('searchCar.segments[0].dropoffDate.day'),document.getElementById('searchCar.segments[0].dropoffDate.month'),document.getElementById('searchCar.segments[0].dropoffDate.year'));
}

function updateReturnFlight()
{
  //* When user changes departure date, make return date month later
  //* If the user chooses the 12th month as departure date, change the return month to the 1st and the return year to the next year
   var newDate = new Date(flightDepartDateControl.getAsDate());
        newDate.addDays(daysInTrip);
        newDate.setTime(Math.min(newDate.getTime(), flightMaxD.getTime()));
     	flightReturnDateControl.showDate(newDate);
}

function updateReturnHotel()
{
  //* When user changes departure date, make return date month later
  //* If the user chooses the 12th month as departure date, change the return month to the 1st and the return year to the next year
   var newDate = new Date(hotelDepartDateControl.getAsDate());
        newDate.addDays(daysInTrip);
        newDate.setTime(Math.min(newDate.getTime(), hotelMaxD.getTime()));
     	hotelReturnDateControl.showDate(newDate);
}

function updateReturnCar()
{
  //* When user changes departure date, make return date month later
  //* If the user chooses the 12th month as departure date, change the return month to the 1st and the return year to the next year
   var newDate = new Date(carDepartDateControl.getAsDate());
        newDate.addDays(daysInTrip);
        newDate.setTime(Math.min(newDate.getTime(), carMaxD.getTime()));
     	carReturnDateControl.showDate(newDate);
}

function checkBlankFlights()
{
	if (document.getElementById('searchAir.segments[0].departCity').value == "") {
		document.getElementById('searchAir.segments[0].departCity').focus();
		document.getElementById('error_depart').innerHTML = "Please type in the first 4 letters of city, then select from the list that appears";
		return false ;
	}else if(document.getElementById('searchAir.segments[0].arrivalCity').value == "") {
		document.getElementById('searchAir.segments[0].arrivalCity').focus();
		document.getElementById('error_arrive').innerHTML = "Please type in the first 4 letters of city, then select from the list that appears";
		return false ;
	}else if (document.getElementById('error_flights').innerHTML !=""){
		return false;
	}else{	
		//send the value of the cabin class chosen through to the full search page
		var cabClass = document.getElementById("cabClassSelect").value
		document.getElementById("searchAir.segments[0].cabinIndicator").value= cabClass;
		document.getElementById("searchAir.segments[1].cabinIndicator").value= cabClass;
		return true ;
  }
}

function checkBlankHotels()
{
	if (document.getElementById('searchHotel.segments[0].city').value == "") {
		document.getElementById('searchHotel.segments[0].city').focus();
		document.getElementById('hotel_error_depart').innerHTML = "Please type in the first 4 letters of city, then select from the list that appears";
		return false ;
	}else if (document.getElementById('error_hotels').innerHTML !=""){
		return false;
	}else{	
		return true ;
  }
}

function checkBlankCars()
{
	if (document.getElementById('searchCar.segments[0].pickupCity').value == "") {
		document.getElementById('searchCar.segments[0].pickupCity').focus();
		document.getElementById('error_cars_city').innerHTML = "Please type in the first 4 letters of city, then select from the list that appears";
		return false ;
	}else if (document.getElementById('error_cars').innerHTML !=""){
		return false;	
	}else{
		//send the value of the drop off city to be the same as the pick up city
		var dropOff = document.getElementById("searchCar.segments[0].pickupCity").value
		document.getElementById("segments[0].dropoffCity").value= dropOff;
		return true ;
  }
}


function clearError()
{
	document.getElementById('error_depart').innerHTML = "";
	document.getElementById('error_arrive').innerHTML = "";
	document.getElementById('error_cars').innerHTML = "";
	document.getElementById('error_cars_city').innerHTML = "";
	document.getElementById('error_flights').innerHTML = "";
	document.getElementById('error_hotels').innerHTML = "";
}

function hotelClearError()
{
	document.getElementById('hotel_error_depart').innerHTML = "";
}

function disableReturn()
{
	var found_it
	var returnEl = document.flights.elements["return"];
	for (var i=0; i<returnEl.length; i++)  {
		if (returnEl[i].checked)  {
			selected = returnEl[i].value
			if (selected=="O")
			{
				document.getElementById("searchAir.segments[1].departDate.day").disabled = true;
				document.getElementById("searchAir.segments[1].departDate.month").disabled = true;
				document.getElementById("searchAir.segments[1].departDate.year").disabled = true;

			}else{
				document.getElementById("searchAir.segments[1].departDate.day").disabled = false;
				document.getElementById("searchAir.segments[1].departDate.month").disabled = false;
				document.getElementById("searchAir.segments[1].departDate.year").disabled = false;
			}
		}
	} 
}


addEvent(window, 'load', setupDates);
/* WebFilter 0x1010006400000194 */
local.fileLinkPickerSearch = function(oText,iFolder) {
	if (oText._searchTimeout) { clearTimeout(oText._searchTimeout); }
	oText._searchTimeout = setTimeout(function() {
		oText._searchTimeout = null;
		var ot = $(oText);
		if (oText._lower == null) oText._lower = ot.closest('.cms-page-search').find('.cms-page-search-lower');
		var lwr = oText._lower;
		if (lwr._oldHtml == null) { lwr._oldHtml = $(lwr).html(); }
		if (oText._searchXhr != null) {
			// Request already in progress
			oText._searchQueued = true;
		} else if (oText.value == '' && lwr._oldHtml != null) {
			lwr.html(lwr._oldHtml);
		} else if (oText._lastSearch != oText.value) {
			// Nothing queued
			oText._searchQueued = false;
			ot.closest('div').addClass('active');
			oText._lastSearch = oText.value;
			oText._searchXhr = $.getJSON(cms.RootPath + '/wf.ashx?f=search.json&t=268566529&q=' + encodeURIComponent(oText.value) + '&file.folder=' + parseInt(iFolder,10),
				function(sData) {
					$(lwr).empty();
					var h = $(lwr).closest('.ui-dialog-content').height();
					ot.closest('div').removeClass('active');
					ot.closest('.cms-page-search').find('.cms-page-search-lower').scrollTop(0);
					var result = false;
					if (sData.length > 0) {
						for (var idx = 0; idx < sData.length; idx++) {
							var sObj = sData[idx];
							var size = parseInt(sObj['size'],10);
							if (size > 0) {
								var item = $('<div/>').addClass('cms-page-search-result').addClass('cms-file-search-result').addClass(idx % 2 == 0 ? 'list-even':'list-odd');
								var thm = parseInt(sObj['thumbnail'],10);
								if (thm != 0) {
									var imgLink = $('<a/>')
										.click(function(){storeFileChoice(this._object_id);return false;})
										.attr('href',sObj['link'])
										.appendTo($('<div/>')
										.addClass('cms-file-search-image')
										.appendTo(item));
									imgLink[0]._type_id = sObj['type_id'];
									imgLink[0]._object_id = sObj['object_id'];
									$('<img/>').attr('src',cms.RootPath + '/f.ashx?v=' + thm).appendTo(imgLink);
								}
								var hdr = $('<div/>').addClass('cms-page-search-result-title');
								var link = $('<a/>');
								link[0]._type_id = sObj['type_id'];
								link[0]._object_id = sObj['object_id'];
								link.click(function(){storeCmsLink('{{268566529:' + this._object_id + ';File.LinkType=Download}}');return false;});
								if(sObj['hl_title'])
									link.html(sObj['hl_title']);
								else
									link.text(sObj['title']);
								link.attr('href',sObj['link']).appendTo(hdr);
								hdr.appendTo(item);
								$('<div/>').addClass('cms-page-search-result-right').text(((Math.round(parseFloat(sObj['size']) / 1024) * 100) / 100) + ' kB').appendTo(item);
								$('<div/>').addClass('cms-page-search-result-url').text(sObj['path']).appendTo(item);
								$('<a/>').attr('href',sObj['download']).attr('target','_blank').text('download')
									.appendTo($('<div/>').addClass('cms-page-search-result-right').appendTo(item));
								$('<div/>').addClass('cms-page-search-result-url').text(sObj['mime']).appendTo(item);
								$('<div/>').addClass('cms-page-search-result-end').appendTo(item);
								if(sObj['summary']) $('<div/>').addClass('cms-page-search-result-body').html(sObj['summary']).appendTo(item);
								item.appendTo(lwr);
								var l = $(lwr);
								l.height(h - l.position().top + 24);
								result = true;
							}
						}
					}
					if (result == false) {
						var outer = $('<div />').addClass('cms-info');
						var inner = $('<div />').addClass('cms-info-inner').addClass('cms-info-info').html('<p>No results found.</p>').appendTo(outer);
						outer.appendTo(lwr);
					}
					oText._searchXhr = null;
					if (oText._searchQueued == true) {
						oText._searchQueued = false;
						local.pagePickerSearch(oText);
					}
				});
		}
	}, 300);
};
/* WebFilter 0x1010006400000195 */
local.filePickerSearch = function(oText,iFolder) {
	if (oText._searchTimeout) { clearTimeout(oText._searchTimeout); }
	oText._searchTimeout = setTimeout(function() {
		oText._searchTimeout = null;
		var ot = $(oText);
		if (oText._lower == null) oText._lower = ot.closest('.cms-page-search').find('.cms-page-search-lower');
		var lwr = oText._lower;
		if (lwr._oldHtml == null) { lwr._oldHtml = $(lwr).html(); }
		if (oText._searchXhr != null) {
			// Request already in progress
			oText._searchQueued = true;
		} else if (oText.value == '' && lwr._oldHtml != null) {
			lwr.html(lwr._oldHtml);
		} else if (oText._lastSearch != oText.value) {
			// Nothing queued
			oText._searchQueued = false;
			ot.closest('div').addClass('active');
			oText._lastSearch = oText.value;
			oText._searchXhr = $.getJSON(cms.RootPath + '/wf.ashx?f=search.json&t=268566529&q=' + encodeURIComponent(oText.value) + '&file.folder=' + parseInt(iFolder,10),
				function(sData) {
					$(lwr).empty();
					var h = $(lwr).closest('.ui-dialog-content').height();
					ot.closest('div').removeClass('active');
					ot.closest('.cms-page-search').find('.cms-page-search-lower').scrollTop(0);
					var result = false;
					if (sData.length > 0) {
						for (var idx = 0; idx < sData.length; idx++) {
							var sObj = sData[idx];
							var size = parseInt(sObj['size'],10);
							if (size > 0) {
								var item = $('<div/>').addClass('cms-page-search-result').addClass('cms-file-search-result').addClass(idx % 2 == 0 ? 'list-even':'list-odd');
								var thm = parseInt(sObj['thumbnail'],10);
								if (thm != 0) {
									var imgLink = $('<a/>')
										.click(function(){storeFileChoice(this._object_id);return false;})
										.attr('href',sObj['link'])
										.appendTo($('<div/>')
										.addClass('cms-file-search-image')
										.appendTo(item));
									imgLink[0]._type_id = sObj['type_id'];
									imgLink[0]._object_id = sObj['object_id'];
									$('<img/>').attr('src',cms.RootPath + '/f.ashx?v=' + thm).appendTo(imgLink);
								}
								var hdr = $('<div/>').addClass('cms-page-search-result-title');
								var link = $('<a/>');
								link[0]._type_id = sObj['type_id'];
								link[0]._object_id = sObj['object_id'];
								link.click(function(){storeFileChoice(this._object_id);return false;});
								if(sObj['hl_title'])
									link.html(sObj['hl_title']);
								else
									link.text(sObj['title']);
								link.attr('href',sObj['link']).appendTo(hdr);
								hdr.appendTo(item);
								$('<div/>').addClass('cms-page-search-result-right').text(((Math.round(parseFloat(sObj['size']) / 1024) * 100) / 100) + ' kB').appendTo(item);
								$('<div/>').addClass('cms-page-search-result-url').text(sObj['path']).appendTo(item);
								$('<a/>').attr('href',sObj['download']).attr('target','_blank').text('download')
									.appendTo($('<div/>').addClass('cms-page-search-result-right').appendTo(item));
								$('<div/>').addClass('cms-page-search-result-url').text(sObj['mime']).appendTo(item);
								$('<div/>').addClass('cms-page-search-result-end').appendTo(item);
								if(sObj['summary']) $('<div/>').addClass('cms-page-search-result-body').html(sObj['summary']).appendTo(item);
								item.appendTo(lwr);
								var l = $(lwr);
								l.height(h - l.position().top + 24);
								result = true;
							}
						}
					}
					if (result == false) {
						var outer = $('<div />').addClass('cms-info');
						var inner = $('<div />').addClass('cms-info-inner').addClass('cms-info-info').html('<p>No results found.</p>').appendTo(outer);
						outer.appendTo(lwr);
					}
					oText._searchXhr = null;
					if (oText._searchQueued == true) {
						oText._searchQueued = false;
						local.pagePickerSearch(oText);
					}
				});
		}
	}, 300);
};
/* WebFilter 0x1010006400000197 */
local.pagePickerSearch = function(oText) {
	if (oText._searchTimeout) { clearTimeout(oText._searchTimeout); }
	oText._searchTimeout = setTimeout(function() {
		oText._searchTimeout = null;
		var ot = $(oText);
		if (oText._lower == null) oText._lower = ot.closest('.cms-page-search').find('.cms-page-search-lower');
		var lwr = oText._lower;
		if (lwr._oldHtml == null) { lwr._oldHtml = $(lwr).html(); }
		if (oText._searchXhr != null) {
			// Request already in progress
			oText._searchQueued = true;
		} else if (oText.value == '' && lwr._oldHtml != null) {
			lwr.html(lwr._oldHtml);
		} else if (oText._lastSearch != oText.value) {
			// Nothing queued
			oText._searchQueued = false;
			ot.closest('div').addClass('active');
			oText._lastSearch = oText.value;
			oText._searchXhr = $.getJSON(cms.RootPath + '/wf.ashx?f=search.json&t=269484034&q=' + encodeURIComponent(oText.value),
				function(sData) {
					$(lwr).empty();
					var h = $(lwr).closest('.ui-dialog-content').height();
					ot.closest('div').removeClass('active');
					ot.closest('.cms-page-search').find('.cms-page-search-lower').scrollTop(0);
					if(sData.length == 0) {
						var outer = $('<div />').addClass('cms-info');
						var inner = $('<div />').addClass('cms-info-inner').addClass('cms-info-info').html('<p>No results found.</p>').appendTo(outer);
						outer.appendTo(lwr);
					} else {
						for (var idx = 0; idx < sData.length; idx++) {
							var sObj = sData[idx];
							var item = $('<div/>').addClass('cms-page-search-result').addClass(idx % 2 == 0 ? 'list-even':'list-odd');
							var hdr = $('<div/>').addClass('cms-page-search-result-title');
							var link = $('<a/>');
							link[0]._type_id = sObj['type_id'];
							link[0]._object_id = sObj['object_id'];
							link.click(function(){storeCmsLink('{{'+this._type_id+':'+this._object_id+'}}');return false;});
							if(sObj['hl_title'])
								link.html(sObj['hl_title']);
							else
								link.text(sObj['title']);
							link.attr('href',sObj['link']).appendTo(hdr);
							hdr.appendTo(item);
							$('<div/>').addClass('cms-page-search-result-url').text(sObj['link']).appendTo(item);
							if(sObj['summary']) $('<div/>').addClass('cms-page-search-result-body').html(sObj['summary']).appendTo(item);
							item.appendTo(lwr);
							var l = $(lwr);
							l.height(h - l.position().top + 24);
						}
					}
					oText._searchXhr = null;
					if (oText._searchQueued == true) {
						oText._searchQueued = false;
						local.pagePickerSearch(oText);
					}
				});
		}
	}, 300);
};

