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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_7df8d7fd3d.ico','http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_3113dfed23.png');
  
	menu.contactDetails({
		phone: '0418827747',
					//optional, can have multiple values['0752212345', ['Head Office', '0752212345']]
		email: 'plumb1industries@gmail.com',
					//optional, can have multiple values['email@gmail.com', ['Support', 'support@yahoo.com']]
		 hours: [ 
					['Mon-Fri', '7:30am - 4:00pm'],
					['Weekend Emergencies', 'Available'],
					['After-hours Emergencies', 'Available']
			] 
			//optional 
	});
	
	//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=='brands') {
				$('html, body').animate({ 
				'scrollTop': $('#brands').offset().top 
				}, 800);
			}
	}
	
	//home services links
	$('#htLink1').replaceWith('<a href="contact">Call us now</a>');
	$('#htLink2').replaceWith('<a href="contact">pick up the phone</a>');
	$('#htLink3').replaceWith('<a href="contact">Get in touch</a>');
	
	//slider
	if ($('body#home').is('*')) {
		$("#slider").backstretch([
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_bc7148e12b.jpg",
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_c0907d8372.jpg",
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_f9ebbcc45a.jpg",
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_a820b7cbfc.jpg"
		], {duration: 3000, fade: 750, random: true});
		// Set active for the first bullet when document ready;;
		$('.pagination').first().addClass('active');
		// Since you called it as $.backstretch, it's attached to the body
		var instance = $("#slider").data("backstretch");
		$('.pagination').click(function () {
			var index = $('.pagination').index( $(this) );
			$('.pagination').removeClass('active');
			$(this).addClass('active');
			// Show the slide based on the clicked index
			instance.show(index);
			// Return false, so that the click doesn't change the page hash
			return false;
		});
		// Set the current pagination active while running as slideshow
		$("#slider").on("backstretch.before", function (e, instance, index) {
			$('.pagination').removeClass('active').eq(index).addClass('active');
		});
	} else {
		$("#slider").backstretch([
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_a82c106ecd.jpg",
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_85d8632a1c.jpg",
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_5c613466df.jpg",
			"http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_8ab6cda091.jpg"
		], {duration: 3000, fade: 750, random: true});
	}
     
});

//form validation
$('#custom_form').smartCaptcha({ 
  validateText: ["name", "message", "number"],
  validateEmail: ["email"],
	validateStyle: "default"
});

function mapcanvas() {
  var myLatlng = new google.maps.LatLng(-26.68200, 153.11800);
  var image = 'http://cdn.myld.com.au/2/1694/plumb-1-industries-gas-fitting_20ee777e61.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);
	  });   
	}
}

$(window).load(function(){
	mapcanvas();
});

//view section 1
$('#view_section_1').insertAfter('#slider');

//error div
$('#error').insertAfter('#slider');

//subnav
$('.navbar .navbar-nav > li').eq(2).addClass('dropdown').append('<ul class="dropdown-menu">'+
      '<li><a href="services#brands">Brands</a></li>'+
    '</ul>').children('a').addClass('dropdown-toggle');
menu.reset();

//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');
}