$(document).ready(function() {

	//TOGGLE SCRIPT
	$(".flowToggle").flowToggle(
		{
			//	DEFAULTS
			// showHideSelector : ".flowShowHide",
			// toggleText : "",
			// toggleTextAfter : "",
			// hideToggle : false

			showHideSelector : ".flowShowHide",
			toggleText : "Continue reading",
			toggleTextAfter : "Close this",
			hideToggle : false
		}
	);

	//GLOBAL NOTIFICATIONS
	$(".notification").removeClass('noScript').addClass('hasScript').slideDown();

	$(".notification div").append("<a href='#' class='closethis'>&times;</a>");

	$(".notification").click(function(){
		$(".notification").fadeOut();
	});

	if(!$(".notification").hasClass('sticky'))
	{
	}
		

	//LIGHTBOX
	$('a.lightbox').lightBox({
		fixedNavigation : true
	}); // Select all links with lightbox class

	//SUPERFISH
	$('ul.sf-menu').superfish({
		pathClass:     'current' // the class you have applied to list items that lead to the current page
	}); 
	
	$('.tabs-box').tabs();
	

	//SLIDESHOWS
	makeSlideShow($('.promoSlide'));
	// makeSlideShow($('.flickr-feed'));
	
	function makeSlideShow(promoSlide){
		
		var h = promoSlide.find('img').height();
		var w = promoSlide.find('img').width();
		promoSlide.height(h);
		promoSlide.width(w);

		promoSlideCSS =	{
							'overflow': 'hidden',
							'background' : '#000 url(/theme/images/loaders/loader_1_black48.gif) center center no-repeat'
						};

		promoSlide.css(promoSlideCSS);	

		// $('#promoSlide .slideItem').height(h).width(w);

		SlideCaptionCSS =	{
								'bottom': -1*$(this).height(),
								'opacity' : '0.7',
								'width' : '100%',
								'position' : 'absolute'
							};
					
		$('#promoSlide .slideCaption').each(function(){
			$(this).css(SlideCaptionCSS);
		});

		function onBefore() {
		}

		function onAfter() {
			sCaption = $(this).find('.slideCaption');
			sCaptionH = -1*sCaption.height();
			sCaption.show().animate({opacity: 0.7}, 500).animate({bottom: "0px"}, { queue:false, duration: 500 }).animate({opacity: 0.7}, 2000).animate({opacity: 0.0, bottom: sCaptionH}, 500);
		}

		function initSlideshow(slideShow)
		{
			slideShow.find('img').fadeIn();
			promoSlide.css({'background' : 'none'});
	
			slideShow.cycle({
			    timeout: 5000, 
				fx: 'fade',
				speed: 1000,
				before: onBefore,
				after: onAfter,
				pause:   1,
				pager: "#pager"			});
		}

		function is_image_loaded(image) {
			if(!image.complete) {
				return false;
			}
			if(typeof image.naturalWidth != "undefined" && image.naturalWidth == 0) {
				return false;
			}
			return true;
		};

		var first_slide = $(promoSlide).find('img:first');

		if(first_slide.length > 0){
			if(is_image_loaded(first_slide.get(0))){
				initSlideshow($(promoSlide));
			} else {
				first_slide.load(function(e) {
					$('#loading').hide();
					initSlideshow($(promoSlide));
				});
			}
		}
		
	}
	

});


