var $j = jQuery.noConflict();


pageName = '';
hl = new Object();

hl.pure_rooms =                        '/rooms-suites?icamp=LH-reservations-ss';
hl.guestroom =                         '/rooms-suites?icamp=LH-reservations-ss';
hl.junior_suite =                      '/rooms-suites?icamp=LH-reservations-ss';
hl.business_plan_double =              '/rooms-suites?icamp=LH-reservations-ss';
hl.executive_king_guestroom_double =   '/rooms-suites?icamp=LH-reservations-ss';
hl.executive_king_guestroom =          '/rooms-suites?icamp=LH-reservations-ss';
hl.pure_allergy_friendly_king_double = '/rooms-suites?icamp=LH-reservations-ss';
hl.pure_allergy_friendly_king =        '/rooms-suites?icamp=LH-reservations-ss';
hl.maps =                              '/map-directions';
hl.local_attractions =                 '/local-attractions';
hl.services_amenities =                '/services-amenities';
hl.weddings_celebrations =             '/weddings-celebrations';
hl.c_catering =                        '/weddings-celebrations';
hl.venues =                            '/weddings-celebrations';
hl.weddings =                          '/weddings-celebrations';
hl.bar_mitzvahs =                      '/weddings-celebrations';
hl.galas_proms =                       '/weddings-celebrations';
hl.personal_celebrations =             '/weddings-celebrations';
hl.holiday =                           '/weddings-celebrations';
hl.dining_entertainment =              '/dining-entertainment';
hl.meetings_groups =                   '/meetings-groups';
hl.meetings_catering =                 '/meetings-groups';
hl.venues =                            '/meetings-groups';
hl.meetings =                          '/meetings-groups';
hl.recognition =                       '/meetings-groups';
hl.executive_meeting_center =          '/executive-meeting-center';
hl.specials_packages =                 '/specials-packages';
hl.rooms_suites =                      '/rooms-suites';

$j(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>'
    }
    $j('#monthyear0').html(optM);
    $j('#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>'
    }
    $j('#monthyear1').html(optM);
    $j('#day1').html(optD);

    // replace the selects
    $j('select').selectbox();

// page name
if(pageName) {
	$j('body').removeClass().addClass(pageName);
	$j('a[href='+hl[pageName]+']').parent().addClass('active');
}

// positioning copy show/hide
	$j('.home #positioning_copy_link').click(function(){
		$j('#positioning_copy').animate({height: '330px'});
		$j('#positioning_copy_link .inner').animate({top: '0px', height: '0px'});
	});
	$j('.home #positioning_copy .close').click(function(){
		$j('#positioning_copy').animate({height: '0px'});
		$j('#positioning_copy_link .inner').animate({top: '-75px', height: '75px'});
	});

// reservations show/hide
	$j('#quick_reservations.colapsed').click(function(){
		$j(this).animate({height: '330px'}).parents(':first').removeClass('colapsed');
		$j('#quick_reservations .close').css({display: 'block'});
	});
	$j('#quick_reservations .close').click(function(){
		$j(this).css({display: 'none'});
		$j('#quick_reservations').animate({height: '80px'}).parents(':first').addClass('colapsed');
		return false;
	});

// top drop show/hide
	$j('#header .c_inner').click(function() {
		$j(this).slideUp();
		$j('#top_drop, #top_drop .inner').animate({height: '86px'});
		if(!setHeight)
			$j('#content').animate({marginTop: '-58px'});
	});

	$j('#header .close').click(function() {
		$j('#top_drop, #top_drop .inner').animate({height: '0px'});
		$j('#header .c_inner').slideDown(function(){$j('#header .c_inner').css({position: 'relative', zIndex: '10'})});
		if(!setHeight)
			$j('#content').animate({marginTop: '0px'});
	});

// load specials
	$j('.lead_rate').load('/gallery-src .lead_rate_src');
	$j('.scrollable').after('<div id="specials-src" style="display: none;"></div>')
	$j('#specials-src').load('/rotating-specials-src .copy', specialsOnLoad);

