
jQuery.fn.reorder = function() {

  // random array sort from
  // http://javascript.about.com/library/blsort2.htm
  function randOrd() { return(Math.round(Math.random())-0.5); }

  return(jQuery(this).each(function() {
    var $this = jQuery(this);
    var $children = $this.children();
    var childCount = $children.length;

    if (childCount > 1) {
      $children.remove();

      var indices = new Array();
      for (i=0;i<childCount;i++) { indices[indices.length] = i; }
      indices = indices.sort(randOrd);
      jQuery.each(indices,function(j,k) { $this.append($children.eq(k)); });

    }
  }));
}

jQuery(document).ready(function($){


	//Search
	$("#searchbutt").attr("value","");
	$("#s").focus(function() {
		$(this).attr("value","");
	});

	//Nav Highlight
	 $("#tnav li a").mousemove(function(e){

				mousex = e.pageX - this.offsetLeft - 75;
				mousey = e.pageY - this.offsetTop - 60;
				mouse = mousex + 'px ' + mousey + 'px';
				$(this).css('background-position',mouse)
			});

	 $('#portlist li:nth-child(5n)').css('margin-right','0');


	//Project Slideshow
	$('#slideshow').cycle({
			fx:     'fade',
			random: 1
	});

	//LIghtbox
	$("a[rel*='lightbox']").lightBox();

	//Cufon
	Cufon.replace('h2', {
		textShadow: '#0d1137 0 2px 2px',
		hover: true
	});
	Cufon.now();

	// SWFObject embed
	var flashvars = {}
	var params = {
		allowfullscreen: "true",
		wmode: "transparent"
	}
	var attributes = {
		id: "ssp"
	}

	if ($('#map').length) {
		showAddress('35 Buckingham St Surry Hills NSW Australia');
	}

	$("#testlist").reorder();

});

function showAddress(address) {

	var map = null;
	var geocoder = null;
	var myicon = new GIcon(G_DEFAULT_ICON);
	myicon.image = "/images/map_marker.png";
	myicon.iconSize = new GSize(42, 42);
	myicon.iconAnchor  =  new GPoint(42,0);
	markerOptions = { icon:myicon };

	geocoder = new GClientGeocoder();
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {

			if (GBrowserIsCompatible()) {
				map = new GMap2(document.getElementById("map"));
				map.setCenter(point, 15);
				//map.setCenter(new GLatLng(-33.878918, 151.224849), 12);
				var marker = new GMarker(point, markerOptions);
				map.addOverlay(marker);
				map.addControl(new GMapTypeControl());
				map.addControl(new GSmallMapControl());

			}

		}
          }
        );
      }
 }
	/*
	 *
	 * //<![CDATA[

				if (GBrowserIsCompatible()) {
					var map = new GMap2(document.getElementById("map"));
					map.addControl(new GMapTypeControl());
					map.addControl(new GSmallMapControl());
					//map.setCenter(new GLatLng(-33.893005, 151.249002), 14);
					//var marker = new GMarker(new GLatLng(-33.890687, 151.244169));
					map.setCenter(new GLatLng(-33.878918, 151.224849), 13);
					var marker = new GMarker(new GLatLng(-33.887025, 151.207590));
					map.addOverlay(marker);
				}

				//]]>
				</script>
	 */
