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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1648/sunshine-gates_2a88bfae2b.ico','http://cdn.myld.com.au/2/1648/sunshine-gates_e959a3eabd.png');
  
	menu.contactDetails({
		phone: '0754765477',
					//optional, can have multiple values['0752212345', ['Head Office', '0752212345']]
		mobile: '0438450881',
					//optional, can have multiple values['0452212345', ['Tom', '0452212345']]
		email: 'gus@sunshinegates.com.au',
					//optional, can have multiple values['email@gmail.com', ['Support', 'support@yahoo.com']]
		address: '4/30 Enterprise Street Kunda Park, QLD 4556',
					//optional, can have multiple values['Robina, QLD', ['Southport', 'Southport, QLD']]
		 hours: [ 
					['Mon-Fri', '6:30am - 2:30pm'],
					['Sat & Sun', 'By Appointment']
			] 
			//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=='filter1') {
				$('.isotope').isotope({ filter: '.filter1' });
				$('#filters li').removeClass('active');
				$('#filters li:eq(0)').addClass('active');
				$('html, body').animate({ 
				'scrollTop': $('#content').offset().top 
				}, 400);
			} else if(hash_value=='filter2') {
				$('.isotope').isotope({ filter: '.filter2' });
				$('#filters li').removeClass('active');
				$('#filters li:eq(1)').addClass('active');
				$('html, body').animate({ 
				'scrollTop': $('#content').offset().top 
				}, 400);
			} else if(hash_value=='filter3') {
				$('.isotope').isotope({ filter: '.filter3' });
				$('#filters li').removeClass('active');
				$('#filters li:eq(2)').addClass('active');
				$('html, body').animate({ 
				'scrollTop': $('#content').offset().top 
				}, 400);
			} else if(hash_value=='filter4') {
				$('.isotope').isotope({ filter: '.filter4' });
				$('#filters li').removeClass('active');
				$('#filters li:eq(3)').addClass('active');
				$('html, body').animate({ 
				'scrollTop': $('#content').offset().top 
				}, 400);
			} else if(hash_value=='filter6') {
  			$('.isotope').isotope({ filter: '.filter6' });
				$('#filters li').removeClass('active');
				$('#filters li:eq(5)').addClass('active');
				$('html, body').animate({ 
				'scrollTop': $('#content').offset().top 
				}, 400);
			} else {
				$('.isotope').isotope({ filter: '.filter1' });
				$('#filters li').removeClass('active');
				$('#filters li:eq(0)').addClass('active');
			}
	}
  
  // initiating the isotope page
$(window).load(function(){

    // Store # parameter and add "." before hash
    var hashID = "." + window.location.hash.substring(1);

    //  the current version of isotope, the hack works in v2 also
    var $container = $('#container');

    $container.imagesLoaded(function(){
        $container.isotope({
            itemSelector: ".item",
            filter: hashID, // the variable filter hack
        });             
    });

});
	
	//match
	$('.htText h3').matchHeight();
	$('.htText p').matchHeight();
	
	//slider
	$("#slider").backstretch([
		"http://cdn.myld.com.au/2/1952/web_sunshine-gates_858395276d.jpg",
		"http://cdn.myld.com.au/2/1952/web_sunshine-gates_7561809e33.jpg",
		"http://cdn.myld.com.au/2/1952/web_sunshine-gates_89c1c232f8.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');
	});
     
});

$(window).load(function(){
	footermap();
	mapcanvas();
});



//form validation
$('#custom_form').smartCaptcha({ 
  validateText: ["name", "message", "number"],
  validateEmail: ["email"],
	validateStyle: "default"
});

//footer-map
function footermap() {
  var myLatlng = new google.maps.LatLng(-26.66704, 153.02917);
  var image = 'http://cdn.myld.com.au/2/1648/sunshine-gates_b3d28c01b6.png';
  var mapOptions = {
    zoom: 13,
		scrollwheel: false,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  
  if ($('#footer-map').length > 0) {
      var map = new google.maps.Map(document.getElementById('footer-map'), 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);
	  });   
	}
}

//Target Data Filtering Modules
$('#filter_6 a').click(function() {
    return $('#.filter6').first().text();
});


//map-canvas
function mapcanvas() {
  var myLatlng = new google.maps.LatLng(-26.66704, 153.02917);
  var image = 'http://cdn.myld.com.au/2/1648/sunshine-gates_b3d28c01b6.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);
	  });   
	}
}
$('#map-canvas').insertAfter('#slider');

//view section 1
$('#view_section_1').insertAfter('#slogan');

//error div
$('#error').insertAfter('#slogan');

//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"
		}
	});
	
	$('#filters').on( 'click', 'a', function() {
		$('#filters li').removeClass('active');
		$(this).parent('li').addClass('active');
		var filterValue = $(this).attr('data-filter');
		$container.isotope({ filter: filterValue });
	});
});

//Detect mac
	var Browser = menu.browserDetect('version');
		if (Browser.OS == 'Mac') {
		$('body').addClass('mac');
}