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 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;
}
$(window).load(function() {
    var h = 0;
    $('div.homeBox p').each(function() {
        var th = $(this).height();
        if (th > h) {
            h = th;
        }
    }).height(h);

    var h = $('#middleWrap').height();
    var w = $('#middleWrap').width();

    $('div.bgImg').height(h);
    $('div.bgImg ul li').height(h).width(w).css({ 'display': 'block' });

    $('div.bgImg img').each(function(i, e) {
        var ph = this.offsetParent.offsetHeight;
        var pw = this.offsetParent.offsetWidth;
        var pr = ph / pw; // parent ratio

        var ih = $(this).height();
        var iw = $(this).width();
        var ir = ih / iw; // image ratio

        if (ir < pr) {
            $(this).height(ph);
        } else {
            $(this).width(pw);
        }
    });
    $('div.bgImg ul li.acActive').siblings().hide();
    // $('div.bgImg ul').adidoCarousel({ autoStart: false, buttonNext: 'a.btnImgNext', buttonPrev: 'a.btnImgPrev', mode: 'fade', randStart: true });

});

$(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'
        });
    }



    var w = $('#middleWrap').width();
    $('div.bgImg ul li').css({ 'position': 'relative' }).width(w);
    $('div.bgImg ul').adidoCarousel({ autoStart: false, buttonNext: 'a.btnImgNext', buttonPrev: 'a.btnImgPrev', mode: 'fade', randStart: true });

    $('div#banner ul').adidoCarousel({ autoStart: false, buttonNext: 'a.btnImgNext', buttonPrev: 'a.btnImgPrev', mode: 'fade', resizeMask: true });
    $('div#logoBar ul').adidoCarousel({ buttonNext: 'a.btnImgNext', buttonPrev: 'a.btnImgPrev', mode: 'fade' });

    $('#subNav').corners();

    $('.searchBox input.textBox').focus(function() {
        var t = $(this).attr('rel');
        var v = $(this).val();
        if (v == t) {
            $(this).val('');
        }
    }).blur(function() {
        var t = $(this).attr('rel');
        var v = $(this).val();
        if (v == '') {
            $(this).val(t);
        }
    });

    $('input.textClear').each(function() {
        var v = $(this).val();
        $(this).attr('title', v);
    });
    $('input.textClear').focus(function() {
        var t = $(this).attr('title');
        var v = $(this).val();
        if (v == t) {
            $(this).val('');
        }
    }).blur(function() {
        var t = $(this).attr('title');
        var v = $(this).val();
        if (v == '') {
            $(this).val(t);
        }
    });

    var h = 0;
    $('div#homeContent div.homeBox').each(function() {
        var th = $(this).height();
        if (th > h) {
            h = th;
        }
    }).height(h);

    $('a.lnkDropDown').click(function(e) {
        e.preventDefault();
        var target = $(this).attr('href');
        $(target).slideToggle().siblings('.dropDownContent').hide();
        $(this).children('span').toggleClass('open').end().siblings('a.lnkDropDown').children('span').removeClass('open');
    });

    $('div#subNav ul').first().append($('<li class="cap"></li>'));


    $(':first-child').addClass('first');
    $(':last-child').addClass('last');
    $('a[rel=newWindow]').attr('target', '_blank');
});
