$(document).ready(function() {

	$("a[rel^='prettyPhoto']").prettyPhoto({
		overlay_gallery: false
	});

	$('body.home .slider').advancedSlider({
		        width:648, 
		        height:328, 
		        effectType:'fade',
		        sliceDuration: 2000,
		        sliceDelay: 500,
		        navigationButtons: false,
		        horizontalSlices:1, 
		        verticalSlices:1,
		        backgroundColor: 'transparent',
		        slideshow: true,
		        shadow:false,
		        captionPosition: 'custom',
		        captionShowEffect: 'fade',
		        captionLeft: 0,
		        captionTop: 180,
		        captionBackgroundColor: 'transparent',
		        fadeNavigationArrows: false,
		        slideshowControls:false,
		        timerAnimation:false});
		
				$('#tagslider').advancedSlider({
					        width:299, 
					        height:26, 
					        effectType:'fade',
					        sliceDuration: 2000,
					        sliceDelay: 250,
					        navigationButtons: false,
					        horizontalSlices:1, 
					        verticalSlices:1,
					        backgroundColor: 'transparent',
					        slideshow: true,
					        shadow:false,
					        captionPosition: 'custom',
					        captionShowEffect: 'fade',
					        captionLeft: 0,
					        captionTop: 180,
					        captionBackgroundColor: 'transparent',
					        fadeNavigationArrows: false,
					        slideshowControls:false,
					        timerAnimation:false});
		
				$('.slider').advancedSlider({
					        width:976, 
					        height:248, 
					        effectType:'fade',
					        sliceDuration: 2000,
					        sliceDelay: 500,
					        navigationButtons: false,
					        horizontalSlices:1, 
					        verticalSlices:1,
					        backgroundColor: 'transparent',
					        slideshow: true,
					        shadow:false,
					        captionPosition: 'custom',
					        captionShowEffect: 'fade',
					        captionLeft: 0,
					        captionTop: 180,
					        captionBackgroundColor: 'transparent',
					        fadeNavigationArrows: false,
					        slideshowControls:false,
					        timerAnimation:false});

	//home gallery
	$(".slidetabs").tabs(".images > div", {
		effect: 'fade',
		rotate: true
	}).slideshow();
	
	$("#accordion").accordion({ 
		autoHeight: false,
		active: -1,
		collapsible: true 
	});
	
	$('p.open a').click(function() {
        var el = $('.quick-enquiry');
        if (el.data('open')) {
            el.animate({
                right: '-=304'
            }, 200, function() {
                el.data('open', false);
            });
            el.removeClass('selected');
            
        } 
        else {
           el.animate({
                right: '+=304'
            }, 200, function() {
                el.data('open', true);
            });
            el.addClass('selected');
        } 
        return false;
      
    });
    
    $('#more').hide();
	
	// target the more anchor
	$('#more-toggle').click( function() {
		var anchor = $(this);
		// toggle more text
		$('#more').slideToggle(function() {
			if($(this).is(':hidden')) {
				anchor.removeClass('opened');
			}
			else {
				anchor.addClass('opened');		
			}
		});
	
		return false;
	});
	
	
	//Price Table Swapper
	
    //When page loads...
	$(".price-table").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".price-table:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".price-table").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	
	//News Swapper
	
    //When page loads...
	$(".news-tab").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".news-tab:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".news-tab").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	// Unit sizes map
	(function() {
		// change targets IDs to prevent jumping but keep bookmarkability
		$('#unit-size-map-details div').each(function(i, e) {
			e.id = 'nchr-' + e.id;
		});
		
		$('.unit-map-legend a').click(function(evt) {
			var id = evt.target.hash;
			update(id);
		})
		
		function update(id) {
			if (id) {
				id = id.replace('#', '');
			}
			
			// Update map and price list.
			$('#unit-size-map-details div').each(function(i, e) {
				var real_e_id = e.id.replace(/^nchr-/, '');
				var priceRow = '#' + real_e_id.replace('map-', 'price-');
				$(priceRow).hide();
				if (real_e_id == id || !id) {
					$(e).fadeTo(500, 1);
					$(priceRow).fadeTo(500, 1);
				}
				else {
					$(e).fadeTo(500, 0);
				}
			});
				
			// Update nav.
			$('.unit-map-legend a').each(function(i, e) {
				if (e.hash == '#' + id) {
					$(e).addClass('selected');
				}
				else {
					$(e).removeClass('selected');
				}
			});
		}
		
		// Update map with URL hash
		update(window.location.hash);
	})();
});


$.tools.tabs.addEffect("fadeInOut", function(i, done) {

	this.getPanes().hide();
	
	var nextPane = this.getPanes().eq(i);
	
	nextPane.fadeTo(500, .99, function() {
		done.call();
	});
});



