
$(document).ready(function() {
	gallery_up_down();
	thumbonclick();
	start_easy_scroll();
	//floorplan_thumbonclick();
	//floorplan_start_easy_scroll();
	//make_email_property_form();
	//show_email_form();
});


function make_viewing_request_form() {
	
	try {
	
		var viewingRequestForm = new RPWViewingRequestFormObject(propertyDataObjectindex_php_RPW_property_details_obj);
		viewingRequestForm.titleStr = "";
		viewingRequestForm.formFields = "Name*,Telephone*,E-mail*,Address";
		viewingRequestForm.action = "moduleoutput&_moduleclass=RPW_property_details_obj&_moduleclasspath=classes/modules/rpw/&_process=request_viewing";
		viewingRequestForm.appendToElement(document.getElementById("viewing_here"));
		viewingRequestForm.displayContent();
		viewingRequestForm.autoPosition = false;
		
	}
	catch(err) {
		$('#viewing_here').html($('#viewing_here').html()+err);
		
	}

}




function make_email_property_form() {
	
try {
	
	var emailPropertyForm = new RPWEmailPropertyFormObject(propertyDataObjectindex_php_RPW_property_details_obj);
	emailPropertyForm.autoPosition = false;
	emailPropertyForm.titleStr = "My title";
	emailPropertyForm.message = "";
	emailPropertyForm.action = "moduleoutput&_moduleclass=RPW_property_details_obj&_moduleclasspath=classes/modules/rpw/&_process=email_property";

	//alert(emailPropertyForm);
	emailPropertyForm.appendToElement(document.getElementById("email_here"));	
	emailPropertyForm.displayContent();
}
catch(err) {
	$('#email_here').html($('#email_here').html()+err);
	//setTimeout("make_email_property_form()",500);
}
}

function show_email_form() {
	$("#email_link_open").hover(function () {
	    $(this).addClass('pointer');
	  }, 
	  function () {
		  $(this).removeClass('pointer');
	  });
	
	
	
	$("#email_link_open").click(function () {
		$('.RPWEmailPropertyForm').slideToggle("slow");
	});
	
}

function post_result_email_toggle() {
	$('.RPWEmailPropertyForm').slideToggle("slow");
	setTimeout("post_result_email_clear()",2000);
}

function post_result_email_clear() {
	$('#email_here').html('');
	make_email_property_form();
}


function thumbonclick() {
	$('.slideshow-thumbnail_item').live('mouseover mouseout', function(event) {
		  if (event.type == 'mouseover') {
			 // $(this).css("background-image","url(img/search_results/Gallery_Up_hover.gif)");
			  $(this).css("border","1px solid #f36b14");
			  $(this).addClass('pointer');
			  // do something on mouseover
		  } else {
			//  $(this).css("background-image","url(img/search_results/Gallery_Up.gif)");
			  $(this).css("border","1px solid white");
			  $(this).removeClass('pointer');
		  }
		});
	
	$('.slideshow-thumbnail_item').live('click', function(event) {
		var clicked_thumb_image = $(this).children('img').attr('src');
		var main_image_src = $('.gallery_slideshow_item').children('img').attr('src');
		$(this).children('img').attr('src',main_image_src);
		$('.gallery_slideshow_item').children('img').attr('src',clicked_thumb_image);
		
		
		});
	
	
	
	
}


