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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/148/web_hvtm-outdoors_27a49a07f2.png');
    	
	$("#slider").backstretch([
		"http://cdn.myld.com.au/2/1749/hvtm-outdoors_e7b768b540.jpg",
		"http://cdn.myld.com.au/2/1749/hvtm-outdoors_4c8c47aa85.jpg",
		"http://cdn.myld.com.au/2/1749/hvtm-outdoors_90fd49d64c.jpg",
		"http://cdn.myld.com.au/2/1749/hvtm-outdoors_d466a31b01.jpg",
		"http://cdn.myld.com.au/2/1749/hvtm-outdoors_e36f4f6a89.jpg"
	], {duration: 3000, fade: 750, random: true});
	
	menu.contactDetails({
		phone: '02 4991 5777', 
					//optional, can have multiple values['0249454622', ['Head Office', '0249454622']]
		mobile: '', 
					//optional, can have multiple values
		email: 'hvtm@bigpond.com', 
					//optional, can have multiple values['macphysb@tpg.com.au', ['Support', 'macphysb@tpg.com.au']]
		address: 'PO Box W192 Cessnock West NSW 2325', 
					//optional, can have multiple values
        hours: [ 
					['Monday - Friday', '8:30am to 5:00pm'],
                    ['Saturday', '8:30am to 1:00pm'],
                    ['Saturday', 'Closed']
			] 
			//optional 
		
	});
     
}); 
 
 
 //insert view section
$('#view_section_1').insertAfter('.nav-bar-holder'); 

//FAQ
$(document).ready(function(){

   var elegance = document.createElement('script');
   elegance.type = "text/javascript";
   elegance.src = 'http://cdn.myld.com.au/1/js/browserdetect/browser_detect.js';
   document.body.appendChild(elegance); 
   
	 $('.faq-list1').goFaq ();
	 $('.faq-list2').goFaq ();
	 
	$("#tab2 .faq-toc ol li:eq(0) a").attr("href", "#firearmsfaq-1")
	$("#tab2 .faq-list2 li:eq(0)").attr("id", "firearmsfaq-1")
	$("#tab2 .faq-toc ol li:eq(1) a").attr("href", "#firearmsfaq-2")
	$("#tab2 .faq-list2 li:eq(1)").attr("id", "firearmsfaq-2")
	$("#tab2 .faq-toc ol li:eq(2) a").attr("href", "#firearmsfaq-3")
	$("#tab2 .faq-list2 li:eq(2)").attr("id", "firearmsfaq-3")
	$("#tab2 .faq-toc ol li:eq(3) a").attr("href", "#firearmsfaq-4")
	$("#tab2 .faq-list2 li:eq(3)").attr("id", "firearmsfaq-4")
	$("#tab2 .faq-toc ol li:eq(4) a").attr("href", "#firearmsfaq-5")
	$("#tab2 .faq-list2 li:eq(4)").attr("id", "firearmsfaq-5")
	$("#tab2 .faq-toc ol li:eq(5) a").attr("href", "#firearmsfaq-5")
	$("#tab2 .faq-list2 li:eq(5)").attr("id", "firearmsfaq-5")
	$("#tab2 .faq-toc ol li:eq(6) a").attr("href", "#firearmsfaq-6")
	$("#tab2 .faq-list2 li:eq(6)").attr("id", "firearmsfaq-6")
	$("#tab2 .faq-toc ol li:eq(7) a").attr("href", "#firearmsfaq-7")
	$("#tab2 .faq-list2 li:eq(7)").attr("id", "firearmsfaq-7")
	$("#tab2 .faq-toc ol li:eq(8) a").attr("href", "#firearmsfaq-8")
	$("#tab2 .faq-list2 li:eq(8)").attr("id", "firearmsfaq-8")
});

//map

function mapcanvas() {
  var myLatlng = new google.maps.LatLng(-32.83927, 151.34356);
  var mapOptions = {
    zoom: 13,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    scrollwheel: false
  }
  
  if ($('#map-canvas').length > 0) {
      var map = new google.maps.Map(document.getElementById('map-canvas'), 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(){
	mapcanvas();
  
  var shopJson = "http://shop.hvtm.com.au/products.json";
  
  //previewUrl(shopJson, 'shopJson');

});

    
function previewUrl(url,target) {
        //use timeout coz mousehover fires several times
        clearTimeout(window.ht);
        window.ht = setTimeout(function(){
            var div = document.getElementById(target);
            div.innerHTML = '<iframe style="width:100%;height:100%;" id="id_description_iframe" frameborder="0" src="' + url + '" />';
            
            setTimeout(function(){
              checkIframeLoaded();
            },2000);      
            
        },20);      
            
} 

      
function checkIframeLoaded() {
    // Get a handle to the iframe element
  var iframe = document.getElementById('id_description_iframe');
    var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;

    // Check if loading is complete
    if (  iframeDoc.readyState  == 'complete' ) {
        //iframe.contentWindow.alert("Hello");
        iframe.contentWindow.onload = function(){
        };
        // The loading is complete, call the function we want executed once the iframe is loaded
        afterLoading();
        return;
    } 

    // If we are here, it is not loaded. Set things up so we check   the status again in 100 milliseconds
    window.setTimeout('checkIframeLoaded();', 100);
}

function afterLoading(){
    setTimeout(function(){
      var json = $("#id_description_iframe").contents().find("body");
      console.log('json',$("#id_description_iframe").contents());
    },5000);  
}
  

//form required field
$('#custom_form').smartCaptcha({ 
    validateText: ["name", "last_name"],
    validateEmail: ["email"],
    validateLetters: ["letters"], 
    validateChar: [{ id: "char", max: 7 }],
    validateNum: [{ id: "zip", max: 4, min: 2 }],
    validateRange: [{ id: "range", limit: [5,20] }],
    validateRadiobutton: ["radiogroup_id"],
    validateCheckbox: [{ id: "cb", limit: [1,1] }],
    validateDropdown: ["state"],
    validateURL: ["website"],
    redirectLink: null,
    validateStyle: "default"
});  

//form validation
$('#custom_form').smartCaptcha({ 
  validateText: ["name",  "email"],
	redirectLink: "http://api.jquery.com/jquery.fn.extend/",
	validateStyle: "default"
}); 

//Detect mac
	var Browser = menu.browserDetect('version');
		if (Browser.OS == 'Mac') {
		$('body').addClass('mac');
}









