$(document).ready(function() { 
	
	
	// Tabs with cookies
	$( "#tabs" ).tabs({
		cookie: {
			// store cookie for a day, without, it would be a session cookie
			expires: 1,
			name: 'tabs-homepage'
		}
	});
	
	// Hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); 
	});

	// Select tab from link
	var $tabs = $('#tabs').tabs(); // first tab selected
	
	// Click tabs
	$('.selfstore-tab-link').click(function() { // bind click event to link
		$tabs.tabs('select', 0); // switch tab
		return false;
	});

	$('.devonmove-tab-link').click(function() { // bind click event to link
		$tabs.tabs('select', 1); // switch tab
		return false;
	});

	$('.pbs-tab-link').click(function() { // bind click event to link
		$tabs.tabs('select', 2); // switch tab
		return false;
	});
	
	// MouseOver images
	$('.selfstore-img-link').mouseover(function() { // bind click event to link
		$tabs.tabs('select', 0); // switch tab
		return false;
	});

	$('.devonmove-img-link').mouseover(function() { // bind click event to link
		$tabs.tabs('select', 1); // switch tab
		return false;
	});

	$('.pbs-img-link').mouseover(function() { // bind click event to link
		$tabs.tabs('select', 2); // switch tab
		return false;
	});
	
		

	//duplicated from selfstorage.js....
	$("#main").scrollable({ 
		// basic settings 
		vertical: true, 
		size: 1, 
		clickable: false, 

		// up/down keys will always control this scrollable 
		keyboard: 'static', 

		// assign left/right keys to the actively viewed scrollable 
		onSeek: function(event, i) { 
		horizontal.scrollable(i).focus(); 
	} 

	// main navigator (thumbnail images) 
	}).navigator("#main_navi"); 

	// horizontal scrollables. each one is circular and has its own navigator instance 
	var horizontal = $(".scrollable").scrollable({size: 1, clickable: false}).navigator(".navi"); 

	// when page loads setup keyboard focus on the first horzontal scrollable 
	horizontal.eq(0).scrollable().focus();

	$('.site-images img').each(function(){
	var maxWidth = 440; // Max width for the image
	var maxHeight = $(this).height();       // Max height for the image
	$(this).css("width", "auto").css("height", "auto"); // Remove existing CSS
	$(this).removeAttr("width").removeAttr("height"); // Remove HTML attributes
	var width = $(this).width();    // Current image width
	var height = $(this).height();  // Current image height

	if(width > maxWidth){
		var ratio = maxWidth / width;   // get ratio for scaling image
		$(this).css("width", maxWidth); // Set new width
		$(this).css("height", height * ratio);  // Scale height based on ratio
		height = height * ratio;        // Reset height to match scaled image
	}
	});

	$(".depot-pages").scrollable({size: 1, speed: 200, clickable: false}).circular().navigator({ navi: "#flowtabs", naviItem: 'a', activeClass: 'current' }); 
	$(".site-images").scrollable({size: 1, speed: 100, nextPage: '.nxtPage', prevPage: '.prvPage'});
	$("#cfStartDate").datepicker({ dateFormat: 'dd/mm/yy' });
	//$(".depot-pages").accordion();
});



function setsite (num) {
    if (num == 1) {
      document.getElementById('phone').innerHTML = '<div class="depotname">St Austell Depot</div>01726 817376';
      document.getElementById('bubble').innerHTML = '<strong>St Austell Depot</strong><br />St. Austell Bay Business Park<br />Par Moor Road<br />Par<br />Cornwall PL25 3RF<br />Tel: 01726 817376';
      document.getElementById('bubble').style.top = '30px';
      document.getElementById('bubble').style.left= '15px';
    }

    if (num == 2) {
      document.getElementById('phone').innerHTML = '<div class="depotname">Plymouth Depot</div>01752 895999';
      document.getElementById('bubble').innerHTML = '<strong>Plymouth Depot</strong><br />Abbots Close<br />Lee Mill Industrial Estate<br />Ivybridge<br />Plymouth PL21 9GA<br />Tel: 01752 895999';
      document.getElementById('bubble').style.top = '33px';
      document.getElementById('bubble').style.left= '100px';
    }

    if (num == 3) {
      document.getElementById('phone').innerHTML = '<div class="depotname">Torquay Depot</div>01803 290336';
      document.getElementById('bubble').innerHTML = '<strong>Torquay Depot</strong><br />Torre Station Yard<br />Newton Road<br />Torre<br >Torquay TQ2 5DD<br />Tel: 01803 290336';
      document.getElementById('bubble').style.top = '20px';
      document.getElementById('bubble').style.left= '170px';
    }

    if (num == 4) {
      document.getElementById('phone').innerHTML = '<div class="depotname">Ipplepen Depot</div>01803 812570';
      document.getElementById('bubble').innerHTML = '<strong>Ipplepen Depot</strong><br />Dainton Manor<br />Dainton<br />Ipplepen<br />Devon TQ12 5TZ<br />Tel: 01803 812570';
      document.getElementById('bubble').style.top = '0px';
      document.getElementById('bubble').style.left= '155px';
    }

    if (num == 5) {
      document.getElementById('phone').innerHTML = '<div class="depotname">Heathfield Depot</div>01626 835547';
      document.getElementById('bubble').innerHTML = '<strong>Heathfield Depot</strong><br />Dainton Business Park<br />Heathfield<br />Newton Abbot TQ12 6RG<br />Tel: 01626 835547';
      document.getElementById('bubble').style.top = '-10px';
      document.getElementById('bubble').style.left= '145px';
    }

    if (num == 6) {
      document.getElementById('phone').innerHTML = '<div class="depotname">Exeter Depot</div>01392 882323';
      document.getElementById('bubble').innerHTML = '<strong>Exeter Depot</strong><br />Greendale Business Park<br />Woodbury Salterton<br />Exeter EX5 1EW<br />Tel: 01392 882323';
      document.getElementById('bubble').style.top = '-35px';
      document.getElementById('bubble').style.left= '175px';
    }

    if (num == 7) {
      document.getElementById('phone').innerHTML = '<div class="depotname">Barnstaple Depot</div>01271 376566';
      document.getElementById('bubble').innerHTML = '<strong>Barnstaple Depot</strong><br />Abbey Field Factory<br />Braunton<br />Barnstaple EX31 1GG<br />Tel: 01271 376566';
      document.getElementById('bubble').style.top = '-90px';
      document.getElementById('bubble').style.left= '115px';
    }

  if (num == 8) {
      document.getElementById('phone').innerHTML = '<div class="depotname">Paignton Depot</div>01803 553874 ';
      document.getElementById('bubble').innerHTML = '<strong>Paignton Depot</strong><br />Alders Way<br />Yalberton Industrial Estate<br />Paignton TQ4 7QL<br />Tel: 01803 553874';
      document.getElementById('bubble').style.top = '20px';
      document.getElementById('bubble').style.left= '165px';
    }

    document.getElementById('bubble').style.display = 'block';
  }

  function restore () {
      document.getElementById('phone').innerHTML = '<div class="depotname">Heathfield Depot</div>01626 835547';
      document.getElementById('bubble').style.display = 'none';
  }
