// Document Ready function to fire main feature
 $(document).ready(function() {
   //Sales View Switching Function
   $("a.switch_thumb").click(function () {
	  $("a.switch_thumb").toggleClass("swap");
	  $("ul.display").fadeOut("fast", function() {
	    $(this).fadeIn("fast").toggleClass("thumb_view");
	  });
	
	  $.cookie('view_State', $('ul.display').is('.thumb_view') ? 'list' : 'thumbs' );
	}); 
	
	// COOKIES
	// view state
	var view_State = $.cookie('view_State');
	// Set the user’s selection for the viewState
	if (view_State == 'thumbs') {
	  $("ul.display").addClass("thumb_view");
	  $("span.switch_thumb").addClass("swap");
	};
	
	//rentals View Switching Function
   $("a.rentals_thumb").click(function () {
	  $("a.rentals_thumb").toggleClass("swap");
	  $("ul.propertyList").fadeOut("fast", function() {
	    $(this).fadeIn("fast").toggleClass("thumb_view");
	  });
	
	  $.cookie('view_StateRentals', $('ul.propertyList').is('.thumb_view') ? 'list' : 'thumbs' );
	}); 
	
	// COOKIES
	// view state
	var view_StateR = $.cookie('view_StateRentals');
	// Set the user’s selection for the viewState
	if (view_StateR == 'thumbs') {
	  $("ul.propertyList").addClass("thumb_view");
	  $("span.rentals_thumb").addClass("swap");
	};


});

	
function drawMap($name, $loc, $address, $phone, $fax, $lat, $long) {
   var $caption = "<div style='margin:4px;'><p class='red'>"+$name+"</p>"+"<p class='small'>"+$address+"</p><p class='small'><span class='red'>P+ </span>"+$phone+"&nbsp;<span class='red'>F+ </span>"+$fax+"</p></div>";
   
   $("#"+$loc).gMap({ markers: [{ 
				  longitude:  $long,
    			  latitude:  $lat,
    			  mapTypeControl: false,
    			  icon: { image: "assets/images/wb_marker.png",
                          iconsize: [32, 37],
                          iconanchor: [12,46],
                          infowindowanchor: [3, 0] },
				  html: $caption,
				  popup: true}],
		  		  zoom: 16 });
	}
	
function openCMS()  {
	window.open("http://www.diaryonline.com.au/login/member_login.php", "Member", "toolbar=0,status=1,location=no,menubar=no,directories=no,scrollbars=no,resizable=no,screenX=0,screenY=0,left=0,top=0,width=1014,height=682")
  }

var timeout	= 500;
var closetimer	= 0;
var menuitem	= 0;

// open hidden layer
function mopen(id) {	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(menuitem) menuitem.style.visibility = 'hidden';

	// get new layer and show it
	menuitem = document.getElementById(id);
	menuitem.style.visibility = 'visible';
}

// close showed layer
function mclose() { if(menuitem) menuitem.style.visibility = 'hidden';}

// go close timer
function mclosetime() { closetimer = window.setTimeout(mclose, timeout);}

// cancel close timer
function mcancelclosetime() { if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose; 

/* Scroller used on the index page to animate the 'Agent Finder' */
(function($) {

$.fn.scroll = function(options) {
	
	// For each item in the wrapped set, perform the following. 
	return this.each(function() {	
	  
		var
		  // Caches this - or the ul widget(s) that was passed in.
		  //  Saves time and improves performance.
		  $this = $(this), 
		  
		  // If the user doesn't pass in parameters, we'll use this object. 
		  defaults = {
		  	speed: 400, // Scroll speed
		  	delay: 3000, // Pause duration
		  	pauseOnHover: true,
		  	list_item_height: $this.children('li').outerHeight() // How tall is each list item? If this parameter isn't passed in, jQuery will grab it.
	     },
	      // Create a new object that merges the defaults and the 
	      // user's "options".  The latter takes precedence.
		  settings = $.extend({}, defaults, options);
		 
	  // This sets an interval that will be called continuously.
	  setInterval(function() {
	  	    // Get the very first list item in the wrapped set.
	  	    $this.children('li:first')
				.css('display', 'none')
				// Animate it
				.animate({ 
					marginTop : '-' + settings.list_item_height, // Shift this first item upwards.
					left: 0 }, 
				 
				   // Over the course of however long is passed in. (settings.speed)
				   settings.speed, 
				   
				   // When complete, run a callback function.
				   function() {
					
					// Get that first list item again. 
						$this.children('li:first')
							 .appendTo($this) // Move it the very bottom of the ul.
							 
							 // Reset its margin top back to 0. Otherwise, 
							 // it will still contain the negative value that we set earlier.
							 .css('marginTop', 0)
							 .css('display', 'inline-block'); // Return DIV to display.
  		 			  }
 	 			  ); // end animate
 	  }, settings.delay); // end setInterval
 	  
 	    //For pauseOnHover setting
        if(settings.pauseOnHover){
          $this.hover(function(){
            $this.children()
            .animate({ left: 0 },16000, function() { // Animation complete.
  				});
             }, function(){
                //Restart    
            });
        }
        
	  });

}

})(jQuery);

