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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1345/chandley-plumbing_39149f59b3.ico','http://cdn.myld.com.au/2/1345/chandley-plumbing_ff6eba4836.png');
	
	menu.contactDetails({
		mobile: '0408615995',
					//optional, can have multiple values['0452212345', ['Tom', '0452212345']]
		email: 'admin@chandleyplumbing.com.au',
					//optional, can have multiple values['email@gmail.com', ['Support', 'support@yahoo.com']]
		 hours: [ 
					['Mon-Fri', '8:00am - 5:00pm'],
					['After Hours', 'Emergency Appointments Available']
			] 
			//optional 
	});
	
	//tabImage
	if ($('body#plumbing').is('*')) {
		$("#content").backstretch([
			"http://cdn.myld.com.au/2/1345/chandley-plumbing_28d90efb6a.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_6a72ec60b9.jpg"
		], {duration: 200, fade: 200, random: false});
	} else if ($('body#gasfitting').is('*')) {
		$("#content").backstretch([
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_ccb57b1ec4.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_ccb57b1ec4.jpg",
			"http://cdn.myld.com.au/2/1874/chandley-plumbing_ccb57b1ec4.jpg"
		], {duration: 200, fade: 200, random: false});
	}
	
	$('#content').backstretch("pause");
		$('#tabNav li:eq(0) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",0);
		})
		$('#tabNav li:eq(1) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",1);
		})
		$('#tabNav li:eq(2) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",2);
		})
		$('#tabNav li:eq(3) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",3);
		})
		$('#tabNav li:eq(4) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",4);
		})
		$('#tabNav li:eq(5) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",5);
		})
		$('#tabNav li:eq(6) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",6);
		})
		$('#tabNav li:eq(7) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",7);
		})
		$('#tabNav li:eq(8) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",8);
		})
		$('#tabNav li:eq(9) a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			$('#content').backstretch("show",9);
		})
		
		//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');
		});
     
});

$(window).load(function(){
	//parallax
	//$('#jmm-content').css({"background": "transparent"});
});

if ($('body#home').is('*')) {
	$(window).bind("load resize",function(){
			var container_width = $('#fbFeed').width();    
			$('#fbFeed').html('<div class="fb-page" data-href="https://www.facebook.com/chandleyplumbing/" data-tabs="timeline" data-width="' + container_width + '" data-height="310" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"><div class="fb-xfbml-parse-ignore"><blockquote cite="https://www.facebook.com/chandleyplumbing/"><a href="https://www.facebook.com/chandleyplumbing/">Chandley plumbing &amp; gasfitting</a></blockquote></div></div>');
			FB.XFBML.parse();    
	});
}

//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"
	});
}

//view section 1
$('#view_section_1').insertAfter('#header');

//error div
$('#error').insertAfter('#header');

//nav justify
$('.navbar .nav').addClass('nav-justified');

//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='gallery_group']").fancybox({
        'transitionIn'    :    'elastic',
        'transitionOut'    :    'elastic',
        'speedIn'        :    600, 
        'speedOut'        :    200 
    });

/* Apply with thumbnails visible */
    $("a.fancybox").fancybox({
		helpers : {
			thumbs : {
				width: 200,
				height: 200
			}
		}
    });
}

$(window).bind("load resize scroll",function(){
	//isotope
	var $container = $('.isotope').isotope({
		"itemSelector": ".item",
		masonry: {
			columnWidth: ".item"
		}
	});
});

//Detect mac
	var Browser = menu.browserDetect('version');
		if (Browser.OS == 'Mac') {
		$('body').addClass('mac');
}