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

$(document).ready(function(){  
  
  //nav
  $(".nav").appendTo("#mymenu"); 
  $(".navbar.main-nav:first").remove();  
  //header
  myheader();
  
  //footer
  footer();
  $("#ld_branding_link_mobile").remove(); 
  
  //404
  my404();
  
   
  
 
  
  //randomise slider images
  $(".item.active").removeClass("active"); 
  $('.item').eq(Math.floor((Math.random() * $('.item').length))).addClass("active");
  
   //favicon
  $('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="http://cdn.myld.com.au/2/132/alice-hosetech_fc41782f3f.ico" />').appendTo('head');
  
  //********Windows IE8 and below popup*********//   		     		
	$("body").browserDetect( {     	
		name: "Alice Industrial and Hydraulic Service",     
		logo: "http://cdn.myld.com.au/2/309/alice-hosetech_a0d2a84fa9.jpg",      
		phone: "08 8953 8222",     //optional
		//fax: "+123 456 789",      //optional
		email: "accounts@alicehosetech.com.au",      //optional
		address: "28 George Crescent, Alice Springs",  //optional	
		ldprofile: "http://www.localdirectories.com.au/Alice-Springs-Area,NT/Alice-Industrial-Hydraulic-Services–Alice-Hosetech/profile/xiST"  
	});  

	//********Mobile Telephone*********//   
	mobileTel(0889538222); //edit phone number
	
  
  //function calls
  applefix();
 detectIE (); 
 
});//end of doc ready

 


//my404
function my404(){
  var pageName =$("#page-not-found").length;
  if(pageName > 0){
    $("#page-not-found div#error").wrap("<div class='container'>").wrap("<div class='row-fluid'>").wrap("<div class='span12'>"); 
    $("#slider").remove();  
    $(".shadow-image ").remove(); 
  } 
 
}

//footer
function footer(){
 
  var maincontainer =$(".main-container").length; //if the page has a .main-container then put footer in it after myheader otherwise append to body
  if(maincontainer > 0){
        $("footer").appendTo(".main-container");
        $("#footer-branding").insertAfter("footer");
   } else {
     $("footer").addClass("container");
     $("footer").appendTo("body");
     $("#footer-branding").remove();
  }   
}


//myheader
function myheader(){
  var maincontainer =$(".main-container").length; //if the page has a .main-container then put my header in it otherwise prepend to body
  if(maincontainer > 0){
     $(".myheader").prependTo(".main-container"); 
        $("#forhomepage").remove();     
  } else {
    $(".myheader").addClass("container"); 
    $(".myheader").prependTo("body"); 
    $("#forhomepage").remove(); 
  }   
} //end of myheader


//carousel - slider
jQuery(document).ready(function($){   
      
	$('.carousel').carousel({interval: 6000 });
 
 
});


function applefix() {
            var deviceAgent = navigator.userAgent.toLowerCase();
             var ipad = deviceAgent.match(/(ipad)/);
             if(ipad){
              //portrait load
              if ( orientation == 0 || orientation == 180 || orientation == -180) {
                        $(".services-desc").css("height","180px");
                }
               //landscape on load
                if ( orientation == 90 || orientation == 270 || orientation == -90 || orientation == -270) {
                         $(".services-desc").css("height","251px");
                 }

                //if orientation changes
                $(window).bind('orientationchange', function(event) {
                    //landscape
                    if (orientation == 90 || orientation == 270 || orientation == -90 || orientation == -270 ) {
                           $(".services-desc").css("height","251px");
                    }
                    //portrait
                    if ( orientation == 0 || orientation == 180 || orientation == -180) {
                           $(".services-desc").css("height","180px");
                     }
                });
             }
              
            var iphone = deviceAgent.match(/(iphone)/);    //if iphone
                if (iphone) {
                  $(".span8").css("margin-top","25px"); 
                  //portrait load
              if ( orientation == 0 || orientation == 180 || orientation == -180) {
                        $(".services-desc").css("height","180px");
                }
               //landscape on load
                if ( orientation == 90 || orientation == 270 || orientation == -90 || orientation == -270) {
                         $(".services-desc").css("height","120px");
                 }
                //if orientation changes
                $(window).bind('orientationchange', function(event) {
                    //landscape
                    if (orientation == 90 || orientation == 270 || orientation == -90 || orientation == -270 ) {
                           $(".services-desc").css("height","120px");
                    }
                    //Change from landscape to portrait on the contact page forces a reload for alignment
                    if ( orientation == 0 || orientation == 180 || orientation == -180) {
                           var pageName =$("#contact").length;
                           $(".services-desc").css("height","180px");
                          if(pageName > 0){
                            location.reload();
                          }
                     }
                });
                }
        } 

 //form validation 
$(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 **// 
});

function detectIE () {
        if ( $.browser.msie ) {
            var ua = parseInt(jQuery.browser.version.substring(0, 2));
                if ( ua > 8 ) {
                  $('.carousel').carousel({interval: 6000 });
                   $(".services-desc").css("height","215px");
                }
           }
    }
    
