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

// Custom JavaScript Document

$(document).ready(function(){  
$('#logo').html('<a href="/"><img src="http://cdn.myld.com.au/2/521/ballina-tyrepro_57bb5828d2.png" alt="Ballina Tyrepro"></a>').appendTo('.logo-here');
$('header').prependTo('body');
$('.navbar').prependTo('.nav-here');
$('body').children('header, div').wrapAll(' <div class="wrapper"></div>').wrapAll('<div class="inner-wrap"></div>');
$('.inner-wrap').after($('footer'));
$('.suppliers').appendTo('.inner-wrap');
$('head').append('<link rel="shortcut icon" type="image/x-icon" href="http://cdn.myld.com.au/2/521/ballina-tyrepro_e177fea912.ico">');
  //********Windows IE8 and below popup*********//   		     		
	$("body").browserDetect( {     	
		name: "Ballina Tyrepro",     
		logo: "http://cdn.myld.com.au/2/521/ballina-tyrepro_57bb5828d2.png",      
		phone: "(02) 6686 0086",     //optional
		fax: "(02) 6686 4486",      //optional
		email: "sales@ballinatyrepro.com.au",      //optional
		address: "1/35 De Havilland Crescent Ballina NSW 2478",  //optional	
		ldprofile: "http://www.localdirectories.com.au/Ballina,NSW/Ballina-Tyrepro/profile/TyYO"  
	});  

// HIDE THE CONTACT US LINK
/*$('.menu_link_4').closest('li').css({'display' : 'none'});*/

	//********Mobile Telephone*********//  
	mobileTel(266860086);

	//Slider
    if ($('body#home').is('*')) {
        $('.camera_wrap').shuffleCamera();
        jQuery('.camera_wrap').camera({
            playPause: false,
            pagination: false,
            loader: 'none',
            navigationHover: false,
            height: '556px'
        });
    }

    //Suppliers
    $('.flexslider').flexslider({
        directionNav: false,
        controlNav: false,
        animation: "slide",
        animationLoop: true,
        itemWidth: 214,
        itemMargin: 0,
        minItems: 1,
        maxItems: 5
    });

    //prev
     $('.arrows #prev').click(function() {
        $('.flexslider').flexslider("prev");
     });

     //next
     $('.arrows #next').click(function() {
        $('.flexslider').flexslider("next");
     });

    //Validation
    $('#custom_form').formValidation({ 
        validateText: ["name", "phone", "message"],
        validateEmail: ["email"],
        validateSpam: true
    });

    //Footer Map
    function footermap() {
      var myLatlng = new google.maps.LatLng(-28.84791, 153.55579);
      var mapOptions = {
        zoom: 14,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      
      if ($('#footer-map').length > 0) {
          var map = new google.maps.Map(document.getElementById('footer-map'), mapOptions);
          var image = 'http://cdn.myld.com.au/2/521/ballina-tyrepro_c2ec7d750c.png';
        
          var marker = new google.maps.Marker({
              position: myLatlng,
              map: map,
              icon: image
          });
          
          google.maps.event.addDomListener(window, 'resize orientationchange', function() {
                map.setCenter(myLatlng);
          }); 
      }
    }

    google.maps.event.addDomListener(window, 'load', footermap);

    //Main Google Map
    function mapcanvas() {
      var myLatlng = new google.maps.LatLng(-28.84791, 153.55579);
      var mapOptions = {
        zoom: 12,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      
      if ($('#footer-map').length > 0) {
          var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
          var image = 'http://cdn.myld.com.au/2/521/ballina-tyrepro_19997c85a5.png';
        
          var marker = new google.maps.Marker({
              position: myLatlng,
              map: map,
              icon: image
          });
          
          google.maps.event.addDomListener(window, 'resize orientationchange', function() {
                map.setCenter(myLatlng);
          }); 
      }
    }

    google.maps.event.addDomListener(window, 'load', mapcanvas);

    //Gallery
    if(jQuery.browser.mobile)
    {
       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 
        });
    }
	
});

(function($){
    $.fn.shuffleCamera = function() {
        return this.each(function(){
            var items = $(this).children().clone(true);
            return (items.length) ? $(this).html($.shuffleCamera(items)) : this;
        });
    }
    
    $.shuffleCamera = function(arr) {
        for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
        return arr;
    }
})(jQuery);


$(window).load(function(){
        // Initialize portfolio isotope 
        var $container          = $('.filter-feed');
  	var selector = '*';
        isotopeFilter(selector, $container);
		
		
		$(window).resize(function(){	
            	 isotopeFilter(selector, $container);
		});
		
		function isotopeFilter(selector, $container) {
			$container.isotope({
				filter              : selector,
				layoutMode          : 'masonry', 
				animationOptions    : {
					duration            : 450,
					easing              : 'linear',
                	queue              : false
				}
			});			
		}
});
