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

//Javascripts
$(document).ready(function(){
    $.favicon('http://cdn.myld.com.au/2/1208/image-windows-doors_3ff2759fa5.png');

    menu.contactDetails({

        phone: '0266433373', //optional, can have multiple values[array]
        email: 'sales@imagewindows.net.au', //optional, can have multiple values[array]
        address: 'Gate 5 - 170 North Street (The Old Brewery) Grafton, NSW 2460', //optional, single value
        //hours: [['Mon - Fri','9am - 5:30pm'],['Sat','9am - 4pm'],['Sun','10am - 3pm']] //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');
    
    // Dropdowns
    $('.navbar .navbar-nav > li').eq(2).addClass('dropdown').append('<ul class="dropdown-menu">'+'<li><a href="services#installation">Installation</a></li><li><a href="services#doors-windows">Doors & Windows</a></li><li><a href="services#glass-replacement">Glass Replacement</a></li><li><a href="services#security-screens">Security Screens</a></li><li><a href="services#mirrors">Mirrors</a></li><li><a href="services#shower-screens">Shower Screens</a></li><li><a href="services#shopfronts">Shopfronts</a></li><li><a href="services#insurance-work">Insurance Work</a></li>'+'</ul>').children('a').addClass('dropdown-toggle').attr('data-toggle', 'dropdown'); 
    $('.navbar .navbar-nav > li').eq(3).addClass('dropdown').append('<ul class="dropdown-menu">'+'<li><a href="products#bi-fold-windows">Bi-fold Windows & Doors</a></li><li><a href="products#glass-window-replacement">Glass & Window Replacement</a></li><li><a href="products#mirror-robe-doors">Mirror Robe Doors</a></li><li><a href="products#crimsafe-security-system">Crimsafe Security System</a></li><li><a href="products#safety-doors-screens">Safety Doors & Screens</a></li><li><a href="products#louvres-sunrooms">Louvres & Sunrooms</a></li><li><a href="products#commercial-shopfronts">Commercial Shopfronts & Automatic Doors</a></li><li><a href="products#double-hung">Double Hung & Awning Windows</a></li><li><a href="products#stacking-doors">Stacking Doors</a></li><li><a href="products#shower-screens-mirrors">Shower Screens & Mirrors</a></li><li><a href="products#glass-brick-frames">Glass & Brick Frames</a></li>'+'</ul>').children('a').addClass('dropdown-toggle').attr('data-toggle', 'dropdown'); 
    
    menu.reset(); 
    
    
    
     $('#navigation .active .dropdown-menu li a').click(function(){
    var path = $(this).attr('href').replace(/^.*?(#|$)/,'');
  
      $('.nav-tabs li.active').removeClass('active');
      $('.nav-tabs li a[href=#'+path+']').closest('li').addClass('active');
    });
    $('#navigation .active .dropdown-menu li a').attr('data-toggle','tab');

    //Contact Page
    if ( $("body#contact").is("*") ) {
      $('#contact_form').smartCaptcha({ 
          validateText: ["name","phone"],
          validateEmail: ["email"],
          validateChar: [{ id: "message", max: null }],
         
          
          redirectLink: null,
          validateStyle: "default"
      });
    }
    
    $('#quote_form').smartCaptcha({ 
        validateText: ["name", "message", "phone", "location"],
        validateEmail: ["email"],
        validateDropdown: ["product"],
        validateRadiobutton: ["preferred_time"],
        validateCheckbox: [{ id: "preferred_day", limit: [1,5] }],       
        redirectLink: null,
        validateStyle: "default"
    });
    
    $('#introduction').insertAfter('#top-header');
    
    //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');
    
    //gallery
    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='group']").fancybox({
            'transitionIn'    :    'elastic',
            'transitionOut'    :    'elastic',
            'speedIn'        :    600, 
            'speedOut'        :    200 
        });
    }
    
    $('.brand-logos').slick({
      dots: false,
      arrows: true,
      centerMode: false,
      centerPadding: '0px',
      slidesToShow: 6,
      responsive: [
        {
          breakpoint: 768,
          settings: {
            arrows: false,
            centerMode: true,
            centerPadding: '40px',
            slidesToShow: 3
          }
        },
        {
          breakpoint: 480,
          settings: {
            arrows: false,
            centerMode: true,
            centerPadding: '40px',
            slidesToShow: 1
          }
        }
      ]
    });
});


$(window).load(function() {
  $("#header").addClass("loaded");  
});

$(window).load(function(){

  // Javascript to enable link to tab
  var url = document.location.toString();
  if (url.match('#')) {
  $('.navbar-collapse a[href=#'+url.split('#')[1]+']').tab('show') ;
  }
  // Change hash for page-reload
  $('.navbar-collapse 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 -5}, '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('#', '');
      $('.navs-holder .nav-tabs li.active').removeClass('active');
      $('.navs-holder .nav-tabs li a[href=#'+hash_value+']').closest('li').addClass('active');
      $('.tab-content .active').removeClass('active');
      $(".tab-content #"+hash_value).addClass('active');
      $('html, body').animate({scrollTop: $('.tabs-holder').offset().top -2}, 'slow');
  }
});