// UTF8‼
Cufon
.replace('#mainnav a', {
    fontFamily: 'Serpentine-Medium',
    textShadow: '1px 1px rgba(0,0,0,0.75)',
    color: '-linear-gradient(white,0.3=white,0.8=#b4b6b8)',
    hover: {
        color: '-linear-gradient(white,0.1=white,0.8=yellow)'
    }
})
.replace('#content h1, #calendar h1', {
    fontFamily: 'Serpentine-Medium',
    textShadow: '1px 1px rgba(0,0,0,0.75)',
    color: '-linear-gradient(white,0.3=white,0.8=#b4b6b8)'
});

$(document).ready(function () {

    $('html').addClass('jquery-active');

    $('.racereport, #gameterms').jScrollPane({ scrollbarWidth: 24, scrollbarMargin: 0, dragMaxHeight: 38 });

    if (/MSIE\s(5\.5|6\.)/.test(navigator.userAgent)) {
        DD_belatedPNG.fix('#wrapper1,#logo,header nav ul');
    }

    if (swfobject.hasFlashPlayerVersion("9")) {
        swfobject.embedSWF(
			v_url_root + "media/swf/home.swf",
			"homefeature",
			904,
			558,
			"9.0.19.0",
			v_url_root + "media/swf/expressInstall.swf",
			{
			    v_url_root: v_url_root
			}, {
			    bgcolor: "000000",
			    menu: "false",
			    wmode: "opaque"
			}, {
			    id: "homefeature",
			    name: "homefeature"
			}
		);
        swfobject.embedSWF(
			v_url_root + "media/swf/summarytouringmov.swf",
			"summarytouringmov",
			904,
			556,
			"9.0.19.0",
			v_url_root + "media/swf/expressInstall.swf",
			{
			    v_url_root: v_url_root
			}, {
			    bgcolor: "ffffff",
			    menu: "false",
			    wmode: "opaque"
			}, {
			    id: "summarytouringmov",
			    name: "summarytouringmov"
			}
		);
    }

    //	var mainnavinterval = setInterval(f_mainnavreset,1000);
    var mannavspd = ((/MSIE (\d+\.\d+);/.test(navigator.userAgent) == false) ? 500 : 0);
    var foo = {};
    //	$.data(foo,'mannavhover',false);
    $.data(foo, 'gallerymain', 'a');
    $('#mainnav li.current ul').show();
    $('#mainnav a.tab').click(function () {
        var temp = $(this).parent();
        if (mannavspd == 0) {
            tempsummary = $('#' + temp.children('a.tab').attr('id').replace('ctl00_mainnav', 'summary')).stop(true, true).show();
            $('#summaries .summary').not(tempsummary).stop(true, true).hide();
            temp.children('a.tab').stop(true, true).css({ backgroundPosition: 'left -273px' });
            temp.children('ul').stop(true, true).show(mannavspd);
            $('#mainnav li.tab').not(temp).children('a.tab').stop(true, true).css({ backgroundPosition: 'left -238px' }, mannavspd);
            $('#mainnav li.tab').not(temp).children('ul').stop(true, true).hide();
        } else {
            tempsummary = $('#' + temp.children('a.tab').attr('id').replace('ctl00_mainnav', 'summary')).stop(true, true).fadeIn(500);
            $('#summaries .summary').not(tempsummary).stop(true, true).fadeOut(500);
            temp.children('a.tab').stop(true, true).animate({ backgroundPosition: 'left -273px' }, mannavspd / 2, 'linear');
            temp.children('ul').stop(true, true).show(mannavspd);
            $('#mainnav li.tab').not(temp).children('a.tab').stop(true, true).animate({ backgroundPosition: 'left -238px' }, mannavspd);
            $('#mainnav li.tab').not(temp).children('ul').stop(true, true).hide(mannavspd);
        }
        return false;
    });
    //	$('#mainnav li.tab').hover(function(){
    //		// Stop Interval
    //		$.data(foo,'mannavhover',true);
    //		var temp = $(this);
    //		var tempiscurrent = $(this).hasClass('current');
    //
    //		if (mannavspd == 0) {
    //			tempsummary = $('#' + temp.children('a.tab').attr('id').replace('ctl00_mainnav','summary')).stop(true,true).show();
    //			$('#summaries .summary').not(tempsummary).stop(true,true).hide();
    //
    //			temp.children('a.tab').stop(true,true).css({backgroundPosition:'left -273px'},mannavspd/2,'linear');
    //			temp.children('ul').stop(true,true).show(mannavspd);
    //			$('#mainnav li.tab').not(hover).children('a.tab').stop(true,true).css({backgroundPosition:'left -238px'},mannavspd);
    //			$('#mainnav li.tab').not(hover).children('ul').stop(true,true).hide(mannavspd);
    //		} else {
    //			if (tempiscurrent == false) {
    //				tempsummary = $('#' + temp.children('a.tab').attr('id').replace('ctl00_mainnav','summary')).stop(true,true).fadeIn(500);
    //			}
    //			$('#summaries .summary').not(tempsummary).stop(true,true).fadeOut(500);
    //
    //			temp.children('a.tab').stop(true,true).animate({backgroundPosition:'left -273px'},mannavspd/2,'linear');
    //			temp.children('ul').stop(true,true).show(mannavspd);
    //			$('#mainnav li.tab').not(hover).children('a.tab').stop(true,true).animate({backgroundPosition:'left -238px'},mannavspd);
    //			$('#mainnav li.tab').not(hover).children('ul').stop(true,true).hide(mannavspd);
    //		}
    //	},function(){
    //		// Restart Interval
    //		$.data(foo,'mannavhover',false);
    //		var temp = $(this);
    //		var tempsummary = $('#' + temp.children('a.tab').attr('id').replace('ctl00_mainnav','summary'));
    //		if (mannavspd == 0) {
    //			temp.children('a.tab').stop(true,true).css({backgroundPosition:'left -238px'},mannavspd/2,'linear');
    //			tempsummary.stop(true,true).hide();
    //		} else {
    //			temp.children('a.tab').stop(true,true).animate({backgroundPosition:'left -238px'},mannavspd/2,'linear');
    //			tempsummary.stop(true,true).fadeOut(500);
    //		}
    //		temp.children('ul').stop(true,true).hide(mannavspd);
    //	});
    //
    //	function f_mainnavreset() {
    //		if ($.data(foo,'mannavhover') == false) {
    //			$('#mainnav li.tab').each(function(){
    //				var temp = $(this);
    //				if (temp.hasClass('current')) {
    //					if (mannavspd == 0) {
    //						temp.children('a.tab').stop(true,true).css({backgroundPosition:'left -273px'},mannavspd/2,'linear');
    //					} else {
    //						temp.children('a.tab').stop(true,true).animate({backgroundPosition:'left -273px'},mannavspd/2,'linear');
    //					}
    //					temp.children('ul').stop(true,true).show(mannavspd);
    //				} else {
    //					if (mannavspd == 0) {
    //						temp.children('a.tab').stop(true,true).css({backgroundPosition:'left -238px'},mannavspd/2,'linear');
    //					} else {
    //						temp.children('a.tab').stop(true,true).animate({backgroundPosition:'left -238px'},mannavspd/2,'linear');
    //					}
    //					temp.children('ul').stop(true,true).hide(mannavspd);
    //				}
    //			});
    //			$('#summaries .summary').each(function(){
    //				var tempsummary = $(this);
    //				if (tempsummary.hasClass('current')) {
    //					if (mannavspd == 0) {
    //						tempsummary.stop(true,true).show();
    //					} else {
    //						tempsummary.stop(true,true).fadeIn(500);
    //					}
    //				} else {
    //					if (mannavspd == 0) {
    //						tempsummary.stop(true,true).hide();
    //					} else {
    //						tempsummary.stop(true,true).fadeOut(500);
    //					}
    //				}
    //			});
    //		}
    //	}

    $('#eventCalendarMonth').jqueryCal({ xmlPath: v_url_root + 'calendar/xml/?' });

    $('#gallerythumbs')
	.css({ height: '373px', overflow: 'hidden' }).children('ul')
	.height(function (index, height) {
	    if (height > 373) {
	        $('#gallerythumbs').after(
				$('<ul>').attr('id', 'gallerynav')
				.append(
					$('<li/>').append('▲').click(function () {
					    $('#gallerythumbs ul').css('top', function (index, value) {
					        if (parseInt(value) < 0 && $(this).queue("fx").length < 1) {
					            $('#gallerythumbs ul').animate({ top: parseInt(value) + 75 }, mannavspd);
					        }
					    })
					})
				)
				.append(
					$('<li/>').append('▼').click(function () {
					    $('#gallerythumbs ul').css('top', function (index, value) {
					        if (parseInt(value) > (373 - height + 2) && $(this).queue("fx").length < 1) {
					            $('#gallerythumbs ul').animate({ top: parseInt(value) - 75 }, mannavspd);
					        }
					    })
					})
				)
			);
	    }
	});

    $('#gallerythumbs.photos a').click(function () {
        var gallerymain_new = (($.data(foo, 'gallerymain') == 'a') ? 'b' : 'a');
        // Fade Out Current 
        $('#gallerymain_' + $.data(foo, 'gallerymain')).stop(false, false).animate({ opacity: 0 }, mannavspd);
        // Make Sure New Starts Hidden
        $('#gallerymain_' + gallerymain_new).stop(false, false).css({ opacity: 0 });
        // Load Image
        var img = new Image();
        $(img)
		.load(function () {
		    $('#gallerymain_' + gallerymain_new).html(this).stop(false, false).animate({ opacity: 1 }, mannavspd);
		    $.data(foo, 'gallerymain', gallerymain_new);
		})
		.error(function () {
		    $('#gallerymain_' + gallerymain_new).html('Error Loading Image').stop(false, false).animate({ opacity: 1 }, mannavspd);
		    $.data(foo, 'gallerymain', gallerymain_new);
		})
		.attr('src', $(this).attr('href'));
        return false;
    });

    $('#gallerythumbs.videos a').click(function () {
        if (swfobject.hasFlashPlayerVersion("9")) {
            swfobject.embedSWF(
				$(this).attr('rel'),
				'gallerymain',
				620, 413,
				'7.0.19.0',
				v_url_root + 'media/swf/expressInstall.swf',
				{
				    variable: ''
				},
				{
				    allowFullScreen: 'true',
				    allowscriptaccess: 'always',
				    menu: 'false',
				    wmode: 'opaque'
				},
				{
				    id: 'gallerymain',
				    name: 'gallerymain'
				}
			);
        }
        return false;
    });
    $('#gallerythumbs.videos a:first').click();

    if ($("#racereports li").length > 4) {
        $("#racereports").jCarouselLite({
            vertical: true,
            hoverPause: true,
            visible: 4,
            auto: 1000,
            speed: 1000
        });
    }

    if ($("#racereports_fullpage li").length > 9) {
        $("#racereports_fullpage").jCarouselLite({
            vertical: true,
            hoverPause: true,
            visible: 9,
            auto: 4000,
            speed: 1000
        });
    }


    $("#btccnews").jCarouselLite({
        vertical: true,
        hoverPause: true,
        visible: 2,
        auto: 1000,
        speed: 1000
    });

   
         
    $('#slideshow').cycle();


});
