/*Define three t namespace*/
site = { };

/**********************************
* Begin Cufon
**********************************/

//Museo
Cufon.replace('#nav div a', { fontFamily: 'Museo 700' });
Cufon.replace('#content .breadcrumbs span', { fontFamily: 'Museo 500' });

// Set fire to the rain
Cufon.replace
(
	".sftr, #slider .title, #sliderNav a, #news-button, #header-form, #news #content .title, #menu a, #menu div.holder div h6, #content .breadcrumbs h1, #content .breadcrumbs h2, #nursery-main #content .details h3, #nursery-main #content a.title", 
	{ fontFamily: 'Set Fire to the Rain' }
);
/**********************************
* End Cufon
**********************************/

/**********************************
* Dom Ready
**********************************/
$(document).ready(function() 
{	
	
	// Tab menu on nursery-healty-eating
	$(".tabs").children().click(function() 
    {	
	
		// Toggle style css
		if($(this).is('.active')) 
        {
			return;
		}

		// Toggle tab styles
		$(".tabs").children().removeClass("active");
		$(this).addClass("active");
		
		// Hide/show relevant content
		$(".tabs-content").children().removeClass("active");
		$("."+this.id).addClass("active");
	});

	
	
	// Slider on nursery-rooms
	$("#nursery-rooms #content div.slideContent").hide();
	
	
	
	// Title OnClick
	$("#nursery-rooms #content").children('h3').click(function() 
    {
		$(this).nextAll('div:first').slideToggle('slow');
	});
	
	//Image OnClick
	$("#nursery-rooms #content").children('img').click(function() 
    {
		$(this).nextAll('div:first').slideToggle('slow');
	});
	
	
	// Gallery Fancybox
	if($("body").attr("id") == "image-gallery") 
    {
		$("a[rel=gallery]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
    
    // Make all external links open in new window
    $('a:not([href=""])').each(function() 
    {
        if($(this).attr("href")) {
            if ((this.hostname !== location.hostname) && (($(this).attr("href").substr(0, 7) == 'http://') || ($(this).attr("href").substr(0, 8) == 'https://'))) // Check HTTP request type to avoid clashes with JS calls
            {
                $(this).bind("click", function()
                {
                    window.open($(this).attr("href"));
                    return false;
                });
            }
        }
    });

});



/***********************************
* Functions
***********************************/
/*
- Recursive function to deal with cufon/slider issue
- Home Page only
*/
function sliderStyle() 
{
	// Remove cufon tags
	$('#sliderNav').find('a').children('cufon').remove();


	$('#sliderNav').find('a').children('span').each(function() 
    {
		if(this.parentNode.className == 'active') 
        {
			// Active - make white visible
			if(this.className == "green") 
            {
				this.style.display = "none";
			} 
            else 
            {
				this.style.display = "inline";
			}
		} else {
			// Inactive - make green visible
			if(this.className == "green") 
            {
				this.style.display = "inline";
			} 
            else 
            {
				this.style.display = "none";
			}
		}
	});
	setTimeout(sliderStyle, 10);
}


