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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1164/o-reilly-dental_de8abc7f13.png');
	
	menu.contactDetails({
		
		phone: '0749262448', //optional, can have multiple values[array] 
		mobile: null, //optional, can have multiple values[array]
		email: 'reception@oreillydental.com.au', //optional, can have multiple values[array] 
		address: '80 High Street North Rockhampton Qld 4701', //optional, single value
		hours: [['Monday','8:00am-5:00pm'],['Tuesday','8:00am-7:00pm'],['Wednesday','8:00am-5:00pm'],['Thursday','8:00am-5:00pm'],['Friday','8:00am-4:00pm'],['Saturday','8:00am-1:00pm']] //optional
		
	});
  
     // View section_1
    $('#view_section_1').insertBefore('.footer');

    // View error div
    $('#error').insertBefore('.footer');    
  
  
    
    
    // Or, to start a slideshow, just pass in an array of images
    $("#slider").backstretch([
      "http://cdn.myld.com.au/2/1160/o-reilly-dental_cce2c12177.jpg",
      "http://cdn.myld.com.au/2/1160/o-reilly-dental_8aaf568af8.jpg",
      "http://cdn.myld.com.au/2/1160/o-reilly-dental_bb63d51292.jpg",
      "http://cdn.myld.com.au/2/1076/o-reilly-dental_f2fed5bb8a.jpg"
    ], {duration: 3000, fade: 750, random: true});   
        
    // match height
    $('.match').matchHeight();
    
    // gallery
    if ( $("body#gallery").is("*") ) {    
        if(Modernizr.touch && $(".fancybox").length > 0 )
        {
           var myPhotoSwipe = $(".fancybox").photoSwipe({ enableMouseWheel: false , enableKeyboard: false });
        }
        else
        {
        /* Apply to single image */
            $("a.fancybox").fancybox();
    
        /* Apply fancybox to multiple items */
            $("a.fancybox[rel='gallery_group']").fancybox({
                'transitionIn'    :    'elastic',
                'transitionOut'    :    'elastic',
                'speedIn'        :    600,
                'speedOut'        :    200
            });
    
        /* Apply with thumbnails visible */
            $("a.fancybox").fancybox({
                  helpers : {
                       thumbs : {
                            width: 200,
                            height: 200
                       }
                  }
            });
        }    
    }
    
    
    // services
    if ( $("body#services").is("*") ) {
      
        // Javascript to enable link to tab
        var url = document.location.toString();
        if (url.match('#')) {
            $('#tabber .nav > li > a[href=#'+url.split('#')[1]+']').tab('show') ;
        }

        // Change hash for page-reload
        $('#tabber .nav > li > a').on('shown.bs.tab', function (e) {
            window.location.hash = e.target.hash;
        })

        window.scrollTo(0, 0);

      $(window).load(function(){
        // Remove the # from the hash, as different browsers may or may not include it
        var hash = location.hash.replace('#',''),
            hash_value = location.hash;

        if(hash != ''){

           // Clear the hash in the URL
           // location.hash = '';   // delete front "//" if you want to change the address bar
            $('html, body').animate({scrollTop: $(hash_value).offset().top -350 }, 'slow');

           }
       });        
      
    }
    
    
    // contact
    if ( $("body#contact").is("*") ) {

        // Contact Form
        $('#contact_form').smartCaptcha({
            validateText: ["name","message"],
            validateEmail: ["email"],
            redirectLink: null,
            validateStyle: "default"
        });

        // Remove Slider
        $('#slider-wrap').remove();

        // Map
        function map() {
          var myLatlng = new google.maps.LatLng(-23.35879, 150.52648);
          var image = 'http://cdn.myld.com.au/2/1164/o-reilly-dental_9113b22ab2.png';
          var mapOptions = {
            scrollwheel: false,
            zoom: 18,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          }

          if ($('#map').length > 0) {
              var map = new google.maps.Map(document.getElementById('map'), mapOptions);

              var marker = new google.maps.Marker({
                  position: myLatlng,
                  map: map,
                  icon: image
              });

              google.maps.event.addDomListener(window, 'resize', function() {
                    map.setCenter(myLatlng);
              });         
              google.maps.event.addDomListener(window, 'orientationchange', function() {
                    map.setCenter(myLatlng);
              });   
            }
        }
        $(window).load(function(){
            map();
        });        
        
    }    
     
}); 
