/*********************************
 210 Simcoe Website
 
 author    : Sandra Mansour
 date      : 11-Jul-2011
 file name : myscript.js

 Class PU52()
 
 Copyright 2011 52 Pick-up Inc.
 Do not use without permission
 info@52pick-up.com
 *********************************/

$(window).resize(function() {
  PU52.Subnavigation.hideSubNav();
});
 

if (typeof (PU52) == 'undefined')
    var PU52 = {};
    
   
/***
 Class Generic() - All global functions should be placed in this class.
 ***/
PU52.Generic = {
	initializeGMap: function(lat, lon) {
		var latlng = new google.maps.LatLng(lat, lon);
		var myOptions = {
	  		zoom: 16,
	  		center: latlng,
	  		draggable: true,
	  		mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("PU52-MapCanvas"), myOptions);
   		var mymarker = new google.maps.Marker({
      		position: latlng,
      		map: map
  		});
	}
}


/***
 Class Subnavigation()
 Handles show/hide of subnavigation menus. The menus will use the jQuery slideDown function
 ***/
PU52.Subnavigation = {
	/* constant variables */
	SUBNAVID: "PU52-Subnav", 	//[string] the id of the subnavigation Div
	
	/* variable declarations */
	_slide_in_progress: false,	//[boolean] indicates that a slide is in progress
	_curr_id: "",				//[string] the id of the currently displayed Sub Navigation
	_curr_menu_id: "",			//[string] the id of the currently selected Menu Item

	//function show() will slide down the specified menu represented by "ulID"
	show: function(thisObj, ulID)
 	{
	 	if (ulID != PU52.Subnavigation._curr_id)
	 	{
		 	PU52.Subnavigation._curr_id = ulID;

		 	//if a slide is in progress, immediately stop that slide
			if (PU52.Subnavigation._slide_in_progress)
			{
				$("#" + PU52.Subnavigation.SUBNAVID).stop(false, true);
				PU52.Subnavigation._slide_in_progress = false;
			}
			
			//hide both the UL and div elements:
			$("#" + PU52.Subnavigation.SUBNAVID + " ul").hide();
			$("#" + PU52.Subnavigation.SUBNAVID).hide();
	
			//check if this menu contains a sub-menu before continuing:
			if ($("#" + ulID).length > 0)
			{
				PU52.Subnavigation._slide_in_progress = true;
				
				$("#" + ulID).show();
				$("#" + PU52.Subnavigation.SUBNAVID).css('top', $(thisObj).offset().top + 35);
				$("#" + PU52.Subnavigation.SUBNAVID).css('left', $(thisObj).offset().left);
				$("#" + PU52.Subnavigation.SUBNAVID).slideDown('500', function(){
					PU52.Subnavigation._slide_in_progress = false;
	
					$("#" + PU52.Subnavigation.SUBNAVID).mouseout(function(e){
	      				PU52.Subnavigation.onmouseout(e.pageX, e.pageY);
	   				});
				});
			}
		}
	},
	
	//determines if the mouse is outside of the bounding box of the sub-navigation DIV:
	onmouseout: function(mouse_x, mouse_y)
	{
		var offset = 20;
		var box_x = $("#" + PU52.Subnavigation.SUBNAVID).offset().left; //x-coordinate of the sub-navigation DIV
		var box_y = $("#" + PU52.Subnavigation.SUBNAVID).offset().top - offset; //y-coordinate of the sub-navigation DIV
		var box_w = $("#" + PU52.Subnavigation.SUBNAVID).width();  //width of the sub-nav div
		var box_h = $("#" + PU52.Subnavigation.SUBNAVID).height(); //height of the sub-nav div
		
		if (mouse_x < box_x || mouse_x > (box_x + box_w) || mouse_y < box_y || mouse_y > (box_y + offset + box_h))
		{
			$("#" + PU52.Subnavigation.SUBNAVID).hide();
			PU52.Subnavigation._curr_id = "";
		}
	},
	
	//hides the subnavibation:
	hideSubNav: function()
	{
		$("#" + PU52.Subnavigation.SUBNAVID).hide();
	}
}


/***
 Class ThePlans()
 Handles show/hide of the Suites images.
 ***/
PU52.ThePlans = {
	//constant variables:
	SUITEID: "PU52-Suite",		//[string] id of the suites list-item
	PLANID: "PU52-Floorplan",	//[string] id of the floorplan image
	PLATEID: "PU52-Floorplate",	//[string] id of the floorplate image
	
	//variables:
	_prev_suite_id: 0,		//[integer] the ID of the last Suite that was displayed (initially, the first one is displayed)

	/***
	 displays a suite's floorplan and floorplate
	 ***/
	showSuite: function(id, sq_ft)
	{
		if (sq_ft == 0)
		{
			sq_ft = $("#" + PU52.ThePlans.SUITEID + id).text();
			sq_ft = sq_ft.substr(0, sq_ft.indexOf(' ', 0));
		}

		//hide the previous suite:
		$("#" + PU52.ThePlans.SUITEID + PU52.ThePlans._prev_suite_id).removeClass("selected");
		$("#" + PU52.ThePlans.PLANID + PU52.ThePlans._prev_suite_id).removeClass("selected");
		$("#" + PU52.ThePlans.PLATEID + PU52.ThePlans._prev_suite_id).removeClass("selected");

		//show the selected suite:
		$("#" + PU52.ThePlans.SUITEID + id).addClass("selected");
		$("#" + PU52.ThePlans.PLANID + id).addClass("selected");
		$("#" + PU52.ThePlans.PLATEID + id).addClass("selected");
		
		PU52.ThePlans._prev_suite_id = id; //set the new id
		$("#hdn_current_square_feet").val(sq_ft);
	},
	
	next: function()
	{
		PU52.Subnavigation.onmouseout(0,0);
		newId = PU52.ThePlans._prev_suite_id + 1 == $("#hdn_theplans_count").val() ? 0 : PU52.ThePlans._prev_suite_id + 1;
		PU52.ThePlans.showSuite(newId, 0);
	},
	
	previous: function()
	{
		PU52.Subnavigation.onmouseout(0,0);
		newId = (PU52.ThePlans._prev_suite_id == 0 ? $("#hdn_theplans_count").val() : PU52.ThePlans._prev_suite_id) - 1;
		PU52.ThePlans.showSuite(newId, 0);
	},
	
	openPDF: function()
	{
		PU52.Subnavigation.onmouseout(0,0);
		window.open("/files/PDF/fp_" + $("#hdn_current_square_feet").val() + ".pdf");
	}
}


/***
 Class Map()
 ***/
PU52.Map = {
	//constant variables:
	SECTIONID: "PU52-NHSection_",	//[string] the section ID
	SPEED: 500,						//[integer] the speed to slide sections up/down
	
	//variables:
	_prev_id: 1,					//[integer] id of the previously displayed section (initially set to 1)
	_slide_in_progress: false,		//[boolean] indicates if a slide is in progress
	
	//PU52-NHSection_1
	showSection: function(id)
	{
		if (!PU52.Map._slide_in_progress)
		{
			PU52.Map._slide_in_progress = true;
			$("#" + PU52.Map.SECTIONID + PU52.Map._prev_id).slideUp(PU52.Map.SPEED);
			$("#" + PU52.Map.SECTIONID + id).slideDown(PU52.Map.SPEED, function()
				{
					$("div.point.s_" + PU52.Map._prev_id).addClass('hide');
					$("div.point.s_" + id).removeClass('hide');
					PU52.Map._prev_id = id;
					PU52.Map._slide_in_progress = false;
				});
		}
	}
}
