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

$(document).ready(function(){  
  
  //nav
  $(".nav").appendTo("#mymenu");
  $(".navbar.main-nav:first").remove();
  $("#logo:first").remove();
  $(".nav").addClass("pull-right menu");
  
  $(".nav li:nth-child(3)").replaceWith('<li><a href="services">Services</a><ul> <li><a href="sheds">Sheds</a></li><li><a href="lysaght-living-collection">Lysaght Living Collect</a></li><li><a href="fencing">Fencing</a></li><li><a href="renovations">Renovations</a></li><li><a href="concreting-minor-earthmoving">Concreting &amp;<br> Minor Earth Moving</a></li><li><a href="tree-milling">Tree Milling</a></li></ul></li>');
  
  $("#myheader").prependTo("body"); 
  
  //favicon
  $('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="http://cdn.myld.com.au/2/413/downright-carpentry_7901c969c4.ico" />').appendTo('head');
  $('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="http://cdn.myld.com.au/2/379/downright-carpentry_f851adea77.png" />').appendTo('head'); 


  //********Windows IE8 and below popup*********//   		     		
	$("body").browserDetect( {     	
		name: "Downright Carpentry",     
		logo: "http://cdn.myld.com.au/2/413/downright-carpentry_5c43ab49dc.png",      
		phone: "0429 699 226 ",     
		fax: "07 4743 9590",      //optional 
		email: "downrightcarpentry@bigpond.com",      //optional 
		address: "11 Ryan Road Mount Isa Queensland 4825",  //optional	
		ldprofile: "http://www.localdirectories.com.au/Mount-Isa-Area,QLD/Downright-Carpentry/profile/LxD4"  
	});  

 
 
	


	//gallery
	if ( $("body.gallery").is("*") ) {
		    if(jQuery.browser.mobile)
		    {
			    var myPhotoSwipe = $(".fancybox").photoSwipe({ enableMouseWheel: false , enableKeyboard: false });
		    }
		    else
		    {
			    /* Apply fancybox to multiple items */
			    $("a.fancybox[rel='gallery_group']").fancybox({
				    'transitionIn'    :    'elastic',
				    'transitionOut'    :    'elastic',
				    'speedIn'        :    600,
				    'speedOut'        :    200,
				    'overlayShow'    :    false
			    });
		    }
	}

	//Map-area
	if ( $("body#contact-us").is("*") ) {
                                
           //GOOGLE MAP WITH SIMPLE MARKER
            function contactMap() {
              var mapOptions = {
                zoom:  18,
                center: new google.maps.LatLng(-20.70235, 139.49822),
                mapTypeId: google.maps.MapTypeId.ROADMAP
              }
              var map = new google.maps.Map(document.getElementById('map-canvas'),
                                            mapOptions);
            
              var image = 'http://cdn.myld.com.au/2/413/downright-carpentry_fefd562260.png';
              var myLatLng = new google.maps.LatLng(-20.70235, 139.49822); 
              var marker = new google.maps.Marker({
                  position: myLatLng,
                  map: map,
                  icon: image
              });
               var deviceAgent = navigator.userAgent.toLowerCase();
               var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
                if (!agentID) {
                   marker.setAnimation(google.maps.Animation.BOUNCE);
                   setTimeout(function(){ marker.setAnimation(null); }, 5250);
                }
              
            }
            
            google.maps.event.addDomListener(window, 'load', contactMap);

            $('#custom_form').formValidation({
		        validateText: ["name", "phone", "message"], //input id (you can have multiple id's)
		        validateEmail: ["email"], //input id (you can have multiple id's)
		        validateSpam: true 
		         
		    });
	 }
		
  //function calls
  iphone();  
  animations();  
});

function animations(){
   var deviceAgent = navigator.userAgent.toLowerCase();
   var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
        if (!agentID) {
            $("#mylogo").addClass("animated fadeInLeftBig"); 
        }
  
}

function iphone(){
   var deviceAgent = navigator.userAgent.toLowerCase();
   var iphone = deviceAgent.match(/(iphone)/);
        if (iphone) {
          //on orientation changes
          $(window).bind('orientationchange', function(event) {
           //portrait
           if ( orientation == 0 || orientation == 180 || orientation == -180) {
                var contactPage = $("#contact-us").length;
                if(contactPage > 0){
                  location.reload(); 
                }
              }
          });
            

        }
}

//shuffle
(function($){
	$.fn.shuffle = function() {
		return this.each(function(){
			var items = $(this).children().clone(true);
			return (items.length) ? $(this).html($.shuffle(items)) : this;
		});
	}
	$.shuffle = 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); 