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

//Javascripts
$(document).ready(function(){ 
  $.favicon('http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_2cbb21041c.ico','http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_dbd6b6500a.png');
  
  menu.contactDetails({
  	phone: '0266224771',
					//optional, can have multiple values['0752212345', ['Head Office', '0752212345']]
		address: '92 Woodlark Street Lismore, NSW 2480',
					//optional, can have multiple values['Robina, QLD', ['Southport', 'Southport, QLD']]
		 hours: [ 
					['Monday', 'Closed'],
					['Tue-Fri', '9:00am - 5:00pm'],
					['Saturday', '9:00am - 12:00pm'],
					['Sunday', 'Closed'],
					['Extended Hours', 'By appointment only']
			] 
			//optional 
	});
	
	//affix
	$('#header').affix({
		offset: {
				top: 0
			}
	});
	
	//match
	$('.testiBox').matchHeight();
	
	//tabImage
	$("#tabImage").backstretch([
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg",
		"http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_c256b1944b.jpg"
	], {duration: 200, fade: 200, random: false});
	$('#tabImage').backstretch("pause");
	
	//slider
	$("#slider").backstretch([
		"http://cdn.myld.com.au/2/1587/mahican-pink-hair-studio_ef3706920b.jpg", 
		"http://cdn.myld.com.au/2/1587/mahican-pink-hair-studio_64b4910a32.jpg", 
		"http://cdn.myld.com.au/2/1587/mahican-pink-hair-studio_2fbd444df2.jpg", 
		"http://cdn.myld.com.au/2/1587/mahican-pink-hair-studio_be4e7e1ead.jpg"
	], {duration: 3000, fade: 750, random: true});
	
	$('.next').click(function(x) {
			x.preventDefault();
			$("#slider").data('backstretch').next();
	});
	
	$('.prev').click(function(x) {
			x.preventDefault();
			$("#slider").data('backstretch').prev();
	});
	
	// 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(){
	mapcanvas();
	
	$('#scrollable').mCustomScrollbar('update');
	
	//$('.isotope').isotope({ filter: '.filter1' });
	
	//check if hash tag exists in the URL
	function scrolltoTop(hash) {
			if ($('#scrollable').length) {
					$("#scrollable").mCustomScrollbar('scrollTo',hash);
					$('html, body').animate({ 
					'scrollTop': $('#content').offset().top -100
					}, 400);
			}
	}
	
	if(window.location.hash) {
			var hash_tag = window.location.hash;
	
			scrolltoTop(hash_tag);
	}
});

$(window).bind("load resize",function(){	
	if ($("#header").css("display") == "block" ){
		$('#scroller').appendTo('#sliderScrollBox .container');
		$('#filterBox').appendTo('#sliderScrollBox .container');
	} else if ($("#header").css("display") == "none" ){
		$('#scroller').prependTo('#scrollBox .container');
		$('#filterBox').prependTo('#scrollBox .container');
	}
});

//form validation
$('#custom_form').smartCaptcha({ 
  validateText: ["name", "message", "number"],
  validateEmail: ["email"],
	validateStyle: "default"
});

//map
function mapcanvas() {
  var myLatlng = new google.maps.LatLng(-28.80713, 153.27889);
  var image = 'http://cdn.myld.com.au/2/1574/mahican-pink-hair-studio_d8da4eefa3.png';
  var mapOptions = {
    zoom: 17,
		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);
	  });   
	}
}

//view section 1
$('#view_section_1').insertAfter('#slider');

//error div
$('#error').insertAfter('#slider');

//inserts
$('#slogan').appendTo('#slider');
$('#slogan2').appendTo('#slider');
$('#sliderCTA').appendTo('#slider');
$('#pageTitle').appendTo('#slider');

//nav justify
$('.navbar .nav').addClass('nav-justified');

//nav span
$('.navbar-nav > li > a').wrapInner('<span>');

//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');
}

//scroll
$('#scrollable').mCustomScrollbar({
        scrollButtons:{
            enable:false
        },
        mouseWheel:{
            enable:true,
            preventDefault:true
        },
        callbacks:{
            onScroll: function(){
                var lastId,
                topMenu = $('#scroll-nav'),
                menuItems = topMenu.find('a'),
                containerHeight = $('#scrollable').offset().top,
                scrollItems = menuItems.map(function(){
                      var item = $($(this).attr("href"));
                      if (item.length) { return item; }
                });

                var cur = scrollItems.map(function(){
                    if ($(this).offset().top <= containerHeight + 50) {
                        return this;
                    }
                });
                cur = cur[cur.length-1];
                var id = cur && cur.length ? cur[0].id : "";
                if (lastId !== id) {
                    lastId = id;
                    menuItems
                        .parent().removeClass("active")
                        .end().filter("[href=#"+id+"]").parent().addClass("active");
                }

                hashTag(id);


            },
        },
        advanced:{
            // updateOnBrowserResize: true
        },
        theme:"dark-thick"
    });
		
    //Scroll Animation
    $("#scroll-nav li a").on('click', function(e) {

        e.preventDefault();
        var hash = $(this).attr('href');
        var imgTag = hash.replace('#', '');

        $("#scrollable").mCustomScrollbar('scrollTo',hash);
        hashTag(imgTag);
				$('html, body').animate({ 
				'scrollTop': $('#content').offset().top -100
				}, 400);
    });

    $(window).bind('resize',function(){
        $('#scrollable').mCustomScrollbar("update");

    });
		
    //Custom Function
    function hashTag(hash_tag) {
        switch(hash_tag) {
            case 'scroll1':
            $('#tabImage').backstretch("show",0);
            break;
            case 'scroll2':
            $('#tabImage').backstretch("show",1);
            break;
            case 'scroll3':
            $('#tabImage').backstretch("show",2);
            break;
            case 'scroll4':
            $('#tabImage').backstretch("show",3);
            break;
            case 'scroll5':
            $('#tabImage').backstretch("show",4);
            break;
            case 'scroll6':
            $('#tabImage').backstretch("show",5);
            break;
            case 'scroll7':
            $('#tabImage').backstretch("show",6);
            break;
            case 'scroll8':
            $('#tabImage').backstretch("show",7);
            break;
            case 'scroll9':
            $('#tabImage').backstretch("show",8);
            break;
            case 'scroll10':
            $('#tabImage').backstretch("show",9);
            break;
            default:
            $('#tabImage').backstretch("show",0);
        }
    }