function specialsOnLoad() {
	$j('.navi').html('');
	$j('.scrollable').html('<div class="items"></div>')
	$j('#specials-src .textElement').each(function(){
		numItems = $j('#specials-src .textElement').length;
		ind = $j('#specials-src .textElement').index(this);
//		$j('.scrollable .items').append('<div class="i_special i_special'+ind+(ind==0?" visible":"")+'" style="display: none;">'+$j(this).html().replace('</p>', '<br />').replace(/<p>|<\/p>/g, '')+'</div>');
//		$j('.scrollable .items').append('<div class="i_special i_special'+ind+(ind==0?" visible":"")+'" style="display: none;">'+$j(this).html()+'</div>');
//		$j('.scrollable .items').append('<div class="i_special i_special'+ind+(ind==0?" visible":"")+'" style="display: none;">'+$j(this).html().replace(/&amp;/g, '&')+'</div>');
		$j('.scrollable .items').append('<div class="i_special i_special'+ind+(ind==0?" visible":"")+'"' +(ind==0?'':' style="display: none;"')+'>'+$j(this).html().replace(/&amp;/g, '&')+'</div>');
		$j('.navi').append('<span id="i_special_nav'+ind+'"'+(ind==0?' class="active"':'')+'></span>')
	});
	$j('.scrollable a').each(function(){
		this.target = '_blank';
	})

}

// highlights rotation
	$j('.navi span').live('click', function(){
		which = $j(this).attr('id').charAt(13);
		$j('.scrollable .items .visible').removeClass('visible').fadeOut("def", function(){
			$j('.i_special'+which).fadeIn().addClass('visible');
		});
		$j('.navi span').removeClass();
		$j(this).addClass('active');
		$j('.scrollable').stopTime('controlled').oneTime('5s', function(){$j('.scrollable').everyTime('5s', 'controlled', rotateSpecials);})
		whichAuto = which;
	});
	whichAuto = 0
	numItems = 3;
	$j('.scrollable').everyTime('5s', 'controlled', rotateSpecials);
	function rotateSpecials() {
		whichAuto++;
		whichAuto %= numItems;
		$j('.scrollable .items .visible').removeClass('visible').fadeOut("def", function(){
			$j('.i_special'+whichAuto).addClass('visible').fadeIn();
		});
		$j('.navi span').removeClass();
		$j('#i_special_nav'+whichAuto).addClass('active');
	}

// external links
	$j('a').each(function(){
		if($j(this).attr('rel')=='external') this.target = '_blank';
		if($j(this).html() == 'rfp') this.target = '_blank';
	});

// reveal the photo
	var imgRev = false;
	pCopy = $j('.seo_copy').text();
	if (pCopy.length > 0) {
		$j('#positioning_copy_link .inner').html('<p>' + pCopy + '</p>');
	} else {
		$j('#positioning_copy_link').not('.home #positioning_copy_link').html('');
	}
	$j('.reveal, #positioning_copy_link').not('.home #positioning_copy_link').click(function() {
		if(imgRev) {
			hideImage();
		} else {
			showImage();
		}
		imgRev = !imgRev;
	});

// hp background image rotation
	$j('.home #content .c_inner').before('<div id="bgr_wrap"><div id="hp_bgr0"></div></div>');

	bgr = $j.cookie('hpBgr')
	if(bgr) {
		$j('#hp_bgr0').css({backgroundImage : 'url(/Websites/hyattdulles/templates/HyattDulles/images/bgr_home'+bgr+'.jpg)'});
		bgr++; bgr %= 3;
		$j.cookie('hpBgr', bgr);
	} else {
		bgr = 0;
		$j.cookie('hpBgr', 1);
	}

	$j('#bgr_wrap').everyTime(7000, 'controlled', function(){
		$j('#hp_bgr0').after('<div id="hp_bgr1"></div>')
		$j('#hp_bgr1').css({display: 'none', backgroundImage : 'url(/Websites/hyattdulles/templates/HyattDulles/images/bgr_home'+bgr+'.jpg)' }).fadeIn(2500, function(){
			$j('#hp_bgr0').css({backgroundImage : 'url(/Websites/hyattdulles/templates/HyattDulles/images/bgr_home'+bgr+'.jpg)'});
			$j(this).remove();
			bgr++; bgr %= 3;
		});
	});



