pageName = '';
hl = new Object();

hl.map_directions =                     '/map-directions';
hl.henry_b_gonzalez_convention_center = '/henry-b-gonzalez-convention-center';
hl.activities =                         '/activities';
hl.san_antonio_attractions =            '/activities';
hl.news_events =                        '/activities';
hl.spa_experience =                     '/activities';
hl.fitness_center =                     '/activities';
hl.pool =                               '/activities';
hl.golf =                               '/activities';
hl.weddings_celebrations =              '/weddings-celebrations';
hl.lone_star_place_weddings =           '/weddings-celebrations';
hl.catering_weddings =                  '/weddings-celebrations';
hl.weddings =                           '/weddings-celebrations';
hl.holiday =                            '/weddings-celebrations';
hl.personal_celebrations =              '/weddings-celebrations';
hl.barbat_mitzvahs =                    '/weddings-celebrations';
hl.galas_proms =                        '/weddings-celebrations';
hl.dining_entertainment =               '/dining-entertainment';
hl.chaps_restaurant =                   '/dining-entertainment';
hl.river_terrace_lounge =               '/dining-entertainment';
hl.jim_cullums_landing =                '/dining-entertainment';
hl.services_amenities =                 '/services-amenities';
hl.meetings_groups =                    '/meetings-groups';
hl.meetings =                           '/meetings-groups';
hl.lone_star_place =                    '/meetings-groups';
hl.catering_meetings =                  '/meetings-groups';
hl.recognition =                        '/meetings-groups';
hl.specials_packages =                  '/specials-packages';
hl.rooms_suites =                       '/rooms-suites';
hl.alamo_view =                         '/rooms-suites';
hl.river_view_double =                  '/rooms-suites';
hl.river_view_king =                    '/rooms-suites';
hl.executive_king =                     '/rooms-suites';
hl.two_double_beds =                    '/rooms-suites';
hl.one_king_bed =                       '/rooms-suites';
hl.business_plan =                      '/rooms-suites';
hl.riverbend_suite =                    '/rooms-suites';
hl.regency_suite =                      '/rooms-suites';
hl.atrium_suite =                       '/rooms-suites';

