function flashWrite(flashfile,x,y,flashvar) {
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+ x +"' height='"+ y +"'>");
	document.write("<param name='movie' value='"+ flashfile +"' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='flashvars' value='"+ flashvar +"' />");
	document.write("<param name='wmode' value='transparent' />");
	document.write("<embed src='"+ flashfile +"' wmode='transparent' ");
	document.write("flashvars='"+ flashvar +"'  ");
	document.write("quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ x +"' height='"+ y +"'></embed>");
	document.write("</object>");
}

function printYear() {
	var today = new Date();
	document.write(today.getFullYear());
}

function writeEmail(email) {
	document.write('<a href="mailto:'+email+'">'+email+'</a>');
}

function changeTextSize(textSize) {
	document.body.className = 'site ' + textSize;
	return false;
}
function changeTextSize2(textSize) {
    $('body').removeClass('smallText').removeClass('mediumText').removeClass('largeText').addClass(textSize);
}

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;
}

function serviceRedirect(select){
    if (select.selectedIndex > 0)
        location.href = select[select.selectedIndex].value;
}

var listCount, listWidth, current, carouselTimer;
$(document).ready(function() {
    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'
        });
    }
    $(':first-child').addClass('first');
    $(':last-child').addClass('last');

    $('a[rel=newWindow]').attr('target', '_blank');

    $("div.dub3Content table").attr("border", "0");
    $("div.dub3Content table.datatable tr:even").addClass("normal");
    $("div.dub3Content table.datatable tr:odd").addClass("alternative");

    if ($('ul.feedListing').size() > 0) {
        adidoCarousel();
    }

    if ($("div.featureBox") != null) {
        var maxHeight = 0;
        $("div.dub3Content div.featureBox table").each(function() { if ($(this).height() > maxHeight) maxHeight = $(this).height(); });
        $("div.dub3Content div.featureBox table").height(maxHeight);
    }

    var counter = 0;
    $('table#tblExpanding td').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++;
    });
    $('div.hbPadding').prepend('<div class="hbPaddingHD"></div>');
    $('div.hbPadding').append('<div class="hbPaddingFT"></div>');
    $('a.showHideBlock').click(function() {
        $(this).toggleClass('open');
        $('div#' + $(this).attr('href').substring($(this).attr('href').indexOf('#') + 1)).slideToggle();
        return false;
    });
    $('.lnkAccessibility').click(function(e) {
        e.preventDefault();
        if ($(this).next().hasClass('open')) {
            $(this).next().slideUp().removeClass('open');
        } else {
            $(this).next().slideDown().addClass('open');
        }
    });

    $('.featureBox h2 a').bigTarget({ clickZone: 'div:eq(0)' });

});

function adidoCarousel() {
    jQuery.easing.def = "easeInOutExpo";

    listWidth = $('div#carousel ul.feedListing > li').eq(0).outerWidth();
    listCount = $('div#carousel ul.feedListing > li').size();
    current = 1;
    
    function nextItem() {
        if (current < listCount) {
            current += 1;
        } else {
            current = 1;
        }
        moveCarousel();
    }

    carouselTimer = setInterval(nextItem, 5000);
    $('div#carousel ul.feedListing').width(listCount * listWidth);
    
    $('#btnNext').click(function(e) {
        clearTimeout(carouselTimer);
        e.preventDefault();
        if (current < listCount) {
            current += 1;
        } else {
            current = 1;
        }
        moveCarousel();
    });

    $('#btnPrevious').click(function(e) {
        clearInterval(carouselTimer);
        e.preventDefault();
        if (current > 1) {
            current -= 1;
        } else {
            current = listCount;
        }
        moveCarousel();
    });
    
}

function moveCarousel() {
    $('ul.feedListing').animate({
        left: -((current - 1) * listWidth) + "px"
    }, 500);
    $('#newsPager ul li a').removeClass("selected");
    var itemID = "";
    itemID = "#carouselA_" + current;
    $(itemID).addClass("selected");

}