// datepicker
// display format oct 2009 2
// actual format  10 2009 02
	$j('#qr_idate0')
	.datepicker({ showAnim: 'slideDown', minDate: '+0', maxDate: '+1Y', dateFormat: 'mm y-dd', altField: '#qr_idate0alt', altFormat: 'M yy-d' })
		.change(function(){
			date0=$j('#qr_idate0').val().toLowerCase().split('-');
			date0alt=$j('#qr_idate0alt').val().toLowerCase().split('-');
			$j('.jquery-selectbox-currentItem:eq(0)').html(date0alt[0]);
			$j('.jquery-selectbox-currentItem:eq(1)').html(date0alt[1]);
			$j('#monthyear0').val(date0[0]);
			$j('#day0').val(date0[1]);
			updateCheckOut();
		})
	$j('#qr_idate0').datepicker('setDate', '+0');
	$j('#qr_date0').click(function(){$j('#qr_idate0').datepicker('show')});
	$j('#qr_idate1')
		.datepicker({ showAnim: 'slideDown', minDate: '+1', maxDate: '+1Y +1D', dateFormat: 'mm y-dd', altField: '#qr_idate1alt', altFormat: 'M yy-d' })
		.change(function(){
			date1=$j('#qr_idate1').val().toLowerCase().split('-');
			date1alt=$j('#qr_idate1alt').val().toLowerCase().split('-');
			$j('.jquery-selectbox-currentItem:eq(2)').html(date1alt[0]);
			$j('.jquery-selectbox-currentItem:eq(3)').html(date1alt[1]);
			$j('#monthyear1').val(date1[0]);
			$j('#day1').val(date1[1]);
		})
	$j('#qr_idate1').datepicker('setDate', '+1');
	$j('#qr_date1').click(function(){$j('#qr_idate1').datepicker('show')});


	$j('#monthyear0, #day0').change(function(){
		mnyr = $j('#monthyear0').val().split(' ');
		dte = new Date('20'+mnyr[1], mnyr[0]-1, $j('#day0').val());
		$j('#qr_idate0').datepicker('setDate', dte);
		updateCheckOut();
	});
	$j('#monthyear1, #day1').change(function(){
		mnyr = $j('#monthyear1').val().split(' ');
		dte = new Date('20'+mnyr[1], mnyr[0]-1, $j('#day1').val());
		$j('#qr_idate1').datepicker('setDate', dte);
		updateCheckOut();
	});

// cancel reservations form submission and open an url instead
	$j('#frm').submit(function(){
		uriel  = 'http://www.hyatt.com/HICBooking?pid=DULLE&adults=';
		uriel += $j('#adults').val();
		uriel += '&kids=';
		uriel += $j('#kids').val();
		uriel += '&rooms=';
		uriel += $j('#number').val();
		uriel += '&monthyear1=';
		uriel += $j('#monthyear0').val();
		uriel += '&day1=';
		uriel += $j('#day0').val();
		uriel += '&monthyear2=';
		uriel += $j('#monthyear1').val();
		uriel += '&day2=';
		uriel += $j('#day1').val();
		uriel += '&offercode=';
		if ($j('#offercodeprop').val() != 'special offer code') {
			uriel += escape($j('#offercodeprop').val());
		}
		uriel += '&corp_id=';
		if ($j('#groupcorporate').val() != 'group/corporate #') {
			uriel += escape($j('#groupcorporate').val());
		}
		uriel += '&icamp=RH-reservations-ss-dulle';
		window.open(uriel);
		return false;
	})


// input default value
	var active_color = '#fff';
	var inactive_color = '#e6c0cc';
	$j('input.default-value').css('color', inactive_color);
	var default_values = new Array();
	$j('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 = '';
		}
		$j(this).blur(function() {
			if (this.value == '') {
				this.style.color = inactive_color;
				this.value = default_values[this.id];
			}
		});
	});

//
	if(!setHeight)
		$j('#footer .c_inner').css({clear: 'both'});
});

$j(window).load(function(){

// purple background
  if(setHeight){
	cHeight = $j('.slider').height();
	cOfset = $j('.slider').offset();
	cTop = cOfset.top;
	mHeight = cHeight + cTop;
	$j('#container').height(mHeight);
  } else if ($j('#gallery .images').length < 1) {
	$j('#footer .c_inner').css({clear: 'none'}).css({clear: 'both'});
  }
});

// show/hide image for reveal the photo functionality
function showImage() {
	$j('#main_content').css({height: $j('#main_content').height()});
	$j('#main_content .slider').slideUp();
	$j('#positioning_copy_link .inner').animate({top: '-75px', height: '75px'}, 'fast');
	$j('.heading').animate({opacity: '.85'});
	$j('.reveal').addClass('revealed');
}
function hideImage() {
	$j('#positioning_copy_link .inner').animate({top: '0px', height: '0px'}, 'fast', function(){});
	$j('#main_content .slider').slideDown();
	$j('.heading').animate({opacity: '1'});
	$j('.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 = $j('#qr_idate0').datepicker('getDate').getTime();
	tomorrow = new Date();
	tomorrow.setTime(checkIn + 86400000);
	checkOut = $j('#qr_idate1').datepicker('getDate').getTime();
	$j('#qr_idate1').datepicker( 'option' , 'minDate' , tomorrow );
	if ( checkIn >= checkOut ) {
		$j('.jquery-selectbox-currentItem:eq(2)').html(months[tomorrow.getMonth()] + ' ' + tomorrow.getFullYear());
		$j('.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;
		$j('#monthyear1').val(mnt + ' ' + yer);
		tmrw = tomorrow.getDate()<10 ? '0' + tomorrow.getDate() : tomorrow.getDate()
		$j('#day1').val(tmrw);
	}
}

