function printYear() {
	var today = new Date();
	document.write(today.getFullYear());
}

function changeTextSize(textSize) {
	$('body').addClass(textSize);
	//return false;
}

function printPage() {
	window.print();
	return false;
}

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 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;
}

$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
        padding: 40,
        showTitle: false,
        theme: 'dark_rounded'
    });

    var counter = 0;    
    $('div.hiddenDiv').each(function(){
        $(this).children('h2:first').replaceWith('<h2><a href="#hiddenBlock' + counter + '" class="showHideBlock">' + $(this).children('h2').text() + '</a></h2>');
        $(this).children().not('h2:first').wrapAll('<div id="hiddenBlock' + counter + '" class="hbPadding"></div>');
        $('div#hiddenBlock' + counter).hide();
        counter++;
    });    
    $('a.showHideBlock').click(function(){
        $(this).toggleClass('open');
        $('div#' + $(this).attr('href').substring($(this).attr('href').indexOf('#')+1)).slideToggle();            
        return false;
    });    

	if($('div.lightbox').length > 0){
	    $('div.lightbox a').lightBox({
	        imageLoading: '/cms/outertemplates/images/lightbox/lightbox-ico-loading.gif',
	        imageBtnClose: '/cms/outertemplates/images/lightbox/lightbox-btn-close.gif',
	        imageBtnPrev: '/cms/outertemplates/images/lightbox/lightbox-btn-prev.gif',
	        imageBtnNext: '/cms/outertemplates/images/lightbox/lightbox-btn-next.gif'
        }); 
    }
    if (IE6){
        $(':first-child').addClass('first-child');
        $(':last-child').addClass('last-child');
    }
    $('blockquote').wrapInner($('<span class="bqInner"></span>'));
        
    /* Footer expanding text */
    $('div.footerText').hide();
    $('ul#footerSubNav a').click(function(e){
        $('ul#footerSubNav a').removeClass('open');
        var target = $($(this).attr('href'));
        e.preventDefault();
        $('div.footerText').hide();
        $('div.footerText').not(target).removeClass('shown');
        if (target.hasClass('shown')){
            target.hide();
            target.removeClass('shown');
        } else {
            target.show();
            target.addClass('shown');
            $(this).addClass('open');
        }
    });
    
    /* News Ticker (Home page) */
    var newsItemCount = $('ul#newsTicker li').size();
    if (newsItemCount > 0){
        var currentNewsItem;
        var newsItemHeight = $('ul#newsTicker li').eq(0).innerHeight();
        
        setInterval(function(){
            $('ul#newsTicker li:first-child').animate({
                marginTop : "-17px"
            }, function(){
                $('ul#newsTicker li:first-child').remove()
                    .appendTo($('ul#newsTicker'))
                    .css({marginTop : 0});
            });
        }, 5000);
    }
    
    /* Home Feature */
    var stepCount = $('#homeFeature div.step').size();
    var timeBetweenFades = 2000;
    
    if (stepCount > 0 && !IE6){
        $('#homeFeature div.step').hide();
        var repeatAnimation = setInterval(function(){
            resetAnimation();
        }, 15000);
        resetAnimation();
    }
    
});

var stepCount = $('#homeFeature div.step').size();
var timeBetweenFades = 2000;

function resetAnimation(){
    var fadeTimeout = new Array(stepCount);
    var currentStep = new Array(stepCount);
    for (var n=0; n < stepCount; n++){
        clearTimeout(fadeTimeout[n]);
    }
    $('#homeFeature div.step').fadeOut(300)
                              .each(function() {
        var i = $('#homeFeature div.step').index($(this));
        currentStep[i] = $(this);
        fadeTimeout[i] = setTimeout(function(){
            currentStep[i].fadeIn(300);
        }, (i+1) * timeBetweenFades);
    });
}

function removeLeftCol() {
    // Remove left column (navigation) when there is no menu to display
    $('body').addClass('noLeftCol');
}