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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1083/illawarra-truck-car-centre_cd6a18916e.ico','http://cdn.myld.com.au/2/1083/illawarra-truck-car-centre_c92e36ca5e.png');
  
	menu.contactDetails({
		phone: '0242835581',
					//optional, can have multiple values['0752212345', ['Head Office', '0752212345']]
		mobile: '0419971381',
					//optional, can have multiple values['0452212345', ['Tom', '0452212345']]
		email: 'tojo44@bigpond.com',
					//optional, can have multiple values['email@gmail.com', ['Support', 'support@yahoo.com']]
		address: '45 Pringle Road Fairy Meadow NSW, 2519',
					//optional, can have multiple values['Robina, QLD', ['Southport', 'Southport, QLD']]
		 hours: [ 
					['Mon-Sat', '8:00am - 5:00pm'],
					['24/7 Emergency Call Out Service', '']
			] 
			//optional 
	});
	
	//tabs
	//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('#tab', '');
			$('#tabNav li:eq('+(hash_value - 1)+') a').tab('show');
	};
	
	$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			var target = this.href.split('#');
			$('#tabNav a').filter('[href="#'+target[1]+'"]').tab('show');
			$('.match').matchHeight();
	});
	
	//match
	$('.match').matchHeight();
	
	//slider
	$("#slider").backstretch([
		"http://cdn.myld.com.au/2/1083/illawarra-truck-car-centre_1f2c4c4346.jpg",
		"http://cdn.myld.com.au/2/1083/illawarra-truck-car-centre_b5be67e4ff.jpg",
		"http://cdn.myld.com.au/2/1083/illawarra-truck-car-centre_9e35b0b421.jpg"
	], {duration: 3000, fade: 750, random: true});
     
});

$(window).load(function(){
	mapcanvas();
});

$(window).bind("load resize",function(){	
	if ($("#slider").css("display") == "block" ){
		$('#pageTitle').prependTo('#slider');
	} else if ($("#slider").css("display") == "none" ){
		$('#pageTitle').prependTo('#pageTitleWrap .container');
	}
});

$(window).bind("load resize",function(){
    var container_width = $('#fbFeed').width();    
    $('#fbFeed').html('<div class="fb-page" data-href="https://www.facebook.com/Illawarra-Truck-Car-Centre-1663201093893575/timeline/" data-width="' + container_width + '" data-height="475" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true" data-show-posts="true"></div>');
    FB.XFBML.parse();    
});

//form validation
$('#custom_form').smartCaptcha({ 
  validateText: ["name", "message", "number"],
  validateEmail: ["email"],
	redirectLink: "http://api.jquery.com/jquery.fn.extend/",
	validateStyle: "default"
}); 

//map
function mapcanvas() {
  var myLatlng = new google.maps.LatLng(-34.38631, 150.89227);
  var image = 'http://cdn.myld.com.au/2/1083/illawarra-truck-car-centre_40c763d3f7.png';
  var mapOptions = {
    zoom: 13,
		scrollwheel: false,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  
  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,
          icon: image
      });
      
      google.maps.event.addDomListener(window, 'resize', function() {
			map.setCenter(myLatlng);
	  });         
      google.maps.event.addDomListener(window, 'orientationchange', function() {
			map.setCenter(myLatlng);
	  });   
	}
}

//view section 1
$('#view_section_1').insertAfter('#slider');

//error div
$('#error').insertAfter('#slider');

//nav justify
$('.navbar .nav').addClass('nav-justified');

//Detect mac
	var Browser = menu.browserDetect('version');
		if (Browser.OS == 'Mac') {
		$('body').addClass('mac');
}