$(function(){
// custom select elements
    var currentTime = new Date();
    var cDay = currentTime.getDate();
    var cMonth = currentTime.getMonth();
    var cYear = currentTime.getFullYear();
    var tomorrow = new Date();
    tomorrow.setTime(currentTime.getTime() + (1000*3600*24))
    var tDay = tomorrow.getDate();
    var tMonth = tomorrow.getMonth();
    var tYear = tomorrow.getFullYear();
    var monthNames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];

    // get the number of days in a month
    function daysInMonth(month,year) {
        var dd = new Date(year, month+1, 0);
        return dd.getDate();
    }

    // set the start date (today)
    optM = '';
    for (cnt=cMonth; cnt<cMonth+13; cnt++) {
        mnt = (cnt) % 12;
        yr = (mnt==cnt)?cYear:cYear+1;
        mntS = mnt+1;
        if (mntS < 10)
            mntS = '0' + mntS;
        optM += '<option value="';
        optM += mntS + ' ' + (yr+'').substr(2,2);
        optM += '">';
        optM += monthNames[mnt] + ' ' + yr
        optM += '</option>';
    }
    dim = daysInMonth(cMonth, cYear);
    optD = '';
    for (cnt=1; cnt<=dim; cnt++) {
        dd = cnt<10?'0'+cnt:cnt;
        selectedDate = cnt == cDay?' selected="selected"':'';
        optD += '<option'+selectedDate+' value="'+dd+'">'+cnt+'</option>'
    }
    $('#monthyear0').html(optM);
    $('#day0').html(optD);

    // set the end date (tomorrow)
    optM = '';
    for (cnt=tMonth; cnt<tMonth+13; cnt++) {
        mnt = (cnt) % 12;
        yr = (mnt==cnt)?tYear:tYear+1;
        mntS = mnt+1;
        if (mntS < 10)
            mntS = '0' + mntS;
        optM += '<option value="';
        optM += mntS + ' ' + (yr+'').substr(2,2);
        optM += '">';
        optM += monthNames[mnt] + ' ' + yr
        optM += '</option>';
    }
    dim = daysInMonth(tMonth, tYear);
    optD = '';
    for (cnt=1; cnt<=dim; cnt++) {
        dd = cnt<10?'0'+cnt:cnt;
        selectedDate = cnt == tDay?' selected="selected"':'';
        optD += '<option'+selectedDate+' value="'+dd+'">'+cnt+'</option>'
    }
    $('#monthyear1').html(optM);
    $('#day1').html(optD);

    // replace the selects
    $('select').selectbox();

// page name
if(pageName) {
	$('body').removeClass().addClass(pageName);
	$('.nav a[href*='+hl[pageName]+']').parent().addClass('active');
}

// positioning copy show/hide
	$('.home #positioning_copy_link').click(function(){
		$('#positioning_copy').animate({height: '330px'});
		$('#positioning_copy_link .inner').animate({top: '0px', height: '0px'});
	});
	$('.home #positioning_copy .close').click(function(){
		$('#positioning_copy').animate({height: '0px'});
		$('#positioning_copy_link .inner').animate({top: '-75px', height: '75px'});
	});

// reservations show/hide
	$('#quick_reservations.colapsed').click(function(){
		$(this).animate({height: '330px'}).parents(':first').removeClass('colapsed');
		$('#quick_reservations .close').css({display: 'block'});
	});
	$('#quick_reservations .close').click(function(){
		$(this).css({display: 'none'});
		$('#quick_reservations').animate({height: '80px'}).parents(':first').addClass('colapsed');
		return false;
	});

// top drop show/hide
	$('#header .c_inner').click(function() {
		$(this).slideUp();
		$('#top_drop, #top_drop .inner').animate({height: '86px'});
		if(!setHeight)
			$('#content').animate({marginTop: '-58px'});
	});

	$('#header .close').click(function() {
		$('#top_drop, #top_drop .inner').animate({height: '0px'});
		$('#header .c_inner').slideDown(function(){$('#header .c_inner').css({position: 'relative', zIndex: '10'})});
		if(!setHeight)
			$('#content').animate({marginTop: '0px'});
	});

// load specials
	$('.lead_rate').load('/gallery-src .lead_rate_src');
	$('.scrollable').after('<div id="specials-src" style="display: none;"></div>')
	$('#specials-src').load('/rotating-specials-src .copy', specialsOnLoad);

function specialsOnLoad() {
	$('.navi').html('');
	$('.scrollable').html('<div class="items"></div>')
	$('#specials-src .textElement').each(function(){
		numItems = $('#specials-src .textElement').length;
		ind = $('#specials-src .textElement').index(this);
		$('.scrollable .items').append('<div class="i_special i_special'+ind+(ind==0?" visible":"")+'"' +(ind==0?'':' style="display: none;"')+'>'+$(this).html().replace(/&amp;/g, '&')+'</div>');
		$('.navi').append('<span id="i_special_nav'+ind+'"'+(ind==0?' class="active"':'')+'></span>')
	});
	$('.scrollable a').each(function(){
		this.target = '_blank';
	})

}


// highlights rotation
	$('.navi span').live('click', function(){
		which = $(this).attr('id').charAt(13);
		$('.scrollable .items .visible').removeClass('visible').fadeOut(function(){
			$('.i_special'+which).fadeIn().addClass('visible');
		});
		$('.navi span').removeClass();
		$(this).addClass('active');
		$('.scrollable').stopTime('controlled').oneTime('5s', function(){$('.scrollable').everyTime('5s', 'controlled', rotateSpecials);})
		whichAuto = which;
	});
	whichAuto = 0
	numItems = 3;
	$('.scrollable').everyTime('5s', 'controlled', rotateSpecials);
	function rotateSpecials() {
		whichAuto++;
		whichAuto %= numItems;
		$('.scrollable .items .visible').removeClass('visible').fadeOut(function(){
			$('.i_special'+whichAuto).addClass('visible').fadeIn();
		});
		$('.navi span').removeClass();
		$('#i_special_nav'+whichAuto).addClass('active');
	}

// external links
	$('a').each(function(){
		if($(this).attr('rel')=='external') this.target = '_blank';
		if($(this).html() == 'rfp') this.target = '_blank';
	});

// reveal the photo
	var imgRev = false;
	pCopy = $('.seo_copy').text();
	if (pCopy.length > 0) {
		$('#positioning_copy_link .inner').html('<p>' + pCopy + '</p>');
	} else {
		$('#positioning_copy_link').not('.home #positioning_copy_link').html('');
	}
	$('.reveal, #positioning_copy_link').not('.home #positioning_copy_link').click(function() {
		if(imgRev) {
			hideImage();
		} else {
			showImage();
		}
		imgRev = !imgRev;
	});

// hp background image rotation
	$('.home #content .c_inner').before('<div id="bgr_wrap"><div id="hp_bgr0"></div></div>');

	bgr = $.cookie('hpBgr')
	if(bgr) {
		$('#hp_bgr0').css({backgroundImage : 'url(/Websites/hyattregencysanantonio/templates/hyattsanantonio/images/bgr_home'+bgr+'.jpg)'});
		bgr++; bgr %= 3;
		$.cookie('hpBgr', bgr);
	} else {
		bgr = 0;
		$.cookie('hpBgr', 1);
	}

	$('#bgr_wrap').everyTime(7000, 'controlled', function(){
		$('#hp_bgr0').after('<div id="hp_bgr1"></div>')
		$('#hp_bgr1').css({display: 'none', backgroundImage : 'url(/Websites/hyattregencysanantonio/templates/hyattsanantonio/images/bgr_home'+bgr+'.jpg)' }).fadeIn(2500, function(){
			$('#hp_bgr0').css({backgroundImage : 'url(/Websites/hyattregencysanantonio/templates/hyattsanantonio/images/bgr_home'+bgr+'.jpg)'});
			$(this).remove();
			bgr++; bgr %= 3;
		});
	});

// datepicker
// display format oct 2009 2
// actual format  10 2009 02
	$('#qr_idate0')
	.datepicker({ showAnim: 'slideDown', minDate: '+0', maxDate: '+1Y', dateFormat: 'mm y-dd', altField: '#qr_idate0alt', altFormat: 'M yy-d' })
		.change(function(){
			date0=$('#qr_idate0').val().toLowerCase().split('-');
			date0alt=$('#qr_idate0alt').val().toLowerCase().split('-');
			$('.jquery-selectbox-currentItem:eq(0)').html(date0alt[0]);
			$('.jquery-selectbox-currentItem:eq(1)').html(date0alt[1]);
			$('#monthyear0').val(date0[0]);
			$('#day0').val(date0[1]);
			updateCheckOut();
		})
	$('#qr_idate0').datepicker('setDate', '+0');
	$('#qr_date0').click(function(){$('#qr_idate0').datepicker('show')});
	$('#qr_idate1')
		.datepicker({ showAnim: 'slideDown', minDate: '+1', maxDate: '+1Y +1D', dateFormat: 'mm y-dd', altField: '#qr_idate1alt', altFormat: 'M yy-d' })
		.change(function(){
			date1=$('#qr_idate1').val().toLowerCase().split('-');
			date1alt=$('#qr_idate1alt').val().toLowerCase().split('-');
			$('.jquery-selectbox-currentItem:eq(2)').html(date1alt[0]);
			$('.jquery-selectbox-currentItem:eq(3)').html(date1alt[1]);
			$('#monthyear1').val(date1[0]);
			$('#day1').val(date1[1]);
		})
	$('#qr_idate1').datepicker('setDate', '+1');
	$('#qr_date1').click(function(){$('#qr_idate1').datepicker('show')});


	$('#monthyear0, #day0').change(function(){
		mnyr = $('#monthyear0').val().split(' ');
		dte = new Date('20'+mnyr[1], mnyr[0]-1, $('#day0').val());
		$('#qr_idate0').datepicker('setDate', dte);
		updateCheckOut();
	});
	$('#monthyear1, #day1').change(function(){
		mnyr = $('#monthyear1').val().split(' ');
		dte = new Date('20'+mnyr[1], mnyr[0]-1, $('#day1').val());
		$('#qr_idate1').datepicker('setDate', dte);
		updateCheckOut();
	});

// cancel reservations form submission and open an url instead
	$('#frm').submit(function(){
		uriel  = 'http://www.hyatt.com/HICBooking?pid=SATRS&adults=';
		uriel += $('#adults').val();
		uriel += '&kids=';
		uriel += $('#kids').val();
		uriel += '&rooms=';
		uriel += $('#number').val();
		uriel += '&monthyear1=';
		uriel += $('#monthyear0').val();
		uriel += '&day1=';
		uriel += $('#day0').val();
		uriel += '&monthyear2=';
		uriel += $('#monthyear1').val();
		uriel += '&day2=';
		uriel += $('#day1').val();
		uriel += '&offercode=';
		if ($('#offercodeprop').val() != 'special offer code') {
			uriel += escape($('#offercodeprop').val());
		}
		uriel += '&corp_id=';
		if ($('#groupcorporate').val() != 'group/corporate #') {
			uriel += escape($('#groupcorporate').val());
		}
		uriel += '&icamp=RH-reservations-ss-satrs';
		window.open(uriel);
		return false;
	})


// input default value
	var active_color = '#fff';
	var inactive_color = '#e6c0cc';
	$('input.default-value').css('color', inactive_color);
	var default_values = new Array();
	$('input.default-value').focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		if (this.value == default_values[this.id]) {
			this.style.color = active_color;
			this.value = '';
		}
		$(this).blur(function() {
			if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		});
	});

