/***********************
*  Site Specific JS   *
************************/

//Javascripts

//Content insert
$('#view_section_1').appendTo('#main-content');
$('.map-area').appendTo('.slider-area');

//Error insert
$('#error').appendTo('#main-content');
$('#error').wrap('<div class="intro-area">');

//Footer Map
function mapfooter() {
  var locations = [
			['Grafton',  -29.69179, 152.93359, 4, "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_a227b0b954.png"],
			['Maclean', -29.45572, 153.19665, 1, "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_a227b0b954.png"]
	];
    
  if ($('#map-footer').length > 0) {
	
	var map = new google.maps.Map(document.getElementById('map-footer'), {
		zoom: 9,
		scrollwheel: false,
		center: new google.maps.LatLng(-29.69179, 152.93359),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});
    
    var infowindow = new google.maps.InfoWindow();
    
    var bounds = new google.maps.LatLngBounds();
    
    for (i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
						position: new google.maps.LatLng(locations[i][1], locations[i][2]),
						icon: locations[i][4],
						title: locations[i][0],
            map: map
        });
    
        bounds.extend(marker.position);
    
        google.maps.event.addListener(marker, 'click', (function (marker, i) {
            return function () {
                infowindow.open(map, marker);
            }
        })(marker, i));
    }
    
    map.fitBounds(bounds);  
  
    var listener = google.maps.event.addListener(map, "idle", function () {
        map.setZoom(9);
        google.maps.event.removeListener(listener);
    });    
      
      google.maps.event.addDomListener(window, 'resize', function() {
			map.setCenter(new google.maps.LatLng(locations[0][0], locations[0][1]));
	  });  
      google.maps.event.addDomListener(window, 'orientationchange', function() {
			map.setCenter(new google.maps.LatLng(locations[0][0], locations[0][1]));
	  });  
  }
  
}

//Main Map
function mapcanvas() {
	var locations = [
			['Grafton',  -29.69179, 152.93359, 4, "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_a227b0b954.png"],
			['Maclean', -29.45572, 153.19665, 1, "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_a227b0b954.png"]
	];
    
  if ($('#map-canvas').length > 0) {
	
	var map = new google.maps.Map(document.getElementById('map-canvas'), {
		zoom: 10,
		scrollwheel: false,
		center: new google.maps.LatLng(-29.69179, 152.93359),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});
    
    var infowindow = new google.maps.InfoWindow();
    
    var bounds = new google.maps.LatLngBounds();
    
    for (i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
						position: new google.maps.LatLng(locations[i][1], locations[i][2]),
						icon: locations[i][4],
						title: locations[i][0],
            map: map
        });
    
        bounds.extend(marker.position);
    
        google.maps.event.addListener(marker, 'click', (function (marker, i) {
            return function () {
                infowindow.open(map, marker);
            }
        })(marker, i));
    }
    
    map.fitBounds(bounds);  
  
    var listener = google.maps.event.addListener(map, "idle", function () {
        map.setZoom(10);
        google.maps.event.removeListener(listener);
    });    
      
      google.maps.event.addDomListener(window, 'resize', function() {
			map.setCenter(new google.maps.LatLng(locations[0][0], locations[0][1]));
	  });  
      google.maps.event.addDomListener(window, 'orientationchange', function() {
			map.setCenter(new google.maps.LatLng(locations[0][0], locations[0][1]));
	  });  
  }
  
}

$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_b7dca76887.ico','http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_2971ab7ae6.png');
	
	menu.contactDetails({
		
		phone: '0266422300', //optional, can have multiple values[array] 
		mobile: null, //optional, can have multiple values[array]
		email: 'kendawes@y7mail.com', //optional, can have multiple values[array] 
		address: [['Grafton', '26 Prince Street Grafton NSW 2460'], ['Maclean', '14A River Street, Maclean NSW 2463']], //optional, single value
		hours: [
            ['Mon - Fri','9am - 5pm'],
            ['After Hours','on request']
        ] //optional
		
	});

	//Slider
    $("#slider").backstretch([
      "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_3af66111dd.jpg",
      "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_ba9b2d69a3.jpg",
      "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_640eb44083.jpg",
      "http://cdn.myld.com.au/2/739/dawes-ken-dental-prosthetist_1530603961.jpg"    
    ], {duration: 3000, fade: 750, random: true});

    //FAQ
    $('.faq-list').goFaq ();

    //Validation
    $('#custom_form').smartCaptcha({ 
        validateText: ["name", "comments", "phone"],
        validateEmail: ["email"],
        redirectLink: "http://api.jquery.com/jquery.fn.extend/",
        validateStyle: "default"
    }); 

    if ($('body#home').is('*')) {
        
    }
     
});  // end declaration

$(window).load(function(){

    //Footer Map
    mapfooter();
    //Main Map
    mapcanvas();
});
