﻿ 
 $(document).ready(function() {
   

   // for show/hide content boxes
   contentHiders();
   
   // quicklinks dropdown
   var settings = {
      over: function(){
		$this = $(this);
		$rollover = $('#topNavQuicklinksDropDown')
		$rollover.css("left", $this.position().left + 17);
		$rollover.css("top", $this.position().top + 20);
		$rollover.fadeIn('fast');
		},
	  timeout: 100,
      sensitivity:7,
      out:function(){$('#topNavQuicklinksDropDown').fadeOut("fast");}
    };
	$('#topNavQuicklinks', this).hoverIntent(settings);

 });
 
 function setDefaultDate(id)
 {
 	var dayId = $('#' + id).parent().children(".day").attr("id");
	var monthId = $('#' + id).parent().children(".month").attr("id");
	var yearId = $('#' + id).parent().children(".year").attr("id");
	
	var year = $("#" + yearId).val();
	var month = $("#" + monthId).val();
	var day = $("#" + dayId).val();
	if(year > 0 & month > 0 & day > 0)
	{
		var dte = new Date(year, month - 1, day);
		$('#' + id).datepicker("setDate", dte);
	}
	else
	{
		if(id == "leaving" | id == "departing")
		{
			$('#' + id).datepicker("setDate", $('#arriving').datepicker('getDate'));
		}
		if($('#' + id).attr("rel") == "dateto")
		{
			$('#' + id).datepicker("setDate", $('.datepicker[rel=datefrom]').datepicker('getDate'));
		}
	}
 }
 
 function setDateDropdown(id,day,month,year)
 {
	var dayId = $('#' + id).parent().children(".day").attr("id");
	var monthId = $('#' + id).parent().children(".month").attr("id");
	var yearId = $('#' + id).parent().children(".year").attr("id");

    if ($("#" + dayId + " option[value=" + day + "]").length == 0){ 
        $("#" + dayId).append(
            $('<option></option>').val(day).html(pad(day,2))
        );
    }
    
    $("#" + dayId).val(day,2);
    
    if ($("#" + monthId + " option[value=" + month + "]").length == 0){ 
        $("#" + monthId).append(
            $('<option></option>').val(month).html(pad(month,2))
        );
    }
    $("#" + monthId).val(month);
    
    if ($("#" + yearId + " option[value=" + year + "]").length == 0){ 
        $("#" + yearId).append(
            $('<option></option>').val(year).html(pad(year,2))
        );
    }
    $("#" + yearId).val(year);
 }
 
 
 function pad(theNumber, max) {
    var numStr = String(theNumber);

    while ( numStr.length < max) {
        numStr = '0' + numStr;
    }

    return numStr;
}

function contentHiders()
{
    $('.showhide').click(function() {
      showHideContent($(this));
    });
    
 	var requestedid = "";
	var url = document.location.toString();
	if (url.match('#')) {
		requestedid = "q" + url.split('#')[1].substring(3);
	}	 
 
	$('.faqlist h3').each(function() {
		var tis = $(this), state = false, answer = tis.next('div');
		if ($(this).attr("id") != requestedid)
		{
			answer.slideUp();
		}
		tis.click(function() {
				state = !state;
				answer.slideToggle(state);
				tis.toggleClass('active',state);
			});
		});
}

function showHideContent(obj)
{
    if(obj.html() == 'Hide')
    {
        obj.html('Show');
        obj.attr('class', 'showhide show')
        $(obj).parent().children('.content').children('.body').css('display', 'none');
    }
    else
    {
        obj.html('Hide');
        obj.attr('class', 'showhide')
        $(obj).parent().children('.content').children('.body').css('display', 'block');
    }
}

function properyDetailsGallery(width)
{
	if(width == null) width = 430;
    var galleries = $('.ad-gallery').adGallery({
        loader_image: '/images/ajax-loader.gif',
        width: width, 
        height: 250, 
        thumb_opacity: 1, 
        start_at_index: 0, 
        animate_first_image: false, 
        animation_speed: 400, 
        display_next_and_prev: false, 
        display_back_and_forward: true,
        scroll_jump: 0,
        slideshow: {
            enable: false,
            autostart: true,
            speed: 5000,
            start_label: 'Start',
            stop_label: 'Stop',
            stop_on_scroll: true,
            countdown_prefix: '(',
            countdown_sufix: ')'
        }
    });
}

