(function($){
function ipadScroll() {
$("#wrapper-bottom").wrapInner("<div id='ipad-scroller'><ul></ul></div>");
	
    $("#wrapper-bottom .content").each(function(){
      alert($(window).height());
      $(this).replaceWith($('<li id="'+$(this).attr('id')+'" class="content">' + $(this).html() + '</li>').height($(window).height()));
    });
    //myScroll = new iScroll('ipad-scroller');
    
    $("#menu a").click(function(){
      // myScroll.scrollToElement($(this).attr('href'));
      $('#ipad-scroller').scrollToElement($(this).attr('href'));
      return false;
    });
	}
$(document).ready(function(){
  // if(!isiPad()){  
  $.localScroll.defaults.axis = "y";
    $("#menu").localScroll({
      queue:true //one axis at a time
    });
  // }else{
    // ipadScroll(); 
//     
  // } 
	
  // default home stretch
  
  $.backstretch("/sites/all/themes/vegas/images/backgrounds/home.jpg", {
    speed: 1000
  });  

  // go1 link animate in
  $("#go1-link").delay(1000).animate({bottom: "30px"}, 1000, function() {});
	
  // go1 link animate in
  $(".socialmedia").delay(1000).animate({bottom: "30px"}, 1000, function() {});	    
    function sliderControl(){
  $("#menu a").not('.menu-139 a').click(function() {
    var link = $(this);
	$("#menu a").removeClass("active");
	$(this).addClass("active");

    $(".backstretch-slide").remove();
			 
    $(".backstretch").delay(2000).fadeOut(1000,function(){
      $(this).delay(1000).remove();
      $.backstretch("/sites/all/themes/vegas/images/backgrounds/"+link.attr('href').replace('#','')+".jpg", {
        speed: 1000
      });
    });		
    
    $("#wrapper-top").animate({top: '60px'}, 500, function(){});
  });
	    }
  sliderControl();
	    
	    
  $("a#close").click(function(){
  $("#slide-nav").remove();
    
    $('#showrooms-slideshow').cycle('stop');
    // Fade out slideshow
    $("#showrooms-slideshow").hide();
    // Fade out controls
    $("#slideshow-controls").hide();
    // Fade In logo + menu
    $("#wrapper-top").fadeIn();
    // Fade in borders
    $(".borders").fadeIn();
    // Fade in Content
    $("#wrapper-bottom").fadeIn();
    return false;
  });
	    
  // Start function 
  function homelink()  {
   // $("#wrapper-bottom").fadeOut();
    //$("#wrapper-top").addClass("home");
    // control background image
			 
    $(".backstretch").fadeOut(1000,function(){
      $(this).delay(1000).remove();
      $.backstretch("/sites/all/themes/vegas/images/backgrounds/home.jpg", {
        speed: 1000
      });
			 
    });
			
    $("#wrapper-top").animate({
      top: '260px'
    }, 500, function(){ // animation complete
      });
  }
  // end function
	      
  $("li.menu-139 a").click(function() {
    homelink();
	$('#menu a').removeClass('active');
	$(this).addClass('active');
	//sliderControl();
  });
	      	     	
  $("#logo-link").click(function() {
    homelink();
    $('#menu a').removeClass('active');
    $("li.menu-139 a").addClass('active');
    return false;
  }); 

		
 // $('#menu a').click(function(){
 //   $('#menu a').removeClass('active');
 //   $(this).addClass('active');
//  });
		
  $("#view-slideshow").click( function() {
    //Slideshow
    $("#showrooms-slideshow").show();
    $("#slideshow-hidden img").each(function(){
      $.backstretchSlideshow($(this).attr("src"),{
        speed:1000
      });
    }); 

    // Start Cycle
    $("#showrooms-slideshow").before('<ul id="slide-nav">');
    $("#showrooms-slideshow").cycle({ 
      fx:     'fade', 
      speed:  'fast', 
      timeout: 5000, 
      pager:  '#slide-nav',
      pagerAnchorBuilder: function(idx, slide) { 
        var src = $("#slideshow-thumbnail img").eq(idx).attr('src');
        return '<li><a href="#"><img src="' + src + '" /></a></li>'; 
      }
    });
    
    // Show slideshow controls   	
    $("#slideshow-controls").fadeIn();
    // Fade out logo & menu
    $("#wrapper-top").fadeOut();
    // Fade out borders
    $(".borders").fadeOut();
    // Fade out content
    $("#wrapper-bottom").fadeOut();
	    	
    return false;	    
  });	
  
  $("#map-link").click(function(){
  $.fancybox('<div id="gmap" style="width:100%;height:100%"></div>',{'overlayColor' : '#FDD2B3','autoDimensions':false,'width':600,'height':350,onComplete:function(){ 
  var latlng = new google.maps.LatLng(-27.478349,153.007622);
   var opts = {
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
	center:latlng
  };
   var map = new google.maps.Map(document.getElementById("gmap"), opts);
      var marker = new google.maps.Marker({
      position: latlng,
      map: map,
      title:"73 Jane St., West End Queensland 4101"
  });
    }});

  return false;
  });
  
});


function isiPad(){
  return navigator.userAgent.match(/iPad/i) != null;
}

})(jQuery)
