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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1184/blindmac_60aaf45d54.ico','http://cdn.myld.com.au/2/1184/blindmac_65834f616e.png');
	
	menu.contactDetails({
		phone: '0266523286',
					//optional, can have multiple values['0752212345', ['Head Office', '0752212345']]
		mobile: [['Blinds', '0481307409'], ['Fencing', '0481300974']],
					//optional, can have multiple values['0452212345', ['Tom', '0452212345']]
		email: ['admin@blindmac.com.au', 'admin@bananacoastfencing.com.au'],
					//optional, can have multiple values['email@gmail.com', ['Support', 'support@yahoo.com']]
		address: '40 Marcia Street, Coffs Harbour NSW 2450',
					//optional, can have multiple values['Robina, QLD', ['Southport', 'Southport, QLD']]
		 hours: [ 
					['Mon-Fri', '8:30am - 5:00pm'],
					['Saturday', 'By appointment']
			] 
			//optional 
	});
	
	//match
	$('.match1').matchHeight();
	$('.match2').matchHeight();
	$('.match3').matchHeight();
	
	//tabImage
	if ($('body#internal-blinds').is('*')) {
		$("#tabImage").backstretch([
			"http://cdn.myld.com.au/2/1235/blindmac_43b3991812.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_566e9576c7.JPG",
			"http://cdn.myld.com.au/2/1293/blindmac_759f5364a7.jpg",
			"http://cdn.myld.com.au/2/1235/blindmac_fda72a4313.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_713cc05cd5.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_410b5fd555.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_286ef58b65.JPG"
		], {duration: 200, fade: 200, random: false});		
	} 
	else if ($('body#awnings').is('*')) {
		$("#tabImage").backstretch([
			"http://cdn.myld.com.au/2/1235/blindmac_06dd90b332.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_1a5905992e.JPG"
		], {duration: 200, fade: 200, random: false});	
	} 
	else if ($('body#shutters').is('*')) {
		$("#tabImage").backstretch([
			"http://cdn.myld.com.au/2/1235/blindmac_eb5ba48d6a.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_2f4dc0f719.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_e49e9532df.jpg",
			"http://cdn.myld.com.au/2/1234/blindmac_e997ee1d19.jpeg"
		], {duration: 200, fade: 200, random: false});	
	} 
	else if ($('body#bananacoast-fencing').is('*')) {
		$("#tabImage").backstretch([
			"http://cdn.myld.com.au/2/1234/blindmac_fe6510e3fc.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_a078cd0e47.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_e73c8ad49f.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_ef765f5e29.JPG",
			"http://cdn.myld.com.au/2/1235/blindmac_855d6d3885.JPG",
			"http://placehold.it/380x260"
		], {duration: 200, fade: 200, random: false});	
	}
	
	$('#tabImage').backstretch("pause");
		$('#tabNav li:eq(0) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#tabImage').backstretch("show",0);
		})
		$('#tabNav li:eq(1) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#tabImage').backstretch("show",1);
		})
		$('#tabNav li:eq(2) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#tabImage').backstretch("show",2);
		})
		$('#tabNav li:eq(3) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#tabImage').backstretch("show",3);
		})
		$('#tabNav li:eq(4) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#tabImage').backstretch("show",4);
		})
		$('#tabNav li:eq(5) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#tabImage').backstretch("show",5);
		})
		$('#tabNav li:eq(6) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#tabImage').backstretch("show",6);
		})
		
		//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');
				$('.match3').matchHeight();
		});
	
	//tab span
	$("#tabNav li a").each(function() {
		var newHeight = $(this).outerHeight() + 1 + "px";
		$(this).children("span").css("height", newHeight);
	});
	
	var newHeight1 = $("#tabNav li:eq(0) a").outerHeight() + 2 + "px";
	$("#tabNav li:eq(0) a").children("span").css("height", newHeight1);
     
});

$(window).load(function(){
	mapcanvas();
});

//form validation
if ($('body#contact').is('*')) {
		$('#custom_form').smartCaptcha({ 
			validateText: ["name", "message", "number"],
			validateEmail: ["email"],
			redirectLink: "http://api.jquery.com/jquery.fn.extend/",
			validateStyle: "default"
		});
	} 
	else {
		$('#footer_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(-30.28992, 153.11870);
  var image = 'http://cdn.myld.com.au/2/1184/blindmac_a576f4ffe3.png';
  var mapOptions = {
    zoom: 13,
    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('#logo');

//error div
$('#error').insertAfter('#logo');

//nav justify
$('.navbar .nav').addClass('nav-justified');

//Detect mac
	var Browser = menu.browserDetect('version');
		if (Browser.OS == 'Mac') {
		$('body').addClass('mac');
}