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

/***********************
*  Site Specific JS   *
************************/

$(document).ready(function(){
    $.favicon('http://cdn.myld.com.au/2/1311/skinfit_f9f6c61b42.png');

    menu.contactDetails({

        phone: '0455120222', //optional, can have multiple values[array]
        email: 'skinfit@girlfit.com.au', //optional, can have multiple values[array]
        address: 'Shop 3 45-49 First Avenue Sawtell NSW 2452', //optional, single value
        hours: [['Mon','10am - 5pm'],['Tue','9am - 5pm'],['Wed','9am - 5pm'],['Thu','9am - 7pm'],['Fri','9am - 5pm'],['Sat','9am - 2pm']] //optional

    }); 
    
    $('h1, h2, h3, h4, h5 , h6').attr('itemprop','name');
    $('p').attr('itemprop','description');
    $('.container').attr('itemtype','http://schema.org/LocalBusiness');
    $('.container-fluid').attr('itemtype','http://schema.org/LocalBusiness');
    $('img').attr('itemprop','image');
    
    $(document).ready(function() {
      $('#tabs-nav>li>a').on('click', function (e) {
        e.preventDefault();
        $(this).tab('show');
        $(".tab-content2 > div").each(function(i, e) {
            $(e).hide();
        });
        $(this.getAttribute('href') + "_2").show();
      });
    });

    //Contact Page
    if ( $("body#contact-us").is("*") ) {
      // Contact Form
      $('#contact_form').smartCaptcha({ 
          validateText: ["name"],
          validateEmail: ["email"],
          validateChar: [{ id: "message", max: null }],
          validateRange: [{ id: "phone", limit: [3,13] }],
          redirectLink: null,
          validateStyle: "default"
      });
    }

    //Homepage
    if ( $("body#home").is("*")) {
        $('.parallax-window').parallax({imageSrc: 'http://cdn.myld.com.au/2/1310/skinfit_caefde6ed3.jpg'});
        //Banner
        $("#header").backstretch([
          "http://cdn.myld.com.au/2/1308/skinfit_8d69bdc206.jpg",
          "http://cdn.myld.com.au/2/1308/skinfit_ddcb21d351.jpg",
          "http://cdn.myld.com.au/2/1308/skinfit_b9e56f0250.jpg",
          "http://cdn.myld.com.au/2/1308/skinfit_33b0f5fa35.jpg"
        ], {duration: 3000, fade: 750, random: true});
    } else {
      //Banner
      $("#header").backstretch([
        "http://cdn.myld.com.au/2/1308/skinfit_8d69bdc206.jpg"
      ], {duration: 3000, fade: 750, random: true});
    }
    
    //VIEW SECTION 1
    $('#view_section_1').insertAfter('#header');
    //$('#view_section_1').append('#content-container');

    //VIEW ERROR DIV
    $('#error').insertAfter('#view_section_1');
    //$('#error').append('#content-container');

});


$(window).load(function() {
  $("body").addClass("loaded");
  $('#fbFeed').append('<iframe src="http://www.facebook.com/plugins/likebox.php?id=751654721540509&amp;connections=4&amp;width=350&amp;height=350&amp;stream=true&amp;header=false&amp;" height="350" scrolling="no" frameborder="0" style="background: #252525;float:left; border:none; overflow:hidden; width:350px; margin:0 auto; height:350px;"></iframe>');
});


/* Wait until the page has rendered to set the #jmm-content background to transparent so the parallax mirror elements can show through */
$(window).load(function() {
  $('#jmm-content').css({"background": "transparent"});
});


/* The following function is only for the Snippets example - DO NOT USE IN A PRODUCTION SITE WITHOUT A DEBOUNCE OR SIMILAR FUNCTION FOR THE RESIZE TRIGGER */
$(function() {
  $(window).resize(function() {
    var parallaxHeight = Math.max($(window).height() * 0.7, 200) | 0;
    $('.parallax-window').height(parallaxHeight);
  }).trigger('resize');
});

$(window).load(function(){

  // Javascript to enable link to tab
  var url = document.location.toString();
  if (url.match('#')) {
  $('.nav-justified a[href=#'+url.split('#')[1]+']').tab('show') ;
  }

  // Change hash for page-reload
  $('.nav-justified a').on('shown.bs.tab', function (e) {
  window.location.hash = e.target.hash;
  })


  // 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 -100 }, 'slow');

  }


  //check if hash tag exists in the URL
  if(window.location.hash) {
      
      //set the value as a variable, and remove the #
      var hash_value = window.location.hash.replace('#', '');
      $('#tabs-nav li.active').removeClass('active');
      $('#tabs-nav li a[href=#'+hash_value+']').closest('li').addClass('active');
      $('.tab-content .active').removeClass('active');
      $('.tab-content2 > div').css('display', 'none');
      $(".tab-content #"+hash_value).addClass('active');
      $(".tab-content2 #"+hash_value+"_2").css('display', 'block');
      $('html, body').animate({scrollTop: $('.tab-content').offset().top -30 }, 'slow');
  }

});

function defaultmap() {
  var myLatlng = new google.maps.LatLng(-30.36855, 153.10006);
  var mapOptions = {
    zoom: 12,
    center: myLatlng,
    scrollwheel: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  
  if ($('#default-map').length > 0) {
      var map = new google.maps.Map(document.getElementById('default-map'), mapOptions);
    
      var marker = new google.maps.Marker({
          position: myLatlng,
          map: map 
      });
      
      google.maps.event.addDomListener(window, 'resize', function() {
  		map.setCenter(myLatlng);
	  });         
      google.maps.event.addDomListener(window, 'orientationchange', function() {
			map.setCenter(myLatlng);
	  });   
	}
}
$(window).load(function(){
	defaultmap();
});