$('html').addClass('json');

  function TitleCase(objField) 
        {
            var objValues = objField.split(" ");
            var outText = "";
            for (var i = 0; i < objValues.length; i++) {
                outText = outText + objValues[i].substr(0, 1).toUpperCase() + objValues[i].substr(1).toLowerCase() + ((i < objValues.length - 1) ? " " : "");
            }
            return outText;
        }
		
var citrusCMS = {
		
	load : function() {
		citrusCMS.coreFunctions();
		if ($('.scrollable')[0]){citrusCMS.scrollable();}
	},
	
		coreFunctions : function(){
		
		$('.openWindow').click(function() {window.open(this.href); return false});
		$('.printWindow').click(function() {window.print()});
		
		
		$('.book').click(function(){
				var left = Math.floor((screen.availWidth - 800) / 2);
				var top = Math.floor((screen.availHeight - 600) / 2);
				window.open($(this).attr('href'), 'book', 'scrollbars=yes, status=yes, left='+left+', top='+top+', width=1040, height=650'); return false;
			});
	
		$('.textform').focus(function() {
			if(this.nodeName != 'SELECT'){
				$('#' + this.id).attr('class', 'textformfocus');
				$('.textform').each(function(){if ($(this).attr('value')=='' && $(this).attr('id')!='file_address'){$(this).attr('value','Enter your ' + TitleCase($(this).attr('id').replace(/_/gi,' ').replace('contact ','').replace('rq1','*').replace('friends','friend\'s')+'...'));} });
				if (this.value.substr(this.value.length-3,3) == '...') {this.value=''; }
						}
			});
		$('.textform').blur(function(){$('#' + this.id).attr('class', 'textform');});
		$('#contents').click(function() {$('.textform').each(function(){if ($(this).attr('value')==''){$(this).attr('value','Enter your ' + TitleCase($(this).attr('id').replace(/_/gi,' ').replace('contact ','').replace('rq1','*').replace('friends','friend\'s')+'...'));} });});
		
		$('#thumbs').galleriffic();
		
		$('.json #nav li div').hide();
		$('.json #nav li div ul').css('opacity', '0');
		$('.json .topnav').hover(function(){	
				$(this).stop().children('div').show();
				rawHeight = $(this).children('div').find('ul').height();
				newHeight = rawHeight/2;
				nextNewHeight = newHeight + 33;
				$(this).children('div').css('top', '-' + nextNewHeight + 'px');
				$(this).stop().children('div').children('ul').animate({ 'opacity' : '1.0', 'left' : '0'}, 225);
			},
			function(){	
				$(this).stop().children('div').children('ul').animate({ 'opacity' : '0', 'left' : '-31px'}, 225, function(){ $(this).parent().hide(); });
		});
		
	},
	
	fancybox : function(){
		$('a.viewlarger').fancybox({
			'overlayOpacity'	:	0.7,
			'overlayColor'		:	'#000000'
		});	
		
	},
	
	scrollable : function(){
		$('.news').scrollable({ vertical: false, circular: true }).navigator('.news .navi');
		$('.offers').scrollable({ vertical: false, circular: true }).navigator('.offers .navi');
	},
	
	
	galleryShow : function(transition) {
		
		// Initialize Advanced Galleriffic Gallery
				var gallery = $('#gallerythumbs').galleriffic({
					delay:                     2500,
					numThumbs:                 3,
					preloadAhead:              10,
					enableTopPager:            true,
					enableBottomPager:         true,
					maxPagesToShow:            7,
					imageContainerSel:         '#galleryslideshow',
					controlsContainerSel:      '#gallerycontrols',
					captionContainerSel:       '#gallerycaption',
					loadingContainerSel:       '#galleryloading',
					renderSSControls:          true,
					renderNavControls:         true,
					playLinkText:              'Play Slideshow',
					pauseLinkText:             'Pause Slideshow',
					prevLinkText:              '&lsaquo; Previous Photo',
					nextLinkText:              'Next Photo &rsaquo;',
					nextPageLinkText:          'Next &rsaquo;',
					prevPageLinkText:          '&lsaquo; Prev',
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					onSlideChange:             function(prevIndex, nextIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
						this.find('#gallerythumbs ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast').end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onPageTransitionOut:       function(callback) {
						if (transition==1){this.show('fast',callback);}else{this.fadeTo('fast', 0.0, callback);}
					},
					onPageTransitionIn:        function() {
						if (transition==1){this.show();}else{this.fadeTo('fast', 1.0);}
					}
				});	
	},
	
	
	
		
	GoogleMap : function(){
		
			var customStyles = [
				{
				  featureType: "all",
				  stylers: [
					{ saturation: -100 }
				  ]
				}
			  ];

			var showmap = new google.maps.LatLng(51.5150562,-0.1732763);
			  var mapOptions = {
				center: showmap,
				zoom: 15,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				styles: customStyles
			  };
			  
			  var map = new google.maps.Map(document.getElementById('googlemap'), mapOptions);
			  
			  var infowindow = new google.maps.InfoWindow(
			{ content: '<p style="width: 200px; height: 70px; color: #555; overflow: hidden;  font: 14px/18px \'Century Gothic W01\'; text-transform: uppercase;"><strong>' + locationName +'</strong><br />' + locationAddress +'<br /><a href="http://maps.google.co.uk/maps?daddr='+ locationPostcode +'" title="Link opens in a new window" target="_blank" class="plan">Plan your journey</a></p>',
				size: new google.maps.Size(39,32),
				position: showmap
			});
			
			
			var image = new google.maps.MarkerImage(
				  '/_img/layup/' + customMarker,
				  new google.maps.Size(24,28),
				  new google.maps.Point(0,0),
				  new google.maps.Point(12,28)
				);
				
				var shadow = new google.maps.MarkerImage(
				  '/_img/layup/marker_shadow.png',
				  new google.maps.Size(42,28),
				  new google.maps.Point(0,0),
				  new google.maps.Point(12,28)
				);
				
				var shape = {
				  coord: [17,0,18,1,19,2,20,3,21,4,22,5,22,6,23,7,23,8,23,9,23,10,23,11,23,12,23,13,23,14,23,15,22,16,22,17,21,18,20,19,19,20,18,21,17,22,16,23,15,24,14,25,14,26,13,27,10,27,9,26,9,25,8,24,7,23,6,22,5,21,4,20,3,19,2,18,1,17,1,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,1,6,1,5,2,4,3,3,4,2,5,1,6,0,17,0],
				  type: 'poly'
				};
				
				var marker = new google.maps.Marker({
				  draggable: false,
				  raiseOnDrag: false,
				  icon: image,
				  shadow: shadow,
				  shape: shape,
				  map: map,
				  position: showmap
				});
			
			google.maps.event.addListener(marker, 'click', function() {
			  infowindow.open(map,marker);
			});
			
			infowindow.open(map);
				
	
}
	
}

$(document).ready(citrusCMS.load);