function floorplan_start_easy_scroll() {

//this.easyscroll = function(){
	
	// id of the container element 
	var id = "floorplans_thumbnails_inner";
	
	// navigation buttons text
	var nav = ["Scroll Up", "Scroll Down", "Reset"];
	
	//	id for each navigation button (OPTIONAL)
	var navId = ["arrow_up", "arrow_down"];

	// movement speed
	var speed = 5;
	
	// desired height of the container element (in pixels)
	var height = 392;
	
	//
	// END CONFIG
	// do not edit below this line (unless you want to of course :) )
	//
	if (document.getElementById(id)) {
		var obj = document.getElementById(id);
		
		obj.up = false;
		obj.down = false;
		obj.fast = false;

		var container = document.createElement("div");
		var parent = obj.parentNode;
		container.id="floorplan_easyscroll";
		parent.insertBefore(container,obj);
		parent.removeChild(obj);	
		
		container.style.position = "relative";
		container.style.height = height + "px";
		container.style.overflow = "hidden";
		obj.style.position = "absolute";
		obj.style.top = "0";
		obj.style.left = "0";
		container.appendChild(obj);
		
		var btns = new Array();
		//var ul = document.createElement("ul");
		//ul.id="easyscrollnav";
		button_up = document.getElementById('floorplan_gallery_up');
		btns.push(button_up);
		button_down = document.getElementById('floorplan_gallery_down');
		btns.push(button_down);
		/*
		for (var i=0;i<nav.length;i++){
			var li = document.createElement("li");
			li.innerHTML = nav[i];
			li.id = navId[i];
			btns.push(li);
			ul.appendChild(li);
		};
		parent.insertBefore(ul,container);
		*/
		btns[0].onmouseover = function(){
			obj.up = true;
			//this.className = "over";
			//alert(1);
		};
		btns[0].onmouseout = function(){
			obj.up = false;
			//this.className = "";
			//alert(2);
		};		
		btns[1].onmouseover = function(){
			obj.down = true;
			//this.className = "over";
			//alert(3);
		};
		btns[1].onmouseout = function(){
			obj.down = false;
			//this.className = "";
			//alert(4);
		};		
		btns[0].onmousedown = btns[1].onmousedown = function(){
			obj.fast = true;
			//alert(5);
		};	
		btns[0].onmouseup = btns[1].onmouseup = function(){
			obj.fast = false;
			//alert(6);
		};	
		/*
		btns[2].onmouseover = function(){ 		
			this.className = "over";
		};	
		btns[2].onmouseout = function(){ 		
			this.className = "";
		};		
		btns[2].onclick = function(){ 		
			obj.style.top = "0px";
		};		
		*/	
			
			
		this.start = function(){				
			var newTop;
			var objHeight = obj.offsetHeight;
			var top = obj.offsetTop;
			var fast = (obj.fast) ? 2 : 1;
			if(obj.down){		 
				newTop = ((objHeight+top) > height) ? top-(speed*fast) : top;	
				obj.style.top = newTop + "px";
			};	
			if(obj.up){		 
				newTop = (top < 0) ? top+(speed*fast) : top;
				obj.style.top = newTop + "px";
			};
		};	
		obj.interval = setInterval("start()",50);		
		
		
	}
		
		
};





function floorplan_thumbonclick() {
	$('.floorplan-thumbnail_item').live('mouseover mouseout', function(event) {
		  if (event.type == 'mouseover') {
			 // $(this).css("background-image","url(img/search_results/Gallery_Up_hover.gif)");
			  $(this).css("border","1px solid #f36b14");
			  $(this).addClass('pointer');
			  // do something on mouseover
		  } else {
			//  $(this).css("background-image","url(img/search_results/Gallery_Up.gif)");
			  $(this).css("border","1px solid white");
			  $(this).removeClass('pointer');
		  }
		});
	
	$('.floorplan-thumbnail_item').live('click', function(event) {
		var clicked_thumb_image = $(this).children('img').attr('src');
		var main_image_src = $('.floorplan_slideshow_item').children('img').attr('src');
		$(this).children('img').attr('src',main_image_src);
		$('.floorplan_slideshow_item').children('img').attr('src',clicked_thumb_image);
		
		
		});
	
	
	
	
}






function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	  return false;
	}



function HideDIV(div_id) {
	//$('#'+div_id).slideUp('normal',function() {
		$('#'+div_id).hide();
		
	//});
	
	
}

function DisplayDIV(div_id) {
	//$('#'+div_id).slideDown();
	$('#'+div_id).show();
	
}


function floor_plan_click() {
	if ($('.icon-floor').attr("class") == 'icon-floor open') {
		floor_plan_alt_click();
		$('#property_details_main').css('border-top-width','0px');
	}
	else {
		$('.open').removeClass('open');
		$('.icon-floor').addClass('open');
	HideDIV('div_epc');
	HideDIV('div_map');
	HideDIV('div_streetview');
	//setTimeout("DisplayDIV('div_floorplan')",500);
	DisplayDIV('div_floorplan');
	$('#property_details_main').css('border-top-width','1px');
	
	}
	
	//alert('Floor plan was clicked');
}