//
	if(!setHeight)
		$('#footer .c_inner').css({clear: 'both'});
});

$(window).load(function(){
// purple background
  if(setHeight){
	cHeight = $('.slider').height();
	cOfset = $('.slider').offset();
	cTop = cOfset.top;
	mHeight = cHeight + cTop;
	$('#container').height(mHeight);
  } else if ($('#gallery .images').length < 1) {
	$('#footer .c_inner').css({clear: 'none'}).css({clear: 'both'});
  }
});

// show/hide image for reveal the photo functionality
function showImage() {
	$('#main_content').css({height: $('#main_content').height()});
	$('#main_content .slider').slideUp();
	$('#positioning_copy_link .inner').animate({top: '-75px', height: '75px'}, 'fast');
	$('.heading').animate({opacity: '.85'});
	$('.reveal').addClass('revealed');
}
function hideImage() {
	$('#positioning_copy_link .inner').animate({top: '0px', height: '0px'}, 'fast', function(){});
	$('#main_content .slider').slideDown();
	$('.heading').animate({opacity: '1'});
	$('.reveal').removeClass('revealed');
}

// check-out date should be updated automatically when check-in is changed
months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
function updateCheckOut() {
	checkIn = $('#qr_idate0').datepicker('getDate').getTime();
	tomorrow = new Date();
	tomorrow.setTime(checkIn + 86400000);
	checkOut = $('#qr_idate1').datepicker('getDate').getTime();
	$('#qr_idate1').datepicker( 'option' , 'minDate' , tomorrow );
	if ( checkIn >= checkOut ) {
		$('.jquery-selectbox-currentItem:eq(2)').html(months[tomorrow.getMonth()] + ' ' + tomorrow.getFullYear());
		$('.jquery-selectbox-currentItem:eq(3)').html(tomorrow.getDate());
		mnt = tomorrow.getMonth()+1;
		yer = tomorrow.getFullYear() % 100;
		if(mnt < 10) mnt = '0' + mnt;
		if(yer < 10) yer = '0' + yer;
		$('#monthyear1').val(mnt + ' ' + yer);
		tmrw = tomorrow.getDate()<10 ? '0' + tomorrow.getDate() : tomorrow.getDate()
		$('#day1').val(tmrw);
	}
}
