
// on DOM ready

$(document).ready(function(){

	$('html').addClass('dom-loaded');

    
    $('a[rel*=external],#content a[href^=http://]:not([href*=' + location.hostname + '])", #pdf a').newWindow();
    
    if ($('body').hasClass('contact')) {
    
    
    
    
         $('#contact-form').validate({
	              rules: {
	                  'full-name': {
	                      required: true
	                  },
	                  email: {
	                      required: true,
	                      email: true
	                  },
	                  enquiry: {
	                      required: true
	                  }

	              },
	              errorPlacement: function(error, element) {
	                 element.parent().after(error);

	               }

	          });          

    } else if ($('body').hasClass('our-location')) {
    
        $('#primary-content').append('<div id="google-map" />');
    
        function LoadMapSearchControl() {
    
          var options = {
                zoomControl : GSmapSearchControl.ZOOM_CONTROL_ENABLE_ALL,
                title : "Limehouse",
                url : "http://www.limehouse.com",
                idleMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM,
                activeMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM
                }
    
          new GSmapSearchControl(
                document.getElementById('google-map'),
                "9-11 Newspaper Place, Maroochydore, Queensland 4558",
                options
                );
                
    
        };
        
        
        var $googleMap = $('#google-map');
        
        $googleMap.html('<p>Loading map...</p>');
        
        // arrange for this function to be called during body.onload
        // event processing
        GSearch.setOnLoadCallback(LoadMapSearchControl);
    
    };
    
    
   
    
    
    // add 'check our adverts' to the site
    
    $('#main-container').append('<span id="check-our-adverts">Check our Adverts</span>');

    var advertImages = [];
    $.getJSON( config.basePath + 'get-adverts/', function(images) {
       advertImages = images;      
    });

    $('#check-our-adverts').click(function() {
        $.slimbox(advertImages, 0);    
    });
    
       
});


// on window loaded



$(window).load(function(){  // window load

	$('html').addClass('window-loaded');
    
    
	//google analytics

	try {

		var pageTracker = _gat._getTracker('UA-693909-50');

		pageTracker._trackPageview();

	} catch(err) {
	   //alert('analytics error');
	}

});


// Open links in new window

 (function($){  
  $.fn.newWindow = function(options) {   
    var defaults = {
		titleText: 'Link opens in a new window'
	};	
	var options = $.extend(defaults, options);   
     return this.each(function() {  
	   var obj = $(this);
       if ( ! obj.is('a')) {
           return;
       };
	   if (options.titleText != '') {   
		   if (obj.attr('title')) {
				var newTitle = obj.attr('title') + ' (' + options.titleText + ')';
		   } else {
				var newTitle = options.titleText;   
		   };		   
		   obj.attr('title', newTitle);   
	   };
	   obj.click(function(event) {
	   	  event.preventDefault();  
		  var newBlankWindow = window.open(obj.attr('href'), '_blank');
		  newBlankWindow.focus();
		}); 
	   });
  };  
 })(jQuery); 
 