function floor_plan_alt_click() {
	$('.icon-floor').removeClass('open');
	HideDIV('div_epc');
	HideDIV('div_map');
	HideDIV('div_streetview');
	HideDIV('div_floorplan');
	
	
	//alert('Floor plan alt was clicked');
}



function EPC_click() {
	if ($('.icon-epc').attr("class") == 'icon-epc open') {
		EPC_alt_click();
		$('#property_details_main').css('border-top-width','0px');
	}
	else {
		$('.open').removeClass('open');
		$('.icon-epc').addClass('open');
	HideDIV('div_map');
	HideDIV('div_streetview');
	HideDIV('div_floorplan');
	//setTimeout("DisplayDIV('div_epc')",500);
	DisplayDIV('div_epc');
	$('#property_details_main').css('border-top-width','1px');
	}
	
	//alert('EPC was clicked');
}


function EPC_alt_click() {
	$('.icon-epc').removeClass('open');
	HideDIV('div_map');
	HideDIV('div_streetview');
	HideDIV('div_floorplan');
	HideDIV('div_epc');
	

	//alert('EPC alt was clicked');
}




function Map_click() {
	//alert($('.icon-map').attr("class"));
	if ($('.icon-map').attr("class") == 'icon-map open') {
		Map_alt_click();
		$('#property_details_main').css('border-top-width','0px');
	}
	else {
		var myOptions = {
			    zoom: 14,
			    center: myLatlng,
			    mapTypeId: google.maps.MapTypeId.ROADMAP
			  }
			var image = 'img/prop_icon.gif';
		
		
		
		$('.open').removeClass('open');
		$('.icon-map').addClass('open');
		
		HideDIV('div_streetview');
		HideDIV('div_floorplan');
		HideDIV('div_epc');
		
		
		
		
			DisplayDIV('div_map');
			var map = new google.maps.Map(document.getElementById('map'), myOptions);  	
			var beachMarker = new google.maps.Marker({ position: myLatlng, map: map, icon: image });
		  
		$('#property_details_main').css('border-top-width','1px');
	}
	
	//alert('Map was clicked');
}

function Map_alt_click() {
	$('.icon-map').removeClass('open');
	HideDIV('div_streetview');
	HideDIV('div_floorplan');
	HideDIV('div_epc');
	HideDIV('div_map');
	

	//alert('Map alt was clicked');
}

function Street_view_click() {
	var panoramaOptions = {
			position: myLatlng,
		visible: true
		};
	
	
	if ($('.icon-street-view').attr("class") == 'icon-street-view open') {
		Street_view_alt_click();
		$('#property_details_main').css('border-top-width','0px');
	}
	else {
		$('.open').removeClass('open');
		$('.icon-street-view').addClass('open');
	HideDIV('div_floorplan');
	HideDIV('div_epc');
	HideDIV('div_map');
	//setTimeout("DisplayDIV('div_streetview')",500);
	DisplayDIV('div_streetview');
	var panorama = new google.maps.StreetViewPanorama(document.getElementById('sv-map'), panoramaOptions);
	var panorama = new google.maps.StreetViewPanorama(document.getElementById('sv-map'), panoramaOptions);
	
	$('#property_details_main').css('border-top-width','1px');
	}
	
	
	//alert('Street View was clicked');
}

function Street_view_alt_click() {
	$('.icon-street-view').removeClass('open');
	HideDIV('div_floorplan');
	HideDIV('div_epc');
	HideDIV('div_map');
	HideDIV('div_streetview');
	

	//alert('Street View alt was clicked');
}


function Brochure_click(link) {
	
	MM_openBrWindow(link,'print','toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600');
	
	//HideDIV('div_floorplan');
	//HideDIV('div_epc');
	//HideDIV('div_streetview');
	//HideDIV('div_map');
	
	//alert('Brochure was clicked');
}


