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;
}

function createPlayer(fileURL, title, width, height) {

    var flashvars = {};
    flashvars.provider = "video";
    flashvars.file = fileURL;
    flashvars.image = "/system/assets/includes/flash/video-preview-1.png";

    var params = {};
    params.wmode = "opaque";
    params.allowfullscreen = "true";
    params.allowscriptaccess = "always";
    
    var attributes = {
        name: "player1"
    };
    swfobject.embedSWF("/system/assets/includes/flash/player.swf", "flashHomeVideo", width, height, "9.0.0", false, flashvars, params, attributes);
    $('#homeVideoTitle').text(title);
}

var player = null;
function playerReady(thePlayer) { player = window.document[thePlayer.id]; }


$(document).ready(function() {
    $("a.videoURL").click(function(e) {
        e.preventDefault();
        fileURL = $(this).attr('href');
        title = $(this).html();
        $("#videoTitle").html(title);
        $("a.videoURL").removeClass("videoTitleActive");
        $(this).addClass("videoTitleActive");

        createPlayer(fileURL, title, 490, 300);
    });


    /*
    player.sendEvent('STOP');
    player.sendEvent('LOAD','/stream/4.flv');
    player.sendEvent('PLAY');
    return false;
    */

    var href = $('#flashVideoFeed ul li:first-child a').attr('href');
    var title = $('#flashVideoFeed ul li:first-child span.title').text();
    if ($('body#home').length > 0) {
        createPlayer(href, title, 276, 180);
    } else {
    createPlayer(href, title, 450, 180);
    }


    $('table#contentTable td#rightCell div#rightColContent a').bigTarget({ clickZone: 'tr:eq(0)' });

    if ($('div.lightbox').length > 0) {
        $('div.lightbox a').lightBox({
            imageLoading: '/system/assets/images/lightbox/lightbox-ico-loading.gif',
            imageBtnClose: '/system/assets/images/lightbox/lightbox-btn-close.gif',
            imageBtnPrev: '/system/assets/images/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/system/assets/images/lightbox/lightbox-btn-next.gif'
        });
    }

    $('a.btnFlashPrev').click(function(e) {
        e.preventDefault();
        $('#flashVideoFeed ul li:last-child').prependTo('#flashVideoFeed ul');
        var href = $('#flashVideoFeed ul li:first-child a').attr('href');
        var title = $('#flashVideoFeed ul li:first-child span.title').text();

        player.sendEvent('STOP');
        player.sendEvent('LOAD', href);
        $('#homeVideoTitle').text(title);
        player.sendEvent('PLAY');

    });
    $('a.btnFlashNext').click(function(e) {
        e.preventDefault();
        $('#flashVideoFeed ul li:first-child').appendTo('#flashVideoFeed ul');
        var href = $('#flashVideoFeed ul li:first-child a').attr('href');
        var title = $('#flashVideoFeed ul li:first-child span.title').text();

        player.sendEvent('STOP');
        player.sendEvent('LOAD', href);
        $('#homeVideoTitle').text(title);
        player.sendEvent('PLAY');
    });



    $(':first-child').addClass('first');
    $(':last-child').addClass('last');
    $('a[rel=newWindow]').attr('target', '_blank');

    $('#customerCarousel ul').adidoCarousel({ buttonNext: '#customerCarouselNext', buttonPrev: '#customerCarouselPrev', startPosition: 2, speed: 6000 });
    $('#newsCarousel ul').adidoCarousel({ buttonNext: '#newsCarouselNext', buttonPrev: '#newsCarouselPrev', resizeMask: true, speed: 6000 });


    $.fn.adidoCarousel.animCallback = function(e, c, s, o) {
        var cli = e.children('li:nth-child(' + c + ')');
        var li = e.children('li');

        li.find('div.bannerContent').hide().end()
        .find('div.bannerContent h2').css({ 'top': '100px' }).end()
        .find('div.bannerContent p').css({ 'top': '100px' });

        cli.find('div.bannerContent').delay(1000).slideDown().end()
        .find('div.bannerContent h2').delay(1250).animate({ top: 0 }).end()
        .find('div.bannerContent p').delay(1500).animate({ top: 0 }).end()
        .find('div.bannerContent p').delay(5500).animate({ top: 160 }).end()
        .find('div.bannerContent h2').delay(6000).animate({ top: 160 }).end()
        .find('div.bannerContent').delay(7000).slideUp();

    }
    $('#banner div.carouselMask ul').adidoCarousel({ clickContinue: false, mode: 'fade', pager: true, pagerElement: '#carouselPager', pagerAuto: true, pagerStyle: 'numeric', speed: 10000 });

    $('div#customerCarousel div.carouselMask').corners();
    $('div#banner').corners();

    var s = 0;
    $("div.homeCol").each(function() {
        if ($(this).height() > s) {
            s = $(this).height();
        }
    }).height(s);
    $('div.homeColMid div.homeColBtm').height(s);

    $('div.formNewsletter input.textBox').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);
        }
    });

});
