$().ready(function() {
	$('.printBtn').removeAttr('href');
	$('.hd a').removeClass('printBtn').addClass('trigger print');
	$('.bd a').attr('href', '');
	$('.sitemap').attr('target','_blank');
	
		
	var $thisIdForIE = '';
	//sets up all the modal craziness
	$('.jqmWindow').jqm( { 
		toTop:true, 
		onShow: function(h) {
			h.w.slideDown("slow"); 
		},
		onHide: function(h) {
			h.w.slideUp("slow",function() { if(h.o) h.o.remove(); });
				
			if($.browser.msie && parseInt($.browser.version)>=6){
				$('body').css('width','805px');
			}
		}	
	});
	
	$('.unitType').hover(
		function () {
			$(this).addClass('selectLine');
		},
		function () {
			$(this).removeClass('selectLine');
		}
	);
	
	//assign the proper trigger for each modal we want to open
	/*
	$('.trigger').click(function thisIE() {
		var thisId = $('.thefpUTypeID').val();
		thisId = thisId.substring(9);
		$thisIdForIE = thisId;
		$('#dialog'+thisId).jqmShow();
		$('#modalFooter').show();
		var fpAreaX = $('.floorPlanArea').width();
		var fpAreaY = $('.floorPlanArea').height();
		var fpImageX = $('img.jqmFloorPlan').width();
		var fpImageY = $('img.jqmFloorPlan').height();
		if(fpAreaX < fpImageX){ $('img.jqmFloorPlan').width(fpAreaX); }
		if(fpAreaY < fpImageY){ $('img.jqmFloorPlan').height(fpAreaY); }
		// all this mess is for IE6
		
		if($.browser.msie && parseInt($.browser.version)>=6 ){
		
		$('.jqmOverlay').css({opacity: 1.0});
		
		$('#main,#footer').hide();
		}
	});
	*/

	$('.trigger').click (
		function (event) {
			event.preventDefault();
			window.print();
		}
	);

	
	$('.printBtn').click(function(){
			$('.jqmWindow #modalFooter').hide();
			
			if($.browser.msie && parseInt($.browser.version)>=6 ){
			document.location.href='floorPlans_IE.php?fpID='+$thisIdForIE+'&cid='+$('#secret').val();	
			}
			else {
				var thisId = $('.closeButton').attr('id').substring(5);
				$('.jqmOverlay').css({opacity: 1.0});
				$('#main').hide();
				window.print();			
				$('#main, #footer').show();
				$('#dialog'+thisId).jqmHide();
				$('.jqmWindow #modalFooter').show();
			}
	});
	
	
	$('.closeButton').click(function() {
		var thisId = this.id;
		thisId = thisId.substring(5);
		$('#dialog'+thisId).jqmHide();
		$('#dialog'+thisId).hide();
		//for ie6	
		if($.browser.msie && parseInt($.browser.version)>=6){
			$('body').css('width','805px');
			$('#main,#footer').show();
			
			
		}
	});	

	
});

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".jqmWindow").height();
	var popupWidth = $(".jqmWindow").width();
	//centering
	$(".jqmWindow").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	/*
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	return(popupWidth);
	*/
}
