$(document).ready(function(){

	/* Multi-col lists */
	if($j('#form1').length == 0){ /* IF FRONTEND */
		$j('.ProjectsContent .Enhance2NewsFeedArticle').wrapAll('<ul></ul>').wrap('<li></li>');
		$j('.ProjectsContent ul').makeacolumnlists({cols:2,colWidth:0,equalHeight:true,startN:1});
	}
	
	/* Map */
	function mapInitialize() {
		if($('#Map').length > 0){
			var centre = new google.maps.LatLng(51.365243,-2.325883);
			var latlng = new google.maps.LatLng(51.365496,-2.322438);
			var latlng2 = new google.maps.LatLng(51.363773,-2.331316);

			var myOptions = {
				zoom: 15,
				center: centre,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};
			var map = new google.maps.Map(document.getElementById("Map"), myOptions);

			var flagimage = new google.maps.MarkerImage('/skin/images/Video-South-Google-icon.png',
				// This marker is 90 pixels wide by 60 pixels tall.
				new google.maps.Size(90, 60),
				// The origin for this image is 0,0.
				new google.maps.Point(0,0),
				// The anchor for this image is the base of the flagpole at 0,60.
				new google.maps.Point(0, 60));
			var flagimage2 = new google.maps.MarkerImage('/skin/images/BMI-Bath-Clinic-Google-icon.png',
				// This marker is 90 pixels wide by 60 pixels tall.
				new google.maps.Size(90, 60),
				// The origin for this image is 0,0.
				new google.maps.Point(0,0),
				// The anchor for this image is the base of the flagpole at 0,60.
				new google.maps.Point(53, 32));
				
			/* Video South Marker */
			var marker = new google.maps.Marker({
				position: latlng,
				map: map,
				title: "Video South",
				icon: flagimage
			});
			/* Bath Clinic Marker */
			var marker2 = new google.maps.Marker({
				position: latlng2,
				map: map,
				title: "BMI Bath Clinic",
				icon: flagimage2
			});

			var infowindow = new google.maps.InfoWindow({
				content: 'Video South'
			});
			var infowindow2 = new google.maps.InfoWindow({
				content: 'BMI Bath Clinic'
			});

			google.maps.event.addListener(marker, 'click', function() {
				infowindow.open(map,marker);
			});
			google.maps.event.addListener(marker2, 'click', function() {
				infowindow2.open(map,marker2);
			});
		}
	}
	mapInitialize();

	/* Right fading images */
	$('.Content .RightContent img').not('.ContentElementControlStrip img, .ContentAreaControlStrip img').each(function() {
		var $this = $(this),
		caption = $this.attr('alt');
		$this.wrap('<div class="Slide"></div>');
		$this.after('<div class="Caption">' + caption + '</div>');
	});
	$j('.Content .RightContent > div').cycle({
	    fx: 'fade',
	    speed: 1500,
		pause: true,
		timeout: 5000,
		slideExpr: '.Slide'
	});

	/* Gallery */
	$('.Gallery .MainContent > div, .SecondContent > div').each(function(groupindex) {
		var $gallery = $(this),
		$thumbnails = $gallery.find('h5'),
		firstThumb,
		firstThumbHref,
		heading;
		if($thumbnails.length > 0){
			$thumbnails.find('img').each(function(index){
				var $this = $(this),
				href = $this.attr('src').replace('/Thumbnail-', '/Library image-');
				if (index == 0) {
					firstThumb = $this.clone();
					firstThumbHref = href;
					$this.remove();
				} else {
					$this.wrap('<a rel="prettyPhoto[group' + groupindex + ']" href="' + href + '"></a>');
				}
			});
			if($('.Gallery').length > 0){
				heading = 'h4';
			}else{
				heading = 'p:last';
			}
			$gallery.find(heading).each(function () {
				if ($(this).children('a').length == 0) {
					$(this).wrapInner('<a href=""></a>');
				}
			});
			$gallery.find(heading + ' a').attr('href', firstThumbHref);
			$gallery.find(heading + ' a').attr('rel', 'prettyPhoto[group' + groupindex + ']');
			firstThumb.css({'display':'none'});
			$gallery.find(heading + ' a').append(firstThumb);
		}

	});
	$j('a[rel^="prettyPhoto"]').prettyPhoto({
		opacity: 0.8,
		default_width: 600,
		default_height: 600,
		autoplay: false,
		markup: '<div class="pp_pic_holder"> \
								<div class="pp_top"> \
									<div class="pp_left"></div> \
									<div class="pp_middle"></div> \
									<div class="pp_right"></div> \
								</div> \
								<div class="pp_content_container"> \
									<div class="pp_left"> \
									<div class="pp_right"> \
										<div class="pp_content"> \
											<div class="pp_loaderIcon"></div> \
											<div class="pp_fade"> \
												<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
												<div class="pp_hoverContainer"> \
													<a class="pp_next" href="#">next</a> \
													<a class="pp_previous" href="#">previous</a> \
												</div> \
												<div id="pp_full_res"></div> \
												<div class="ppt">&nbsp;</div> \
												<div class="pp_details"> \
													<div class="pp_nav"> \
														<a href="#" class="pp_arrow_previous">Previous</a> \
														<p class="currentTextHolder">0/0</p> \
														<a href="#" class="pp_arrow_next">Next</a> \
													</div> \
													<p class="pp_description"></p> \
													<a class="pp_close" href="#">Close</a> \
												</div> \
											</div> \
										</div> \
									</div> \
									</div> \
								</div> \
								<div class="pp_bottom"> \
									<div class="pp_left"></div> \
									<div class="pp_middle"></div> \
									<div class="pp_right"></div> \
								</div> \
							</div> \
							<div class="pp_overlay"></div>'
	});
	
	/*$('.Gallery .MainContent > div h4 a').click(function(){
		$(this).parent('h4').siblings('h5').find('a:first-child').trigger('click');
		return false;
	});*/
	
	/*$('.MainAreaWrapWide .RightContent .Enhance2NewsFeedArticles').cycle({  
	    fx: 'fade', 
	    speed: 1500,
		pause: true,
		timeout: 8000,
		slideExpr: '.Enhance2NewsFeedArticle'
	 });
	 
	$(".HeaderWrap .HeaderImage img").parent('p').addClass('Slide');
	$(".HeaderWrap .HeaderImage .Slide").wrapAll('<div class="slides_container"></div>');

	 $(".HeaderImage").slides({
        pagination: true,
        preload: true,
        preloadImage: '',
        play: 5000,
        pause: 2500,
        hoverPause: true
    });*/
	
	if($j('#form1').length == 0){ /* IF FRONTEND */
		$j(".Home .HeaderImage .Enhance2ContentElement1 .EnhanceContentElementWrap").jCarouselLite({
			auto: 3000,
			speed: 2000
		});
	}
});	
