$(document).ready(function() {
	$(".hide_contacted").click(function () {
		$("#fade_after").fadeOut("800");
	});
});

/*
 * opens link in new window
 */

$(function() {
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});
});

// News ticker

// News Ticker

	$(document).ready(function() {
		if ($('#ticker-area ul').length > 0){
			createTicker();
	  	}
	});
	
	function createTicker(){
		var tickerLIs = $("#ticker-area ul").children();
		tickerItems = new Array();
		tickerLIs.each(function(el) {
			tickerItems.push( jQuery(this).html() );
		});
		i = 0
		rotateTicker();
	}
	
	function rotateTicker(){
		if( i == tickerItems.length ){
		  i = 0;
		}
	  tickerText = tickerItems[i];
		c = 0;
		typetext();
		setTimeout( "rotateTicker()", 8000 );
		i++;
	}
	
	function typetext() {	
		var thisChar = tickerText.substr(c, 1);
		if( thisChar == '<' ){ isInTag = true; }
		if( thisChar == '>' ){ isInTag = false; }
		$('#ticker-area').html(tickerText.substr(0, c++) + '');
		if(c < tickerText.length+1)
			if( isInTag ){
				typetext();
			}else{
				setTimeout("typetext()", 28);
			}
		else {
			c = 1;
			tickerText = "";
		}	
	}

/*
 * function changeBox() and restoreBox() allows password text to be displayed in the password type input box
 */

function changeBox()
{
	document.getElementById('password1').style.display='none';
	document.getElementById('password2').style.display='';
	document.getElementById('password').focus();
}
function restoreBox()
{
	if(document.getElementById('password').value=='')
	{
		document.getElementById('password1').style.display='';
		document.getElementById('password2').style.display='none';
	}
}

/*
 * ALL AJAX STARTS HERE
 */
 
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
		
	return xmlhttp;
}

function getArea(strURL) {		
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('area_drop').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function getAddToPropertyFolder(strURL) {

	$('#property_list').fadeOut("fast");
	
	var req = getXMLHTTP();
	
	if (req) {
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('property_list').innerHTML=req.responseText;
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}	
		req.open("GET", strURL, true);
		req.send(null);
	}
	
	$('#property_list').fadeIn("slow");
	
}


function getBobCaptcha(strURL) {
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('bobcaptcha').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

function getBobCaptchaText(strURL) {
	
	var req = getXMLHTTP();
	
	if (req) {
		
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('bobcaptchatext').innerHTML=req.responseText;						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}			
}

/*
 * Property Folder
 */

$(document).ready(function() {
	$('#show_hide_folder').hide();
	$('a.show_folder').click(function() {
    $('#show_hide_folder').slideToggle(400);
    return false;
	});
	$('a.added_show_folder').click(function() {
    $('#show_hide_folder').slideDown(400);
    return false;
	});
});

$(document).ready(function() {
	$('#property_folder_form').hide();
	$('a.show_form').click(function() {
    $('#property_folder_form').toggle(400);
	$("a.show_form").toggleClass("less");
	$("a.show_form").toggleClass("more");
    return false;
	});
});

/*
 * Lightbox
 */
 
$(document).ready(function() {
	$('a.zoom').fancyZoom({directory: '/js/fancyzoom_images'});
});

// Faqs

SSS_faq = {
	init : function() {
		$('div.faq .answer').slideToggle('fast');
		$('div.faq .question').click(function() { 
                    SSS_faq.toggle(this) 
                });
	},
	
	toggle : function(elt) {
		$(elt).toggleClass('active');
		$(elt).siblings('.answer').slideToggle('fast');
	}
}

$(function() { 
	SSS_faq.init();
});

/*
 * UI Slider
 */



/*
 * Drag & Drop
 */
 
$(function() {

	$(".draggable").draggable({ 
		revert: 'invalid', 
		helper: 'clone', 
		scroll: false 
	});

	$("#droppable").droppable({
		activeClass: 'drag',
		hoverClass: 'drop',
		tolerance: 'touch',
		drop: function(event, ui) {
			// Get Property ID
			var propertyID = $(ui.draggable).attr("id").replace('property_id_','');
			
			
			//Opens Property Folder when property added by drag & drop
			$('#show_hide_folder').slideDown(400);
			
			// do our thing
			$.ajax({type:'GET',url:'property_folder_change.php',data:'action=add&property_id='+propertyID,success:
				
				function getAddToPropertyFolder(strURL) {		
				
					$('#property_list').fadeOut("fast");
	
					var req = getXMLHTTP();
					
					if (req) {
						
						req.onreadystatechange = function() {
							if (req.readyState == 4) {
								// only if "OK"
								if (req.status == 200) {						
									document.getElementById('property_list').innerHTML=req.responseText;
								} else {
									alert("There was a problem while using XMLHTTP:\n" + req.statusText);
								}
							}				
						}			
						req.open("GET", 'property_folder_change.php', true);
						req.send(null);
					}
					
					$('#property_list').fadeIn("slow");
				}
			}); // end ajax call to add to cookies
			
			
		}
	});

});

// Datepicker 

$(function() {
	$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' });
});

// Include other JS

function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}

IncludeJavaScript('swfobject.js');

// check terms agreed

$(function() {
   //button
   $("#check_terms").click(function(e){
       if(!$("#terms").is(':checked'))
       {
           alert("You must agree to our terms & conditions before creating an account."); 
           e.preventDefault();
       }
   });
});

