/********************************************************************
Initialise background and set up scroll for iPad and iPhone, Cufon
********************************************************************/
var showBgImage;
$(document).ready(function(){
initBackground();
setupiPadPageScroll();
jQuery('#mycarousel').jcarousel();
$("#pikame").PikaChoose({carousel:true});
$("#signUpForm").validate();
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('h3');	
Cufon.replace('#navbar ul li a', {hover: 'true'});
Cufon.replace('#subnavbar ul li a', {hover: 'true'});
Cufon.replace('nav#secondnavcontainer li a', {hover: 'true'});
Cufon.replace('#secondnavlist ul li a', {hover: 'true'});
Cufon.replace('.feature-text',{fontWeight:'bold'} );	
Cufon.replace('.feature-link');
Cufon.replace('.feature-link span',{fontWeight:'bold'} );
Cufon.replace('.slide-out-div h1');
Cufon.replace('.h1 span',{fontWeight:'bold'} );
Cufon.replace('#signUpForm label',{fontWeight:'bold'} );


/************* FANCY BOX (LIGHTBOX ALTERNATIVE FOR GALLERY **********/
$("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					
		}
});

/************* SLIDE OUT TABS **********/
$('.slide-out-div').show().tabSlideOut({ /* bauhaus concept */
   tabHandle: '.handle',                               //class of the element that will be your tab
   pathToTabImage: 'http://www.thebauhaus.co.uk/images/tabs/concept_tab.png',    //path to the image for the tab (optionaly can be set using css)
   imageHeight: '165px',                               //height of tab image
   imageWidth: '51px',                                 //width of tab image    
   tabLocation: 'left',                                //side of screen where tab lives, top, right, bottom, or left
   speed: 800,                                         //speed of animation
   action: 'click',                                    //options: 'click' or 'hover', action to trigger animation
   topPos: '140px',                                    //position from the top
   fixedPosition: true                                 //options: true makes it stick(fixed position) on scroll
});
$('.slide-out-div2').show().tabSlideOut({ /* book a room */
   tabHandle: '.handle2', 
   pathToTabImage: 'http://www.thebauhaus.co.uk/images/tabs/bookroom_tab.png',
   imageHeight: '165px',  
   imageWidth: '51px',  
   tabLocation: 'right', 
   speed: 800, 
   action: 'click',  
   topPos: '140px',
   fixedPosition: true, 
   onLoadSlideOut: false 
});
}); 



/**********************************************************************
Functions to manipulate background image when resizing browser window
**********************************************************************/
function initBackground() {
$(window).resize(backgroundResizeHandler);
$(window).trigger('resize');
};
var backgroundResizeHandler = function() {

if(browser.isIPad || browser.isIPhone) {
if($('#background').length == 0 && latestImageFile != "") {
// create background div
var bg = document.createElement("div");
bg.setAttribute("id","background");
bg.setAttribute("class", "vertical");
// create image
var bgImg = document.createElement("img");
bgImg.setAttribute("src", latestImageFile);
bg.appendChild(bgImg);
document.body.insertBefore(bg, document.getElementById("footer"));
}
}

if ($('#background img').height() == 0 || $('#background img').width() == 0) {
setTimeout(function() { $(window).trigger('resize'); }, 100);
return;
}

var landscape = false;
if(browser.isIPad || browser.isIPhone) {
landscape = (window.orientation % 180) ? true : false;
if (!$('#background').addClass('vertical')) {
$('#background').addClass('vertical').removeClass('horizontal');
}
$('#background').removeClass('horizontal');
$('#background img').css('marginLeft', -1 * parseInt($('#background img').width() / 2));
}

else {
if ($('#background').hasClass('horizontal')) {
if ($('#background img').height() < $('#background').height()) {
$('#background').addClass('vertical').removeClass('horizontal');
$('#background img').css('marginLeft', -1 * parseInt($('#background img').width() / 2));
}
} else {
if ($('#background img').width() < $('#background').width()) {
$('#background').addClass('horizontal').removeClass('vertical');
$('#background img').css('marginLeft', 0);
}
}
}
};

/*******************************************************************************
Function to set up page scrolling on iPads and iPhones - fixed header and footer
*******************************************************************************/
function setupiPadPageScroll() {
var path = location.pathname.substring(0);
var url = location.href;
// if browser is iPad or iPhone
if((browser.isIPad || browser.isIPhone)) {
// stop the window from scrolling
document.body.addEventListener("touchmove", touchMove, false);
// Create a new YUI instance and populate it with the required modules.
YUI().use('scrollview', function (Y) {
// get the initial height of the window
var initialHeight = (Y.DOM.winHeight());
// ScrollView is available and ready for use.
var scrollView = new Y.ScrollView({
id:"pageScrollContainer",
srcNode:"#pagecontainer",
height:initialHeight
});
// render the scrollview
scrollView.render();
// adjust the height of the scrollview when the device orientation changes
Y.on("orientationchange", function (e) {
var orientation = (Y.config.win.orientation % 180) ? "landscape" : "portrait",
prevOrientation = (orientation == "portrait") ? "landscape" : "portrait";
scrollView.set("height", (Y.DOM.winHeight() + 29));
Y.one("body").replaceClass(prevOrientation, orientation);
});
});
}

}
function touchMove(event) {
event.preventDefault();
}
/**********************************************************************
Function to handle the rollover capsliders on the home page.
**********************************************************************/
$(function() {
     $("#capslide_img_cont").capslide({
         caption_color	: '#fff',
         caption_bgcolor	: '#000',
         overlay_bgcolor : 'black',
         border			: '',
         showcaption	    : true
      });
				
	  $("#capslide_img_cont2").capslide({
          caption_color	: '#fff',
          caption_bgcolor	: '#000',
          overlay_bgcolor : 'black',
          border			: '',
          showcaption	    : true
       });
				
	   $("#capslide_img_cont3").capslide({
           caption_color	: '#fff',
           caption_bgcolor	: '#000',
           overlay_bgcolor : 'black',
           border			: '',
           showcaption	    : true
       });
				
	   $("#capslide_img_cont4").capslide({
           caption_color	: '#fff',
           caption_bgcolor	: '#000',
           overlay_bgcolor : 'black',
           border			: '',
           showcaption	    : true
       });
});
/**********************************************************************
Function for gallery slider at foooter
**********************************************************************/
	jQuery(function($) {
		var open = false;
		$('#footerSlideButton').click(function () {
			if(open === false) {
				$('#footerSlideContent').animate({ height: '103px' });
				$(this).css('backgroundPosition', 'bottom left');
				open = true;
			} else {
				$('#footerSlideContent').animate({ height: '0px' });
				$(this).css('backgroundPosition', 'top left');
				open = false;
			}
		});		
	});