function propertyDetailsMap(lat, lng, title)
{
    var latlng = new google.maps.LatLng(lat, lng); 
    var myOptions = { 
      zoom: 12, 
      center: latlng,
      streetViewControl: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    var marker = new google.maps.Marker({
        position: latlng, 
        map: map,
        title: title
    });
}

function showPopup(params)
{
	var popupId = "";
	var popupContentId = "";
	var popupWidth = 400;
	var popupHeight = 0;
	
	if(params.width != undefined & params.width != '') popupWidth = params.width;
	if(params.height != undefined & params.height != '') popupHeight = params.height;
	
	if(params.popupElement != undefined & params.popupElement != '')
	{
		closePopup();
		
		popupId = params.popupElement + "-popup";
		popupContentId = params.popupElement + "-popup-content";
		
		// add background
		if($('#PopupBackgroundOverlay').length == 0) $('body').append('<div id="PopupBackgroundOverlay"></div>');

		// create popup
		var divstr = "";
		divstr += '<div class="Popup" id="' + popupId + '">';
		divstr += '<div class="popupClose"><a href="javascript:void(0);" onclick="closePopup()">close</a></div>';
		divstr += '<div style="clear:both;"></div>';
		divstr += '<div class="gradbox">';
		divstr += '<div class="content" id="' + popupContentId + '">';
		
		if(params.title != undefined & params.title != '')
		{
			divstr += '<h1>' + params.title + '</h1>';
		}
		
		divstr += '</div>';
		divstr += '</div>';
	    divstr += '</div>';
	    
		if($('#' + popupId).length == 0)
		{
			if($('#aspnetForm').length == 0)
			{
				$('#form1').append(divstr);
			}
			else
			{
				$('#aspnetForm').append(divstr);
			}
		}
		
		// add popup element
		if($('#' + params.popupElement).parent().attr('id') != popupContentId) $('#' + popupContentId).append( $('#' + params.popupElement) );

		// show popup element
		$('#' + params.popupElement).show();
		
    	// show popup
		$('#' + popupId).show().width(popupWidth).height(popupHeight).css({left: ($(window).width() / 2) - ($('#' + popupId).width() / 2), top: $(window).scrollTop() + ($(window).height() / 2) - ($('#' + popupId).height() / 2) });
		$(window).resize(resizePopup);

		// correct outer height
		var popContentHeight = 10;
		$('#' + popupId).children().each(function() {
			var child = $(this);
			if(child.css('position') != 'absolute')
			{
				popContentHeight += child.innerHeight();
			}
		});
		if(popupHeight == 0)
		{
			if($('#' + popupId).css('height') != popContentHeight + 'px') $('#' + popupId).css('height', popContentHeight + 'px');
		}
		else
		{
			if(popContentHeight > popupHeight)
			{
				$('#' + popupId).css('overflow-y', 'scroll');
			}
		}
		
		// correct top
		$('#' + popupId).css('top', $(window).scrollTop() + ($(window).height() / 2) - ($('#' + popupId).height() / 2) );
		
		// lightbox background
		var ovHeight = $(document).height();
		if($(window).height() + 10 > $(document).height()) ovHeight = $(window).height();
		$('#PopupBackgroundOverlay').show().width($(window).width()).height(ovHeight);
    
		if(parseInt($('#' + popupId).css('top')) < 0) $('#' + popupId).css('top', '0px');
		if(parseInt($('#' + popupId).css('left')) < 0) $('#' + popupId).css('left', '0px');

		setTimeout(resizePopup, 500);

    }
}

function closePopup()
{
    $('#PopupBackgroundOverlay').hide();

    $('.Popup').each(function() {
        if($(this).find('iframe').attr('src') != undefined)
        {
            if($(this).css('display') != 'none') $(this).find('iframe').attr('src', $(this).find('iframe').attr('src'));
        }
    });
    
    $('.Popup').hide();
}
function resizePopup()
{
    if($('#PopupBackgroundOverlay').css('display') != 'none')
    {
        $('.Popup').each(function() {
            if($(this).css('display') == 'block')
            {
                $(this).css({left: ($(window).width() / 2) - ($(this).width() / 2), top: $(window).scrollTop() + ($(window).height() / 2) - ($(this).height() / 2) });
                if(parseInt($(this).css('top')) < 0) $(this).css('top', '0px');
                if(parseInt($(this).css('left')) < 0) $(this).css('left', '0px');
            }
        });
		var ovHeight = $(document).height();
		if($(window).height() + 10 > $(document).height()) ovHeight = $(window).height();
		$('#PopupBackgroundOverlay').show().width($(window).width()).height(ovHeight);
    }
}
