// Calendar open/close - script =============================
$(document).ready(function(){ 
	$('a.side-menu-titles').toggle(function() {
		$('div#calendarSlide').slideDown('slow');
		$('a.side-menu-titles span').text('-');
		$('a.side-menu-titles').attr('title', 'close');
	},function() {
  		$('div#calendarSlide').slideUp('slow');
		$('a.side-menu-titles span').text('+');
		$('a.side-menu-titles').attr('title', 'open');
	}
	) 	
}); 
	
// Slideshow - script =============================
$(function() {			    
			    $('#slide').cycle({
			        prev:   '#slide-left',
			        next:   '#slide-right',
			        delay: 2000,
			        speed: 1500,
			        before: onBefore
			    });
			    
			    function onBefore() {
			        $('#slide-title').html(this.alt);
			    }
			});

// Dropdown menu - script =============================
$(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    27,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({ 
            delay:       500,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            
            dropShadows: false                            // disable drop shadows 
        });  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
    }); 

// FanceBox - script =============================			
$(document).ready(function() {
			$("a.iframeLogin").fancybox({ 
				'hideOnContentClick': false,
				'frameWidth':430,
				'frameHeight':300,
				'padding':0,
				'centerOnScroll':true
			}); 
			$("a.iframeContact").fancybox({ 
				'hideOnContentClick': false,
				'frameWidth':670,
				'frameHeight':450,
				'padding':0,
				'centerOnScroll':true
			});
			$("a.group").fancybox({ 
				'zoomSpeedIn': 300, 
				'zoomSpeedOut': 300, 
				'hideOnContentClick': false,
				'centerOnScroll':true
			}); 
			$("a.iframeRegistration").fancybox({ 
				'hideOnContentClick': false,
				'frameWidth':550,
				'frameHeight':400,
				'padding':0,
				'hideOnOverlayClick': false,
				'centerOnScroll':true
			}); 
			$("a.contentimg").fancybox({ 
				'zoomSpeedIn': 300, 
				'zoomSpeedOut': 300
			}); 

		});
		
// Sliding Boxes and Captions with jQuery - script =============================			
$(document).ready(function(){
	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	//Full Caption Sliding (Hidden to Visible)
	$('.boxgrid.captionfull').hover(function(){
		$(".cover", this).stop().animate({opacity: 0.8},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({opacity: 0},{queue:false,duration:160});
	});
});

// Check Font and Change Style - script =============================	
$(document).ready(function () {
	var c = readCookie('style');
	if (c) {
		switchStylestyle(c);
	}
	else {
		font.setup(); // run setup when the DOM is ready
		var x = font.isInstalled("calibri");
		if (x) {
			var style = "style1";
		}
		else 
			var style = "style2";
		switchStylestyle(style);
		return false;
	}
});


var font = (function () {
    var test_string = 'mmmmmmmmmwwwwwww';
    var test_font = '"Comic Sans MS"';
    var notInstalledWidth = 0;
    var testbed = null;
    var guid = 0;
    
    return {
        // must be called when the dom is ready
        setup : function () {
            if ($('#fontInstalledTest').length) return;

            $('head').append('<' + 'style> #fontInstalledTest, #fontTestBed { position: absolute; left: -9999px; top: 0; visibility: hidden; } #fontInstalledTest { font-size: 50px!important; font-family: ' + test_font + ';}</' + 'style>');
            
            
            $('body').append('<div id="fontTestBed"></div>').append('<span id="fontInstalledTest" class="fonttest">' + test_string + '</span>');
            testbed = $('#fontTestBed');
            notInstalledWidth = $('#fontInstalledTest').width();
        },
        
        isInstalled : function(font) {
            guid++;
        
            var style = '<' + 'style id="fonttestStyle"> #fonttest' + guid + ' { font-size: 50px!important; font-family: ' + font + ', ' + test_font + '; } <' + '/style>';
            
            $('head').find('#fonttestStyle').remove().end().append(style);
            testbed.empty().append('<span id="fonttest' + guid + '" class="fonttest">' + test_string + '</span>');
                        
            return (testbed.find('span').width() != notInstalledWidth);
        }
    };
})();



function switchStylestyle(styleName)
	{
		$('link[@rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		createCookie('style', styleName, 365);
	}

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions


