﻿var pageLoaded = true, storyState = true, propertyNewsCarousel = false, guidesCarousel = null, articleCarousel = null;
$(document).ready(function() { pageLoaded = true; });

(function($) {
    var concertinaOptions = { autoCollapse: true, onChange: OnChange };
    if (concertinaOptions.onChange) {
			$('.concertina').concertina(concertinaOptions);
			$.each($.unique($('.concertinaButton, .concertinaLabel', '.concertina li.concertinaExpandDefault')), function(i, v) {
				concertinaOptions.onChange.call(this, true);
			});
		}



	})(jQuery);
	
	function OnChange(expanded) {
	    if (expanded) {

	        if (!guidesCarousel || !propertyNewsCarousel || !articleCarousel) {
	            var parent = $(this).parents('li');
	            switch (parent.attr('id')) {
	                case 'PropertyNews':
	                    if (!propertyNewsCarousel) {
	                        $('.storyCarousel', '#PropertyNews').jcarousel({ scroll: 2, wrap: 'both', auto: 10,
	                            initCallback: function(carousel) {
	                                propertyNewsCarousel = carousel;
	                                window.FAP.UI.carousel_circleInitCallback(propertyNewsCarousel);

	                                $('> li', '#MortgageConcertina').bind('click', function() {
	                                    window.FAP.UI.stopCarousel(propertyNewsCarousel, $('#PropertyNews'), storyState)
	                                });
	                            }
	                        });

	                    }
	                    break;
	                case 'Guides':
	                    if (!guidesCarousel) {
	                        $('.storyCarousel', '#Guides').jcarousel({ scroll: 4 });
	                        guidesCarousel = true;
	                    }
	                    break;
	                case 'Articles':
	                    if (!articleCarousel) {
	                        $('.storyCarousel', '#Articles').jcarousel({ scroll: 4 });
	                        articleCarousel = true;
	                    }
	                    break;
	            }
	        }

	    }
	}
