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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1609/kosmo-smash-repairs_abf2d0cb8b.ico','http://cdn.myld.com.au/2/1609/kosmo-smash-repairs_a36da2476e.png');
	
	menu.contactDetails({
		phone: '0267655911',
					//optional, can have multiple values['0752212345', ['Head Office', '0752212345']]
		email: 'admin@kosmosmash.com.au',
					//optional, can have multiple values['email@gmail.com', ['Support', 'support@yahoo.com']]
		address: '10 MacIntosh Street Tamworth, NSW 2340',
					//optional, can have multiple values['Robina, QLD', ['Southport', 'Southport, QLD']]
		 hours: [ 
					['Mon-Fri', '7:30am - 5:00pm']
			] 
			//optional 
	});
	
	//content nav
	$('#contentNav a:eq(0)').click(function(){
		$('html, body').animate({ 
		'scrollTop': $('#module1').offset().top 
		}, 400);
		return false;
	});
	$('#contentNav a:eq(1)').click(function(){
		$('html, body').animate({ 
		'scrollTop': $('#module2').offset().top 
		}, 400);
		return false;
	});
	$('#contentNav a:eq(2)').click(function(){
		$('html, body').animate({ 
		'scrollTop': $('#module3').offset().top 
		}, 400);
		return false;
	});
	$('#contentNav a:eq(3)').click(function(){
		$('html, body').animate({ 
		'scrollTop': $('#module4').offset().top 
		}, 400);
		return false;
	});
	$('#contentNav a:eq(4)').click(function(){
		$('html, body').animate({ 
		'scrollTop': $('#module5').offset().top 
		}, 400);
		return false;
	});
	$('#contentNav a:eq(5)').click(function(){
		$('html, body').animate({ 
		'scrollTop': $('#module6').offset().top 
		}, 400);
		return false;
	});
	
	//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('#', '');
			
			if(hash_value=='module1') {
				$('html, body').animate({ 
				'scrollTop': $('#module1').offset().top 
				}, 400);
			} else if(hash_value=='module2') {
				$('html, body').animate({ 
				'scrollTop': $('#module2').offset().top 
				}, 400);
			} else if(hash_value=='module3') {
				$('html, body').animate({ 
				'scrollTop': $('#module3').offset().top 
				}, 400);
			} else if(hash_value=='module4') {
				$('html, body').animate({ 
				'scrollTop': $('#module4').offset().top 
				}, 400);
			} else if(hash_value=='module5') {
				$('html, body').animate({ 
				'scrollTop': $('#module5').offset().top 
				}, 400);
			}
	}
	
	//footer contact
	$('#footerContact a').hide();
	$(".footerPhone").hover(
		 function () {
			 $('#footerContact a').hide();
			 $('#footerPhone').show();
			 $('#footerIcons a').removeClass('active');
			 $('.footerPhone').addClass('active');
		 }
	 );
	$(".footerMail").hover(
		 function () {
			 $('#footerContact a').hide();
			 $('#footerMail').show();
			 $('#footerIcons a').removeClass('active');
			 $('.footerMail').addClass('active');
		 }
	 );
	$(".footerAddress").hover(
		 function () {
			 $('#footerContact a').hide();
			 $('#footerAddress').show();
			 $('#footerIcons a').removeClass('active');
			 $('.footerAddress').addClass('active');
		 }
	 );
	$(".footerHours").hover(
		 function () {
			 $('#footerContact a').hide();
			 $('#footerHours').show();
			 $('#footerIcons a').removeClass('active');
			 $('.footerHours').addClass('active');
		 }
	 );
	$(".footerLocalSearch").hover(
		 function () {
			 $('#footerContact a').hide();
			 $('#footerLocalSearch').show();
			 $('#footerIcons a').removeClass('active');
			 $('.footerLocalSearch').addClass('active');
		 }
	 );
	
	//match
	$('.homeThumb h3').matchHeight();
	$('.homeThumb p').matchHeight();
	
	//slider
	$("#slider").backstretch([
		"http://cdn.myld.com.au/2/1609/kosmo-smash-repairs_6adce49558.jpg",
		"http://cdn.myld.com.au/2/1609/kosmo-smash-repairs_1e728d0f29.jpg",
		"http://cdn.myld.com.au/2/1609/kosmo-smash-repairs_1e7b561e1d.jpg",
		"http://cdn.myld.com.au/2/1609/kosmo-smash-repairs_6eaf119e34.jpg"
	], {duration: 3000, fade: 750, random: true});
     
});

$(window).load(function(){
	mapcanvas();
});

//form validation
$('#custom_form').smartCaptcha({ 
  validateText: ["name", "message", "number"],
  validateEmail: ["email"],
	validateStyle: "default"
});

//map
function mapcanvas() {
  var myLatlng = new google.maps.LatLng(-31.09732, 150.90017);
  var image = 'http://cdn.myld.com.au/2/1609/kosmo-smash-repairs_87b4d85a1f.png';
  var mapOptions = {
    zoom: 18,
		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);
	  });   
	}
}
$('#map-canvas').insertAfter('#slider');

//view section 1
$('#view_section_1').insertAfter('#cta');

//error div
$('#error').insertAfter('#cta');

//nav justify
$('.navbar .nav').addClass('nav-justified');

//Detect mac
	var Browser = menu.browserDetect('version');
		if (Browser.OS == 'Mac') {
		$('body').addClass('mac');
}