var apptTime = hour = qtrHour = '';
function setQuarter(pos){
	$('#quarterHour').css({
		left: pos
	});
};

function formAction(href){
	$('form#form').attr({ 
		action: href
	});
        
        $('form#form').submit();
};

function simple_tooltip(target_items, name, placement){
	
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
		var my_tooltip = $("#"+name+i);

		$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(100);
		}).mousemove(function(kmouse){	
			if(placement == 'viewNextBtn'){
				my_tooltip.css({left:kmouse.pageX-175, top:kmouse.pageY+15});
			}else{
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
			}
		}).mouseout(function(){
				my_tooltip.fadeOut(200);
		});
	});
}

$(document).ready(function(){
	
	/*-- Home Page Slideshow --*/
	$('#flashTwoImg').cycle({ 
	    fx: 'fade',
	    speed: 2500,
	    pause: 1
	});
	
	
	$('#nav li, #sideNav li').hover(function(){
		$(this).animate({ backgroundColor: '#5a778d' }, 300);

	}, function(){
		$(this).not('.currentPage').animate({ backgroundColor: '#002238' }, 500);

	});
	
	$('#selectDate input#selectDateInput').datepicker({
		dateFormat: 'D, M d, yy',	// Thurs, Apr 16, 2010
		minDate: 0			// Minimum valid date: 0 = Today
	});

	
	$('.dealsOfWeek').hover(function(){
		$('.dealsOfWeek').css({
			border: '5px inset #403a38'		
		});
	},function(){
		$('.dealsOfWeek').css({
			border: '5px outset #403a38'
		});
	});
	
	$('a.resLoginBtn').hover(function(){
		$('.resLoginBtn').css({
			border: '5px inset #5a778d'		
		});
	},function(){
		$('a.resLoginBtn').css({
			border: '5px outset #5a778d'
		});
	});
	
	$('div.applyBtn, a.applyOnline').click(function(){
		window.open('https://secure.resiteit.com/apps/?cid=143','','toolbar=no, location=no, status=yes, menubar=no, scrollbars=yes, resizable=yes, width=640 ,height=600');
	});
	
	$('ol#footerMenu li:last-child').css('border','none');
	
	
$('img.social').hover(function(){
	var thisId = $(this).attr('id');
	switch (thisId){
		case 'facebook':
			var src = ($(this).attr('src') === 'images/icon-F.jpg')
			? 'images/icon-F2.jpg'
			: 'images/icon-F.jpg';
		break;
		case 'twitter':
			var src = ($(this).attr('src') === 'images/icon-T.jpg')
			? 'images/icon-T2.jpg'
			: 'images/icon-T.jpg';
		break;
	};
	
	$(this).attr('src',src);		
});

/* -------------------------------------------------------- */
/* Side Menu */
	$('#nav ol#menu li, #sideNav ol#menu li, .dealsOfWeek, .social').click(function(){
			
		switch (this.id){
			case 'home':
				var href = 'index.php';
				break;
			case 'tour':
				var href = 'tour.php';
				break;
			case 'floorplans':
				var href = 'floorplans.php';
				break;
			case 'views':
				var href = 'views.php';
				break;
			case 'location':
				var href = 'location.php';
				break;
			case 'features':
				var href = 'features.php';
				break;
			case 'pricing':
				var href = 'pricing.php';
				break;
			case 'movein':
				var href = 'movein.php';
				break;
			case 'contact':
				var href = 'contact.php';
				break;
			case 'deals':
				var href = 'special.php';
				break;
			case 'facebook':
				var href = 'http://www.facebook.com/pages/Chicago-IL/Park-View-Apartments/91331176947';
				break;
			case 'twitter':
				var href = 'http://twitter.com/parkviewchicago';
				break;
		};
		
		formAction(href);
	});

	$('#submitChoice, #submitBtn').bind({
		click: function(){
			var $time = $('label#hour').text()+':'+$('label#minute').text()+$('label#ampmHour').text();
			var $date = $('#selectDateInput').val();
			formAction('contact.php?apptDate='+$date+'&apptTime='+$time);
		}
	});

/* -------------------------------------------------------- */
/* Time Picker */
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
/* NOT READY YET FOR IE >:-( AS OF 04.16.2010 */
var brow=(navigator.appName).substr(0,9);

if(brow != 'Microsofts'){
	$('#timeWrapper').css({'opacity':0.5,'background-color':'black'});
	
	$('#selectTime').click(function() {
		//$('#selectTime p').hide();
		$('#ampmHour').html('');
		$('#timeWrapper, #appointment #timeBox, #sideAppointment #timeBox, .time').slideDown('slow');
		return false;
	});
	
	$('#quarterHour').css({
		top: 57,
		left: 10,
		display: 'block'
	});
	
	$('#ampm li').hover(function(){
		$(this).siblings().css('backgroundColor', '#1a3b55');
		$(this).css('backgroundColor', '#5a778d');
		setQuarter($(this).position().left);
		$('#ampmHour').html($(this).text());
		apptTime = '';
		apptTime = $(this).text();
		
		if($(this).attr('id')=='am'){
			$('#pmHours').hide();
			$('#amHours').show();
			var startAmPm = '08:00 ';
		}else{
			$('#amHours').hide();
			$('#pmHours').show();
			var startAmPm = '12:00 ';
		}
		$('#selectedTime').html('');
		$('#selectedTime, .time').html(startAmPm+apptTime);
	});
	
	$('.timeWarp li').hover(function(){
		setQuarter($(this).position().left);
		if($(this).parent().attr('id')=='amHours'){			
			$('#ampm li#am').focus().css('backgroundColor', '#5a778d');
		}else if($(this).parent().attr('id')=='pmHours'){			
			$('#ampm li#pm').focus().css('backgroundColor', '#5a778d');
		}
		hour = '';
		hour = $(this).text();
		if(!apptTime){
			apptTime = 'am';
		}
		$('#selectedTime, .time').html(hour+':00 '+apptTime);
		$('.timeWarp li').css('backgroundColor', '#1a3b55');
		$(this).css('backgroundColor', '#5a778d');
	}, function(){
		$(this).css('backgroundColor', '#1a3b55');
	});
	
	$('#quarterHour li').hover(function(){
		qtrHour = '';
		qtrHour = $(this).text();
		$('#selectedTime, .time').html(hour+':'+qtrHour+' '+apptTime);
		$(this).css('backgroundColor', '#5a778d');
		var hourID = $('#selectedTime').text().substr(0,$('#selectedTime').text().indexOf(':'));
		$('#'+hourID).css('backgroundColor', '#5a778d');
	}, function(){
		$(this).css('backgroundColor', '#1a3b55');	
		var hourID = $('#selectedTime').text().substr(0,$('#selectedTime').text().indexOf(':'));
		$('#'+hourID).css('backgroundColor', '#5a778d');
	});
	
	$('html').click(function(){
		if($('label#hour').text() == '00'){
			$('.time').hide();
			$('#selectTime p').show();
		}else{
			$('#selectTime p').hide();
		}
		$('#timeWrapper, #timeBox').hide('slow');		
	});
}
/* -------------------------------------------------------- */
/* Virtual Tour */
	$('#imageTitle').css({'opacity':0.5,'background-color':'black'});
	
	$('ol#virtualTourList div.windowView').hover(function() {
		$(this).children('.viewBtn').css('background','#5a778d');
	}, function(){		
		$(this).children('.viewBtn').css('background','#1a3b55');
	});
	
	$('ol#virtualTourList li').click(function(){		
		formAction($('.viewLabel a',this).attr('href'));
	});

/* -------------------------------------------------------- */
/* Panorama viewButtons for Next/Previous images            */
/* -------------------------------------------------------- */
$('.viewBtns').hover(function(){
	simple_tooltip(".viewBtns","tooltip", this.id);
	
	if(this.id == 'viewNextBtn'){
		$('.tooltip p').text('Next Image');
	} else {
		$('.tooltip p').text('Previous Image');
	}
		
});

$('.viewBtns').click(function(){
	$("#" + $currentImg).removeClass('viewing');
	if(this.id == 'viewNextBtn'){
		$currentImg++;
		if($currentImg > $photoNmbr){
			$currentImg = 0;	
		}
	} else {
		$currentImg--;
		if($currentImg < 0){
			$currentImg = $photoNmbr;
		}
	}
	$('#viewImage img').attr('src','photo/'+viewPhotos[$currentImg]);
	
	$("#" + $currentImg).addClass('viewing');
});


/* -------------------------------------------------------- */
/* Pricing */
$('table#priceTable tr:not([th]):odd').css({'background-color':'#a39f9f'});
$('table#priceTable tr:not([th]):even').css({'background-color':'#c0c0c0'});

$('a[href*=".pdf"]').click(function(){
	window.open(this.href);
	return false;
});

$('table#priceTable tr').hover(function(){
	$('td', this).addClass('trOver');
	}, function() {
	$('td',this).removeClass('trOver');
}).click(function() {
	$('td').removeClass('trClick');
	$('td', this).toggleClass("trClick");
});

/* -------------------------------------------------------- */
/* */
});/* End of jQuery */

