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

$(document).ready(function(){  

  //nav
  $(".nav").appendTo("#mymenu"); 
  $(".navbar.main-nav:first").remove();
  
  //header
  $("#header").prependTo("body"); //page partial
  $("#slider-bg").insertAfter("#header"); //slider
  
  //logo in navbar
  $(".nav li:nth-child(3)").after('<li class="hidden-logo"><a href="/"><img class="animated bounceInDown" src="http://cdn.myld.com.au/2/307/mcburney-engineering_0a580c225c.png"></a></li>');
  
  //favicon
  $('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="http://cdn.myld.com.au/2/308/mcburney-engineering_595bab277d.ico " />').appendTo('head');
  $('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="http://cdn.myld.com.au/2/231/mcburney-engineering_1a3bd70375.jpg " />').appendTo('head');
  
  //slider
  $('.carousel').carousel(); 
  if( !$("#home").length ) {
    $(".carousel-inner>.item>img, .carousel-inner>.item>a>img").css({"height": "280px","width": "100%"});
  } else {
    $(".carousel-inner>.item>img, .carousel-inner>.item>a>img").css({"height": "350px","width": "100%"});
  }
 

  //404
  $("#page-not-found div#error").wrap("<div class='container'>").wrap("<div class='row-fluid'>").wrap("<div class='span12'>"); 

  //********Windows IE8 and below popup*********//   		     		
	$("body").browserDetect( {     	
		name: "McBurney Engineering",     
		logo: "http://cdn.myld.com.au/2/307/mcburney-engineering_0a580c225c.png",      
		phone: "(07) 4998 5430",     //optional
		 
		email: "mcburneyengineering@bigpond.com",      //optional
		address: "Shed 8/58 Elvin Street Paget QLD 4740",  //optional	
		ldprofile: "http://www.localdirectories.com.au/Mackay-Area,QLD/McBurney-Engineering/profile/FzNs"  
	});  

	//********Mobile Telephone*********//  
	mobileTel("0458 011 762"); //edit phone number

 

	
	//$.backstretch("http://cdn.myld.com.au/2/307/mcburney-engineering_2d1c093549.jpg");
  
  //function calls
   iphone();
   ipad();

});//end of main doc ready

function ipad(){
  var deviceAgent = navigator.userAgent.toLowerCase();
  var ipad = deviceAgent.match(/(ipad)/);
  if(ipad){
     
    $("#content #services .service-pics h2").css({"margin-top":"20px","margin-bottom":"-20px" });
    $("#content .service-item  p").css("padding-top","20px");
    $("#aboutimg").css({"padding-left":"10px","padding-top":"15px"});
     $("#macimg").css({"padding-left":"10px","padding-top":"20px"});
    $(".animated.fadeInLeftBig").removeClass("service-pics box");
    $("#img3").css("text-align","center").removeClass("service-pics box");
    $("#img4").css("text-align","center").removeClass("service-pics box");
    $(".display").css({"padding": "10px 20px 10px 20px"}); 
    $("#content h2").css("font-size","22px");
    $(".main-nav.navbar ul li.active a, .main-nav.navbar ul li a:hover, .main-nav.navbar ul li.active a:hover ").css("height", "19px");
    
    var pageName =$("#contact").length;
        if(pageName > 0){
         $("#content").css("padding-left","65px"); 
         $(".btn.btn-send.btn-large").css("float","right");
         $("#message").css("height","100px"); 
        } 
    //portrait on load
                if ( orientation == 0 || orientation == 180 || orientation == -180) {
                      $("#header ").css({"height": "auto","margin-top":" -20px"});
                       
                }

                //landscape on load
                if ( orientation == 90 || orientation == 270 || orientation == -90 || orientation == -270) {
                     $("#header ").css({"height": "80px","margin-top":" -10px"});
                     
                 }

                //if orientation changes
                $(window).bind('orientationchange', function(event) {
                    //landscape
                    if (orientation == 90 || orientation == 270 || orientation == -90 || orientation == -270 ) {
                        $("#header ").css({"height": "80px","margin-top":"-10px"});
                        $(".sticky h1.title").hide();
                        
                    }
                    //portrait
                    if ( orientation == 0 || orientation == 180 || orientation == -180) {
                       $("#header ").css({"height": "auto","margin-top":" -20px"}); 
                       $(".sticky h1.title").show();
                        
                     }
                });
    
  }
  
}


function iphone(){
  var deviceAgent = navigator.userAgent.toLowerCase();
    var iphone = deviceAgent.match(/(iphone)/);
        if (iphone) {
          
          $("#aboutimg").css("text-align","center");
          $(".display").css({"padding": "10px 20px 10px 20px"}); 
          $(".animated.fadeInLeftBig").removeClass("service-pics box");
          $("#img3").css("text-align","center").removeClass("service-pics box");
          $("#img4").css("text-align","center").removeClass("service-pics box");
          $(".animated.fadeInLeftBig").css("text-align","center");
          $("#map-canvas").css("height","200px");  
            
          var pageName =$("#contact").length;
          if(pageName > 0){
          
           $("#content").css("padding-left","10px");
           $("#message").css("height","100px"); 
          } 
        }
  
}//end iphone


$(document).ready(function(){ 
$("#custom_form").submit(function(){    //** START - SUBMIT FUNCTION **//     
            
    validateText(["first_name", "first_name2"]); // input id (can validate multiple id's)  
    validateEmail(["email", "email2"]); // input id (can validate multiple id's)  
        
    //DO NOT DELETE ***if any inputs on the page have the class 'needsfilled' the form will not submit
        if (($(":input").hasClass("needsfilled")) || ($("form label").hasClass("needsfilled")) || ($("form select").hasClass("needsfilled2"))) 
        return false;
        else return true;
        
    }); //** END - SUBMIT FUNCTION **// 
}); 