function gallery_up_down() {
	$('.gallery_up').live('mouseover mouseout', function(event) {
		  if (event.type == 'mouseover') {
			  $(this).css("backgroundPosition","0px -74px");
			  $(this).addClass('pointer');
			  // do something on mouseover
		  } else {
			  $(this).css("backgroundPosition","0px 0px");
			  $(this).removeClass('pointer');
		  }
		});
	
	$('.gallery_down').live('mouseover mouseout', function(event) {
		  if (event.type == 'mouseover') {
			  $(this).css("backgroundPosition","0px -74px");
			  $(this).addClass('pointer');
			  // do something on mouseover
		  } else {
			  $(this).css("backgroundPosition","0px 0px");
			  $(this).removeClass('pointer');
		  }
		});
	
}


function start_easy_scroll() {
	
	//this.easyscroll = function(){
	
	// id of the container element 
	var id = "slideshow_thumbnails_inner";
	
	// navigation buttons text
	var nav = ["Scroll Up", "Scroll Down", "Reset"];
	
	//	id for each navigation button (OPTIONAL)
	var navId = ["gallery_up", "gallery_down"];

	// movement speed
	var speed = 5;
	
	// desired height of the container element (in pixels)
	var height = 392;
	
	//
	// END CONFIG
	// do not edit below this line (unless you want to of course :) )
	//
	if (document.getElementById(id)) {
		var obj = document.getElementById(id);
		
		obj.up = false;
		obj.down = false;
		obj.fast = false;

		var container = document.createElement("div");
		var parent = obj.parentNode;
		container.id="gallery_easyscroll";
		parent.insertBefore(container,obj);
		parent.removeChild(obj);	
		
		container.style.position = "relative";
		container.style.height = height + "px";
		container.style.overflow = "hidden";
		obj.style.position = "absolute";
		obj.style.top = "0";
		obj.style.left = "0";
		container.appendChild(obj);
		
		var btns = new Array();
		//var ul = document.createElement("ul");
		//ul.id="easyscrollnav";
		button_up = document.getElementById('gallery_up');
		btns.push(button_up);
		button_down = document.getElementById('gallery_down');
		btns.push(button_down);
		/*
		for (var i=0;i<nav.length;i++){
			var li = document.createElement("li");
			li.innerHTML = nav[i];
			li.id = navId[i];
			btns.push(li);
			ul.appendChild(li);
		};
		parent.insertBefore(ul,container);
		*/
		btns[0].onmouseover = function(){
			obj.up = true;
			//this.className = "over";
			//alert(1);
		};
		btns[0].onmouseout = function(){
			obj.up = false;
			//this.className = "";
			//alert(2);
		};		
		btns[1].onmouseover = function(){
			obj.down = true;
			//this.className = "over";
			//alert(3);
		};
		btns[1].onmouseout = function(){
			obj.down = false;
			//this.className = "";
			//alert(4);
		};		
		btns[0].onmousedown = btns[1].onmousedown = function(){
			obj.fast = true;
			//alert(5);
		};	
		btns[0].onmouseup = btns[1].onmouseup = function(){
			obj.fast = false;
			//alert(6);
		};	
		/*
		btns[2].onmouseover = function(){ 		
			this.className = "over";
		};	
		btns[2].onmouseout = function(){ 		
			this.className = "";
		};		
		btns[2].onclick = function(){ 		
			obj.style.top = "0px";
		};		
		*/	
			
			
		this.start_gallery = function(){				
			var newTop;
			var objHeight = obj.offsetHeight;
			var top = obj.offsetTop;
			var fast = (obj.fast) ? 2 : 1;
			if(obj.down){
				//alert('bob');
				newTop = ((objHeight+top) > height) ? top-(speed*fast) : top;
				/*
				if ((newTop*-1) > height) {
					newTop = (height+2)*-1;
				}
				*/
				//alert(newTop*-1);
				//alert(height);
				obj.style.top = newTop + "px";
				
			};	
			if(obj.up){		 
				newTop = (top < 0) ? top+(speed*fast) : top;
				if ((newTop*-1) < 0) {
					newTop = 0;
				}
				//alert(newTop*-1);
				//alert(height);
				
				obj.style.top = newTop + "px";
			};
		};	
		obj.interval = setInterval("start_gallery()",50);		
		
		
	}
		
		
}


