//limit text area input
function limitChars(textid, limit, infodiv){
	var text = $('#'+textid).val(); 
	var textlength = text.length;
	if(textlength > limit){
		$('#' + infodiv).html('Please limit your comment to '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
 		return false;
	}
	else{
 		$('#' + infodiv).html('Characters remaining: '+ (limit - textlength));
 		return true;
 	}
}
 
function getOrg(group){
		var RegEx = new RegExp(/[.]*group[\s]{0,1}(\d{1,2})/i);
		var m = RegEx.exec(group);
		if(m)
			return m[1];
		else
			return 'null';
}
//organisers
function orgClick(thelink){
	var listToShow = getOrg($(thelink).attr('class'));
	var listToGo = getOrg($(".raceorganisers UL LI.selected P").attr('class'));
	var listToShowText = $(thelink).text();
	var listToGoText = $(".raceorganisers UL LI.selected P STRONG").text();
	$(".raceorganisers UL LI.selected").html('');
	$("<a></a>")
	.attr({href:"index.aspx#group" + parseInt(listToGo,10)})
	.addClass("group" + parseInt(listToGo,10))
	.text(listToGoText)
	.appendTo(".raceorganisers UL LI.selected")
	.click(function(){
		orgClick(this);
		return false;
	});	
	$(".raceorganisers UL LI.selected").removeClass('selected');	
	$(thelink).parent().addClass('selected');
	$(thelink).parent().html('<p class=group' + listToShow + '><strong>' + listToShowText + '</strong></p>');
	listToShow--;
	for(i=0;i<$('.raceorganisers UL LI').length+1;i++){
	$(".profilelist"+i).hide();
	}
	$(".profilelist"+listToShow).show();
}
 
//tabs
function tabClick(node){
	var clickedtab = $(node.parentNode).attr('class');
	
	var containerDiv =  $(node.parentNode.parentNode.parentNode);
		
	// check for disabled tabs -> section 6 data centre
	if($(node.parentNode).hasClass("disabled")){
		$(".duringRace").show();
		var hideNote = setTimeout(function(){$(".duringRace").hide();},5000);
		return false;
	}else{
		$(".duringRace").hide();
	}
	
	var currentTab = $('DIV.currenttab', containerDiv).slice(0,1);
	
	if (!currentTab.length)
		currentTab = $('DIV.currenttab', $(containerDiv.parentNode)).slice(0,1);
	
	$(currentTab).hide();
	$(currentTab).removeClass('currenttab');
	
	var selectedTab = $('UL.tabs LI.selected', containerDiv).slice(0,1);
		
	var selectedtabtext = $(selectedTab).text();
	// $('UL.tabs LI.selected').html("<a href='#'>"+selectedtabtext+"</a>");
	$(selectedTab).empty();
	//$("UL.tabs LI.selected").append()
	
	$("<a></a>")
	.attr({href:"#"})
	.text(selectedtabtext)
	.click(function(){
		tabClick(this);
		return false;
	})
	.appendTo($(selectedTab));
	
	$(selectedTab).removeClass('selected');
	$(node.parentNode).addClass('selected');
	
	var newtabtext = $(node).text();
	
	var tabToShow = $('DIV.'+clickedtab, containerDiv);
	
	if (!tabToShow.length)
		 tabToShow = $('DIV.'+clickedtab, $(containerDiv.parentNode));

	$(tabToShow).slice(0,1).show();
	$(tabToShow).slice(0,1).addClass('currenttab');
	$(node.parentNode).html("<h2>"+newtabtext+"</h2>");
}


 //ticker
/* amended to handle links or paragraphs October 14th 2008 twentysixlondon.com */
(function($) {
	
	function runTicker(settings) {
		if(settings.firstRun == 1){
			currentLength = settings.currentLength;
			currentItem = settings.currentItem;
			settings.firstRun = 0;
		}
		if(currentItem == settings.newsItemCounter + 1){
			currentItem = 0;
		}
		
		if(currentLength == 0) {
            // handle target="_blank" attribute on links, open link in new window
			nLI = $('<li></li>');
			nP = $('<p></p>')
			.text('Latest:');
			
			if(settings.newsLinks[currentItem] == null){
				package = $('<p></p>')
				.addClass('text');
			}else{
				package = $('<a></a>')
				.attr({href:settings.newsLinks[currentItem]})
				if(settings.newsTarget[currentItem]){
					package = $(package)
					.attr({target:'_blank'})
					.click(function(e){
						window.open($(this).attr('href'));
						e.preventDefault();
					});
				}
			}
			nLi = $(nLI).append(nP).append(package);
			$(settings.newsList).empty().append(nLi);

            /*
			if(settings.newsLinks[currentItem] == null){
				$(settings.newsList).empty().append('<li><p>Latest:</p><p class=\"text\"></p></li>');
			}else{
				$(settings.newsList).empty().append('<li><p>Latest:</p><a href="'+ settings.newsLinks[currentItem] +'"></a></li>');
			}
            */
		}
		
		if( currentLength % 2 == 0) {
				placeHolder = settings.placeHolder1;
		}
		else {
			placeHolder = settings.placeHolder2;
		}
		
		if( currentLength <= settings.newsItems[currentItem].length + 1) {
			var tickerText = settings.newsItems[currentItem].substring(0,currentLength);
			if(settings.newsLinks[currentItem] == null){
				$(settings.newsList + ' li p.text').text(tickerText + placeHolder);
			}else{
				$(settings.newsList + ' li a').text(tickerText + placeHolder);
			}
			currentLength ++;
			setTimeout(function(){runTicker(settings); settings = null;},settings.tickerRate);
		}
		else {
			if(settings.newsLinks[currentItem] == null){
				$(settings.newsList + ' li p.text').text(settings.newsItems[currentItem]);
			}else{
				$(settings.newsList + ' li a').text(settings.newsItems[currentItem]);
			}
			currentLength = 0;
			currentItem ++;
			setTimeout(function(){runTicker(settings); settings = null;},settings.loopDelay);	
			$(settings.newsList + ' li a').css('text-decoration','underline');
		}	
	}
	
	$.fn.extend({
		newsTicker: function(settings) {
			settings = jQuery.extend({
		 	  	newsList: "#news",
		   		tickerRate: 80,
		    	startDelay: 100,
		    	loopDelay: 3000,
		    	placeHolder1: " |",
		    	placeHolder2: "_"
			}, settings);
			
			var newsItems = new Array();
			var newsLinks = new Array();
			var newsTarget = new Array();
			var newsItemCounter = 0;
			
			$(settings.newsList + ' li').each(function(){
			    // handle real P tags in server-side generated HTML
				if($(this).find('p').length != 0){
					node = $(this).find('p');
					newsItems[newsItemCounter] = $(node).text();
					newsLinks[newsItemCounter] = null;
				}else{
					node = $(this).find('a');
					newsItems[newsItemCounter] = $(node).text();
					newsLinks[newsItemCounter] = $(node).attr('href');
 					newsTarget[newsItemCounter] = ($(node).attr('target')) ? $(node).attr('target'): null;
				}
			    /*
			    */

                /*
                // handle case where the system isn't flexible enough to generate P tags, but
                // generates A tags with href="#" to mark plain text
                node = $(this).find('a');
                if($(node).attr('href') == '#'){
                    newsItems[newsItemCounter] = $(node).text();
                    newsLinks[newsItemCounter] = null;
                }else{
                    newsItems[newsItemCounter] = $(node).text();
                    newsLinks[newsItemCounter] = $(node).attr('href');
                    newsTarget[newsItemCounter] = ($(node).attr('target')) ? $(node).attr('target'): null;
                }
                */
				newsItemCounter ++;
			});
			
			settings = jQuery.extend(settings,{
				newsItems: newsItems,
				newsLinks: newsLinks,
				newsTarget: newsTarget,
				newsItemCounter: newsItemCounter - 1,
				currentItem: 0,
				currentLength: 0,
				firstRun:1
			});
			
			setTimeout(function(){runTicker(settings); settings = null;},settings.startDelay);
		}
	
	});
})(jQuery);

function getMenu(menuClasses){
		var topnavRegEx = new RegExp(/(topnav\d{1,2})/);
		var m = topnavRegEx.exec(menuClasses);
		if(m)
			return m[1];
		else
			return 'null';
}

function toggleVisibility(elem)
{
	if (elem.is(':visible'))
	{
		elem.css('display', 'none');
		elem.css('overflow', 'hidden');
	}
	else
	{
		elem.css('display', 'block');
		elem.css('overflow', 'visible');
	}
}
function resetColHeights()
            {	                        
            //leftcol
			        var colHeight = 0;
			        var moduleHeights = $(".col0 .module").slice(0,1);
			        while(moduleHeights.length != 0){				
				        colHeight = colHeight + $(moduleHeights).height() +10;
				        moduleHeights = $(moduleHeights).next();				
			        }
			        var left = colHeight;
		        //rightcol
			        colHeight = 0;
			        moduleHeights = $(".col1 .module").slice(0,1);
			        while(moduleHeights.length != 0){				
				        colHeight = colHeight + $(moduleHeights).height() +10;
				        moduleHeights = $(moduleHeights).next();				
			        }
			        var newHeight = (left > colHeight) ? left : colHeight;			
			        $(".col0,.divider,.col1").css("height",newHeight + "px");
            }
            
//
function showDefaultRData()
{

//jQuery.each($(".racedata .content .edit"), function(i, m) {        
//        showSelectedData($(".racedata .edit:eq(" + i + ")"));       
//    });

//for (var i = 0; i<5;i++)
//{
//    showSelectedData($(".racedata .edit:eq(" + i + ") .cancel"));       
//}

    
//    $(".racedata TABLE TBODY TR").hide();
//    
//    jQuery.each($(".racedata .edit"), function(i, m) {
//        jQuery.each($(".racedata .edit:eq(" + i +") INPUT"), function(j, n) {
//            if($(".racedata .edit:eq(" + i + ") INPUT:eq(" + j + ")").attr("checked")) {
//                $(".racedata .content TABLE:eq(" + i + ") TBODY TR:eq(" + j + ")").show();
//            }
//        })
//    }); 
//    $(".rdcscoreboard TABLE TBODY TR").show();   
}

function showSelectedData(elem)
{
    $(elem).parents().find(".content").slice(0,1).find("TABLE TBODY TR").hide();
    
//    jQuery.each($(elem).parents().find(".content").slice(0,1).find(".edit"), function(i, m) {
//        jQuery.each($(elem).parents().find(".content").slice(0,1).find(".edit:eq(" + i +") INPUT"), function(j, n) {
//            if($(elem).parents().find(".content").slice(0,1).find(".edit:eq(" + i + ") INPUT:eq(" + j + ")").attr("checked")) {
//                $(elem).parents().find(".content").slice(0,1).find("TABLE:eq(" + i + ") TBODY TR:eq(" + j + ")").show();
//            }
//        })
//    });     
    
    for(i=0;i < $(elem).parents().find(".content").slice(0,1).find(".edit INPUT").length;i++)
    {         
        if($(elem).parents().find(".content").slice(0,1).find(".edit INPUT:eq(" + i +")").attr("checked"))
        {
            $(elem).parents().find(".content").slice(0,1).find("TABLE TBODY TR:eq(" + i + ")").show();
        }
    }

}
//limit rdc graphs to 7
$.fn.limit = function(n) {
     var self = this;
     this.click(function(){
     //alert(n + " - " + self.filter(":checked").length==n);
     (self.filter(":checked").length==n)?
         self.not(":checked").attr("disabled",true).addClass("disabled"):
         self.not(":checked").attr("disabled",false).removeClass("disabled");
     });
}
//$("DIV.edit UL LI SPAN input:checkbox").limit(7);

//document ready function
$(document).ready(function(){

        //H1 font-size tweak for Sifred H1 tag (this will leave the non-js/flash version with large text
        $('H1').css('font-size','1.2em');
        //tabs
		if ($('UL.tabs').size() > 0){
			for(i=0;i<$('UL.tabs LI').length+1;i++){
				$("DIV.tab"+i).hide();
				$("DIV.tab"+i+" H2").hide();
			}	
			$("DIV.tab0").show();
			$('.tabs a').click(function () {			  
			  	tabClick(this);
			  	return false;			  
			});
		}
						
		if ($('span#countdown').size() > 0){
				ReportTimer.init();
			}
		
        var $btn = $(".defaultbutton");     
        var $form = $btn.parents(".form");     
        $form.keypress(function(e)
        {
            if (e.which == 13 && e.target.type != "textarea") 
            {             
                if ($btn[0].type == "submit")                 
                    $btn[0].click();             
                else                 
                    eval($btn[0].href);     
                            
                return false;         
            }     
        });

        //dottvwrapper - change border-color of this module to avoid appearance of 1px gap on Right Hand Side
        $("div.dottvwrapper").parents("div.promo").css("border-color","#072343");
        $("div.dottvwrapper").parents("div.promo").css("border-top","none");
		//Main Nav
		if($('#menu').length != 0){
			$('.activemenu UL').show();
			var delayHide = null;
			var activeFirstLevel = getMenu($('.activemenu').attr("class"));
			var activesub = $('.activemenu LI.mainchannel LI A.active').parent().attr("class");
			$('LI.mainchannel').mouseover(function () {
				var menuid = getMenu($(this).parent("UL").slice(0,1).attr("class"));
				// $('.activemenu LI.mainchannel A').removeClass('active');
				$('LI.mainchannel A').removeClass('over');
				if (delayHide) clearTimeout(delayHide);
				$('.' + menuid + ' LI.mainchannel A').addClass('over');
				$('.' + menuid + ' LI.mainchannel LI A').removeClass('over');
				//$('#' + menuid + ' LI LI A')
				$('.activemenu UL').hide();
				$('.mainchannel UL').hide();
							
				$("." + menuid + " UL").show();
			});
			$('LI.mainchannel').mouseout(function () {
				delayHide = setTimeout(function(){$('.mainchannel UL').hide();$('LI.mainchannel A').removeClass('over');$('.activemenu UL').show();$('.ticker').show();$('.activemenu LI.mainchannel A').addClass('active');$('.activemenu LI LI A').removeClass('active');$('.' + activeFirstLevel + ' LI.mainchannel LI.' + activesub + ' A').addClass('active');},500);	
				
			});
		}
		
		// bind action to 'close' button in thickbox overlay / iframe
         $("DIV.overlay SPAN.close A").click(function(e){
             if(self.parent)
             self.parent.tb_remove();
             else
             tb_remove();
             e.preventDefault();
         });
        		
		//SWFobject flash media : documentation ref - http://code.google.com/p/swfobject/wiki/documentation
		var flashvars = {};
		var attributes = {};
		
		if($.cookie("noplaymasthead")){
		 var flashvars = {
		      skip_intro: "yes"
		    };
		}
		else{
		$.cookie("noplaymasthead", "1");
		var flashvars = {
		      skip_intro: "no"
		    };		    
		}
		var params = {
		      scale: "noscale",
		      somename:  "",
		      salign: "LT",
		      menu: false,
		      wmode: "opaque",
		      allowScriptAccess: "always"
		    };
		    
		flashvars.country = VorSettings.lang;
		flashvars.XMLPath = '/xml/MastHead.xml';
		flashvars.XMLPath2 = '/xml/VORinRace-language.xml';
		    
		//swfobject.embedSWF("/flash/2008/VOR_masthead.swf", "flashcontent", "838", "111", "8","expressInstall.swf", flashvars, params, attributes);
		swfobject.embedSWF("/flash/2008/VOR_masthead_progress.swf", "flashcontent", "838", "111", "8","expressInstall.swf", flashvars, params, attributes);
		
		swfobject.embedSWF("/racedata/RDC_showcase_v2.swf", "dataCentreFlash", "960", "413", "8","expressInstall.swf", flashvars, params, attributes);
		swfobject.embedSWF("/racedata/RDC_showcase_v2.swf", "virtualspectator", "960", "413", "8","expressInstall.swf", flashvars, params, attributes);
		swfobject.embedSWF("/rdc/FormGuide_v2.swf", "rdcFormGuide", "636", "722", "8","expressInstall.swf", flashvars, params, attributes);
		//Homepage Image Carousel
		if ($('.latestimagescarousel').size() > 0){
			$('.latestimagescarousel').removeClass('noscriptimglist');
			jQuery('.latestimagescarousel').jcarousel({
			    scroll: 2
			});
		}
		
		//Crew Image Carousel
		if ($('.crewcarousel').size() > 0){
			$('.crewcarousel').removeClass('noscriptcrewlist');
			jQuery('.crewcarousel').jcarousel();
		}
		
		//Homepage Customise Modules Option DIV slide animation
		if ($('.customise_hp_modules').size() > 0){			
			$('#customise_hp_modules').bind('click', function (e) {			 
			 // $('.customise_hp_modules').slideToggle('slow');		
			
			toggleVisibility($('.customise_hp_modules'));
						 	  
			  if($('#customise_hp_modules').hasClass('plus')){
				  $('#customise_hp_modules').removeClass('plus').addClass('minus');
				  sIFR.replaceElement("DIV.customise_hp_modules h2.sifred", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#072343", sWmode: "transparent"}));
			  }else{
				  $('#customise_hp_modules').removeClass('minus').addClass('plus');
			  }
			});			
			$('.cancel').click(function () {
			  $('.customise_hp_modules').slideToggle('slow');
			  if($('#customise_hp_modules').hasClass('plus')){
				  $('#customise_hp_modules').removeClass('plus').addClass('minus');
			  }else{
				  $('#customise_hp_modules').removeClass('minus').addClass('plus');
			  }
			});
		}
		//customise homepage modules
		if ($('.customise_hp_modules').size() > 0){
		    //inster spacer image into each col - ie6 requires this otherwise the col is collapsed when empty
		    $("<img></img>")
                .attr({src:"/images/2008/bg/spacer.gif"})
                .appendTo(".col0,.col1");
            
	        ModuleHelper.init();
		    resetColHeights();
            $(".col0").sortable({ 
                placeholder: "ui-selected", 
                handle: $(".module H2"),
                revert: true,                
                scroll: true,
                cursor: "move",
                zIndex: 5000,
                dropOnEmpty: true,
                sort: resetColHeights,
                stop: resetColHeights,
                connectWith: [".col1"] 
            }); 
	        $(".col1").sortable({ 
		        placeholder: "ui-selected",
		        handle: $(".module H2"), 
		        revert: true,
		        scroll: true,
		        cursor: "move",
		        zIndex: 5000,
		        dropOnEmpty: true,
		        sort: resetColHeights,
                stop: resetColHeights,
		        update: ModuleHelper.saveSettings,
		        connectWith: [".col0"] 
	        });	 
	        $('.collapsebut').click(function () {
	            //$(this).next().slideToggle('slow',resetColHeights);    	        	  
			          if($(this).hasClass('plus')){
				          $(this).removeClass('plus').addClass('minus');
				          $(this).find("img").slice(0,1).attr({ 
					          src: "images/2008/btn/collapse.gif",
					          title: "Collapse",
					          alt: "Collapse"
					        });
					        $('.contentWrapper', this.parentNode).css('display','block');
			          }else{
				          $(this).removeClass('minus').addClass('plus');
				          $(this).find("img").slice(0,1).attr({ 
					          src: "images/2008/btn/expand.gif",
					          title: "Expand",
					          alt: "Expand"
					        });
					        $('.contentWrapper', this.parentNode).css('display','none');
			          }
			          resetColHeights();
			          return false;
			          ModuleHelper.saveSettings();
            });
            $('.editbut').click(function () {
                        //$(this).next().slideToggle('slow');    
                        
                        var settingsPanel = $('.modulesettings', this.parentNode);
                        	        	  
			          if($(settingsPanel).css('display') == 'block'){
				          $(this).find("img").slice(0,1).attr({ 
					          src: "images/2008/btn/edit.gif",
					          title: "Edit",
					          alt: "Edit"
					        });
					        $('.modulesettings', this.parentNode).css('display','none');
			          }else{
				          $(this).find("img").slice(0,1).attr({ 
					          src: "images/2008/btn/edit.gif",
					          title: "Cancel Edit",
					          alt: "Cancel Edit"
					        });
					        $('.modulesettings', this.parentNode).css('display','block');
			          }
			          return false;
            });
        }        
	    /*Homepage Custom Modules toggle collapse
		    if ($('.custommodules').size() > 0){	
			    $('.collapsebut').click(function () {
			      $(this).next().slideToggle('slow');			  
			      if($(this).hasClass('plus')){
				      $(this).removeClass('plus').addClass('minus');
				      $(this).find("img").slice(0,1).attr({ 
					      src: "images/2008/btn/collapse.gif",
					      title: "Collapse",
					      alt: "Collapse"
					    });
			      }else{
				      $(this).removeClass('minus').addClass('plus');
				      $(this).find("img").slice(0,1).attr({ 
					      src: "images/2008/btn/expand.gif",
					      title: "Expand",
					      alt: "Expand"
					    });
			      }
			      ModuleHelper.saveSettings();
			      return false;
			    });
		    }
		    */
		//Homepage Ticker
		/*
		if ($('.ticker').size() > 0){
			$('.ticker').css('display','inline');
			var options = {
			newsList: ".news",
			tickerRate: 60,
			startDelay: 10,
			placeHolder1: "_"
			}
			$().newsTicker(options);
		}
		*/
		if ($('.ticker').size() > 0){
			var tickerRunner = new Ticker.TickerRunner('.ticker');
			tickerRunner.init();
		}
		
		/*show / hide ticker functionality*/
		if ($('#news').size() > 0){
			$("#menu").mouseover(function () {
			  $('.ticker').hide();
			  //setTimeout(function(){$('.ticker').show();},10000);
			  return false;
			});
			/*Note: Ticker show() event is in the Nav code*/
		}
		
		//limit textarea input
		$(function(){
			$("DIV.posttext .commentstextarea").before("<p id='charactercount'>Characters remaining: 500</p>");
			$('DIV.posttext .commentstextarea').keyup(function(){
			    var commentFieldID = $(this).attr("id");
			    limitChars(commentFieldID, 500, 'charactercount');
			})
		});			
		
		//show / hide narrow search results panel
		//$('.selection').hide();
		//$('.togglebut').html("<span class='genericButton plus fl'><input type='button' value='Narrow your search'/></span>");
		$('.narrowresults H2 A').click(function () {			 
			  $('.selection').slideToggle('slow');
			  var text = $('.narrowresults H2 SPAN').text();
			  if(text == "[+]"){
				  $('.narrowresults H2 SPAN').text('[-]');
			  }
			  else{
				  $('.narrowresults H2 SPAN').text('[+]');
			  }
			  return false;
			});
		
		$('.togglebut INPUT').click(function () {			 
			  $('.selection').slideToggle('slow');			  
			  if($('.togglebut SPAN').hasClass('plus')){
				  $('.togglebut SPAN').removeClass('plus').addClass('minus');
			  }else{
				  $('.togglebut SPAN').removeClass('minus').addClass('plus');
			  }
			});
		
		//show / hide comments
		//$('.comments UL').hide();
		$('.comments H3 A').click(function () {			 
			  $('.comments UL').slideToggle('slow');
			  if($('.comments H3').hasClass('closed')){
				  $('.comments H3').removeClass('closed').addClass('open');
			  }else{
				  $('.comments H3').removeClass('open').addClass('closed');
			  }
			  return false;
			});
		
		//show / hide post
		//$('.post .posttext').hide();
//		$('.post H3 A').click(function () {			 
//			  $('.post .posttext').slideToggle('slow');
//			  if($('.post H3').hasClass('closed')){
//				  $('.post H3').removeClass('closed').addClass('open');
//			  }else{
//				  $('.post H3').removeClass('open').addClass('closed');
//			  }
//			  return false;
//			});		
			
		// bind action to 'close' button in thickbox overlay / iframe
		$("DIV.overlay SPAN.close A").click(function(e){
			self.parent.tb_remove();
			/*
			if(self.parent){
				self.parent.tb_remove();
			}else{
				tb_remove();
			}
			*/
			e.preventDefault();
		});

			/*$("UL.imageGrid LI A").click(function(e){
			var imageRef = $(this).parent("LI").slice(0,1).attr("class");
			var imageNumber = imageRef.substring(2,imageRef.length);
			var imageWidth,imageHeight;
			switch(imageNumber){
				case 1,10:
				{
					imageWidth = 312;
					imageHeight = 208;
				}
				break;
				default:
				{
					imageWidth = 150;
					imageHeight = 100;
				}
				break;
			}
			
			var loaderDiv = $("#TB_window DIV.loader");
			
			if (!loaderDiv.length)
			{
				$("<div>")
				.attr({"class":"loader"})
				.appendTo("#TB_window");
			}
			
			// alert(imageRef + "/" + imageNumber + "/" + imageWidth + "/" + imageHeight);
			$("#TB_window DIV.loader").empty();
			$("<img>")
			.attr({"src":"/images/2008/content/image" + imageNumber + ".jpg","width":600,"height":400})
			.appendTo("#TB_window DIV.loader");
			
			// $("#TB_window DIV.loader").html("<p>" + imageRef + "</p>");
			// e.preventDefault();
		});*/
		/* pass parameter into inline thickbox content
		*/ 

        /* 3D boat viewer overlay */
		$('<div></div>')
		.attr({id:'bv_overlay'})
		.appendTo('BODY');

        $('.boatViewer').click(function(e){
	        $('#bv_overlay').show();
	        $('#boatViewer').show();
	        e.preventDefault();
        });

        if($('#boatViewer').length != 0){
	        $('.threeDBVCLoser').click(function(e){
		        $('#boatViewer').hide();
		        $('#bv_overlay').hide();
		        e.preventDefault();
	        });
            // embed flash video - 3D boat viewer flash applet
	        var flashvars = {};
	        var attributes = {};
	        var params = {
	          scale: "noscale",
	          somename:  "",
	          salign: "LT",
	          menu: false,
	          wmode: "opaque",
	          allowScriptAccess: "always"
	        };
	        // currently using the masthead flash 
	        swfobject.embedSWF("volvo_module.swf", "boatModel", "960", "631", "8","expressInstall.swf", flashvars, params, attributes);
            /*
            */
        }
		
		/* Glossary section selection */
		$("#glos0").addClass("openGlossary");
		$(".glossaryLinks LI A").slice(0,1).addClass("open");
		$("UL.glossaryLinks LI A").click(function(e){
			if(!$(this).hasClass("open")){
				var glossaryAnchor = $(this).attr("href");
				$(".openGlossary").hide();
				$(".glossarySection").removeClass("openGlossary");
				$(".glossaryLinks LI A").removeClass("open");
				$(this).addClass("open");
				$(glossaryAnchor).addClass("openGlossary").show();
			} else{
		//		alert('oops');
			}
			e.preventDefault();				  
		});
		
	   //sifr config
	   if(typeof sIFR == "function"){
		   	//documentation @ http://www.mikeindustries.com/blog/sifr/
			//http://designintellection.com/2008/this-is-how-you-get-sifr-to-work/
			/*
			sIFR takes the following arguments (in this order): sSelector, sFlashSrc, sColor, sLinkColor, sHoverColor, sBgColor, nPaddingTop, nPaddingRight, nPaddingBottom, nPaddingLeft, sFlashVars, sCase, sWmode
			*/ 

			switch (VorSettings.lang)
			{
				case 'en':
			        sIFR.replaceElement("h1", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#072343", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.sifred", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#072343", sWmode: "transparent"}));
					sIFR.replaceElement("#header LABEL.sifred", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sWmode: "transparent"}));
					sIFR.replaceElement("#sidebar h2.moduletitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.moduletitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.lcSubject", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#072444", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#contentwide h2.wideTitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#contentwide h2.moduletitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement(".legnumber p.single", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=17", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement(".legnumber p.double", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=7", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("P.num", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=14", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("P.num2", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=7", sCase: "upper", sWmode: "transparent"}));
					break;
				case 'es':
			        sIFR.replaceElement("h1", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#072343", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.sifred", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#072343", sWmode: "transparent"}));
					sIFR.replaceElement("#header LABEL.sifred", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sWmode: "transparent"}));
					sIFR.replaceElement("#sidebar h2.moduletitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.moduletitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.lcSubject", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#072444", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#contentwide h2.wideTitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#contentwide h2.moduletitle", named({sFlashSrc: "/flash/2008/helvNeueLTPro97BlkCn.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement(".legnumber p.single", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=17", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement(".legnumber p.double", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=7", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("P.num", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=14", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("P.num2", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=7", sCase: "upper", sWmode: "transparent"}));
					break;
				case 'ru':
			        sIFR.replaceElement("h1", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#072343", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.sifred", named({sFlashSrc: "/flash/2008/HelveticatNeueMac65.swf", sColor: "#072343", sWmode: "transparent"}));
					sIFR.replaceElement("#header LABEL.sifred", named({sFlashSrc: "/flash/2008/HelveticatNeueMac65.swf", sColor: "#ffffff", sWmode: "transparent"}));
					sIFR.replaceElement("#sidebar h2.moduletitle", named({sFlashSrc: "/flash/2008/HelveticatNeueMac65.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.moduletitle", named({sFlashSrc: "/flash/2008/HelveticatNeueMac65.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#content h2.lcSubject", named({sFlashSrc: "/flash/2008/HelveticatNeueMac65.swf", sColor: "#072444", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#contentwide h2.wideTitle", named({sFlashSrc: "/flash/2008/HelveticatNeueMac65.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement("#contentwide h2.moduletitle", named({sFlashSrc: "/flash/2008/HelveticatNeueMac65.swf", sColor: "#ffffff", sFlashVars: "offsetTop=2", nPaddingRight: "0px", nPaddingLeft: "0px", sWmode: "transparent"}));
					sIFR.replaceElement(".legnumber p.single", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=17", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement(".legnumber p.double", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=7", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("P.num", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=14", sCase: "upper", sWmode: "transparent"}));
					sIFR.replaceElement("P.num2", named({sFlashSrc: "/flash/2008/disintegration.swf", sColor: "#ffffff", sFlashVars: "offsetLeft=7", sCase: "upper", sWmode: "transparent"}));
					break;
				case 'cn':
			        $("html").removeClass("sIFR-hasFlash");
			        $("h1").css("font-size","3.6em");
					break;
		   	}
		};
		
		//pngfix
        $(document).pngFix();
		
		//jscrollpane custom scrollbar for homepage modules - (any element with the class 'no-scroll' will be excluded)
		$(function()
		{		//set module heights
		        $('.custommodules .modulecontent.padded').css('height','197px');
		        $('.custommodules .modulecontent.unpadded').css('height','197px');
		        $('.custommodules .unpadded.no-scroll').css('height','207px');
		        //$('#content DIV.module DIV.scroll').css('overflow','auto'); 
		       // $('.custommodules div.module div.scroll').css('width','300px');
		        //call jscroll
				$('#content DIV.module DIV.scroll').jScrollPane();
				//next line needed to reset container widths in ie6
				$('DIV.module DIV.jScrollPaneContainer').css('width','313px');
				$('.latestimages').css('overflow','hidden');
		});
		
		//jscrollpane
		$(function()
		{			
				$('DIV.headpod DIV.linklist').jScrollPane();
		});
		//meet volvo slideshow
		$('.slideShow1').cycle({ 
			fx:      'scrollRight', 
			speed:    700, 
			timeout:  7000,
			pause: 1
		});
		/*
			Slideshow Slide transition options:
		    *  blindX
			* blindY
			* blindZ
			* cover
			* curtainX
			* curtainY
			* fade
			* fadeZoom
			* growX
			* growY
			* scrollUp
			* scrollDown
			* scrollLeft
			* scrollRight
			* scrollHorz
			* scrollVert
			* shuffle
			* slideX
			* slideY
			* toss
			* turnUp
			* turnDown
			* turnLeft
			* turnRight
			* uncover
			* wipe
			* zoom

		*/
		//race organiser show/hide
		if ($('.raceorganisers').size() > 0){
			$('.profilelist H2').hide();
			for(i=1;i<$('.raceorganisers UL LI').length+1;i++){
				$(".profilelist"+i).hide();
			}
		$('.raceorganisers UL LI A').click(function () {	
				orgClick(this);
				return false;
			});
		}		
		
		if ($('DIV#vista DIV#canvas DIV#content DIV.fullwidth DIV.lcForm INPUT.chatdatepicker').size() > 0)	
		{
	        if(VorSettings.lang=="en")
            {
                //datepicker eng
                $("DIV#vista DIV#canvas DIV#content DIV.fullwidth DIV.lcForm INPUT.chatdatepicker").datepicker($.extend({}, 
                $.datepicker.regional[""], {  
	                dateFormat: "dd/mm/yy",
	                duration: "",
	                changeMonth: false, 
	                changeYear: false, 
	                showStatus: true,
	                showOn: "both",
	                buttonImage: "/images/2008/icon/calendar.gif",
	                buttonImageOnly: true 
                }));
        		        
            }
            if(VorSettings.lang=="ru")
            {
                //datepicker russian
                $("DIV#vista DIV#canvas DIV#content DIV.fullwidth DIV.lcForm INPUT.chatdatepicker").datepicker($.extend({}, 
                $.datepicker.regional["ru"], { 
	                dateFormat: "dd/mm/yy",
	                changeMonth: false, 
	                changeYear: false, 
	                showStatus: true, 
	                showOn: "both", 
	                buttonImage: "/images/2008/icon/calendar.gif", 
	                buttonImageOnly: true 
                })); 
            }
            if(VorSettings.lang=="es")
            {
                //datepicker spanish
                $("DIV#vista DIV#canvas DIV#content DIV.fullwidth DIV.lcForm INPUT.chatdatepicker").datepicker($.extend({}, 
                $.datepicker.regional["es"], { 
	                dateFormat: "dd/mm/yy",
	                changeMonth: false, 
	                changeYear: false, 
	                showStatus: true, 
	                showOn: "both", 
	                buttonImage: "/images/2008/icon/calendar.gif", 
	                buttonImageOnly: true 
                })); 
            }
            if(VorSettings.lang=="cn")
            {
                //datepicker chinese
                $("DIV#vista DIV#canvas DIV#content DIV.fullwidth DIV.lcForm INPUT.chatdatepicker").datepicker($.extend({}, 
                $.datepicker.regional["zh-CN"], { 
                    dateFormat: "dd/mm/yy",
                    changeMonth: false, 
                    changeYear: false, 
                    showStatus: true, 
                    showOn: "both", 
                    buttonImage: "/images/2008/icon/calendar.gif", 
                    buttonImageOnly: true 
                }));
            }
		}
		
		//racedata inrace
		if ($('DIV#content DIV.datacentretabs DIV.racedata').size() > 0){			
		    $("DIV#content DIV.datacentretabs SPAN.genericButton").show();
			$("DIV#content DIV.datacentretabs DIV.racedata A.editbut").show();
			$("DIV#content DIV.datacentretabs DIV.racedata A.helpbut").show();
			$("DIV#content DIV.datacentretabs DIV.racedata A.collapsebut").show();
		    $('DIV#content DIV.datacentretabs DIV.racedata A.collapsebut').click(function () {	
			      $(this).next().slideToggle('slow');			  
			      if($(this).hasClass('plus')){
				      $(this).removeClass('plus').addClass('minus');				  
				      $(this).siblings(".editbut").show();
				      $(this).siblings(".helpbut").show();
				      $(this).find("img").slice(0,1).attr({ 
					      src: "/images/2008/btn/collapse.gif",
					      title: "Collapse",
					      alt: "Collapse"
					    });
			      }else{
				      $(this).removeClass('minus').addClass('plus');
				      $(this).siblings(".editbut").hide();
				      $(this).siblings(".helpbut").hide();
				      $(this).find("img").slice(0,1).attr({ 
					      src: "/images/2008/btn/expand.gif",
					      title: "Expand",
					      alt: "Expand"
					    });
			      }
			      return false;
			    });
			    $('DIV#content DIV.datacentretabs DIV.racedata A.editbut').click(function () {
					    $(this).siblings().find(".edit").slice(0,1).toggle();
					    return false;
			    });
			    $('DIV#content DIV.datacentretabs DIV.racedata DIV.edit span A').click(function () {
					    $(this).parents().find(".edit").slice(0,1).hide();	
					    //return false;
			    });
			   $('DIV#content DIV.datacentretabs DIV.racedata DIV.edit A.cancel').click(function () {
					    $(this).parents().find(".edit").slice(0,1).hide();	
					    return false;
			    }); 
			    $('DIV#content DIV.datacentretabs DIV.racedata A.helpbut').click(function () {
					    $(this).siblings().find(".help").slice(0,1).toggle();
					    return false;
			    });
			    $('DIV#content DIV.datacentretabs DIV.racedata DIV.help A').click(function () {
					    $(this).parents().find(".help").slice(0,1).hide();	
					    return false;
			    });	
			   
			   var fakeCustomRange = function customRange(input) {
					return {minDate: new Date(2008,9,04), maxDate:  "-0d"};
				};
			   			   			   
                $("UL.datagraphcheckboxes LI SPAN input:checkbox").limit(7);
			   			  			   			   			   			   
			    if(VorSettings.lang=="en"){
			        //datepicker eng
			        $("DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.startDate,DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.endDate").datepicker($.extend({}, 
			        $.datepicker.regional[""], {  
				        dateFormat: "dd/mm/yy",
				        duration: "",
				        changeMonth: false, 
				        changeYear: false, 
				        showStatus: true,
				        beforeShow: (typeof(customRange) == 'function' ? customRange : fakeCustomRange),
				        showOn: "both",
				        buttonImage: "/images/2008/icon/calendar.gif",
				        buttonImageOnly: true 
			        }));
			    }
			    if(VorSettings.lang=="ru"){
			        //datepicker russian
			        $("DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.startDate,DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.endDate").datepicker($.extend({}, 
			        $.datepicker.regional["ru"], { 
				        dateFormat: "dd/mm/yy",
				        changeMonth: false, 
				        changeYear: false, 
				        showStatus: true, 
				        showOn: "both", 
				        buttonImage: "/images/2008/icon/calendar.gif", 
				        buttonImageOnly: true 
			        })); 
			    }
			    if(VorSettings.lang=="es"){
			        //datepicker spanish
			        $("DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.startDate,DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.endDate").datepicker($.extend({}, 
			        $.datepicker.regional["es"], { 
				        dateFormat: "dd/mm/yy",
				        changeMonth: false, 
				        changeYear: false, 
				        showStatus: true, 
				        showOn: "both", 
				        buttonImage: "/images/2008/icon/calendar.gif", 
				        buttonImageOnly: true 
			        })); 
			    }
			    if(VorSettings.lang=="cn"){
			        //datepicker chinese
			        $("DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.startDate,DIV#content DIV.datacentretabs DIV.tab2 DIV.racedata DIV.datagraphselection DIV.timeinterval INPUT.endDate").datepicker($.extend({}, 
			        $.datepicker.regional["zh-CN"], { 
				        dateFormat: "dd/mm/yy",
				        changeMonth: false, 
				        changeYear: false, 
				        showStatus: true, 
				        showOn: "both", 
				        buttonImage: "/images/2008/icon/calendar.gif", 
				        buttonImageOnly: true 
			        }));
			    }
			    $("DIV#content DIV.datacentretabs DIV.rdcquestions DIV").hide();
				$("DIV#content DIV.datacentretabs DIV.rdcquestions H4").click(function() {
					$(this).next().toggle();
					if($(this).find("span").hasClass('plus')){
					  $(this).find("span").removeClass('plus').addClass('minus');
					  $(this).find("span").find("img").slice(0,1).attr({ 
					  src: "/images/2008/btn/collapse_sml.gif",
					  title: "Collapse",
					  alt: "Collapse"
					});
				  }else{
					  $(this).find("span").removeClass('minus').addClass('plus');
					  $(this).find("span").find("img").slice(0,1).attr({ 
					  src: "/images/2008/btn/expand_sml.gif",
					  title: "Expand",
					  alt: "Expand"
					});		  
				  }	
				});
				$("DIV#content DIV.datacentretabs DIV.rdcquestions H4").mouseover(function() {
					$(this).css("cursor","pointer");
				});
				$("DIV#content DIV.datacentretabs DIV.rdcquestions H4").mouseout(function() {
					$(this).css("cursor","default");		   
				});
			   }
//end doc ready function	
            
            resetColHeights();
	
    });

function PrepareRDCPage()
{
    $(window).unload( function () 
        {                                                
            var showdata = "";            
	        var timeToKeep = 60000000000;
	        var expires = new Date();
	        var cookieName = "rdcprefscookie";
	        expires.setTime(expires.getTime() + timeToKeep);	                	        
	                	
	        for(a=0; a<$("DIV#content DIV.datacentretabs DIV.racedata DIV.edit").length; a++)
	        {		    
		        for(i=0; i<$("DIV#content DIV.datacentretabs DIV.racedata DIV.edit:eq("+ a +") INPUT").length; i++)
		        {
			        if($("DIV#content DIV.datacentretabs DIV.racedata DIV.edit:eq(" + a + ") INPUT:eq(" + [i] + ")").is(":checked"))
			        {
			            var variableId = $("DIV#content DIV.datacentretabs DIV.racedata DIV.edit:eq(" + a + ") SPAN:eq(" + [i] + ")").attr("variableid");			        			            
			        
				        showdata = showdata + variableId + ",";							
			        }	
		        }	    		    			        
	        }	
	        
	        showdata = showdata.substring(0,(showdata.length-1));
        	
	        //Write cookie
	        $.cookie(cookieName, showdata, { path: '/', expires: expires });
        } 
    );
}

function ConvertDegrees(value)
{
	var numberValue = Number(value.replace(",", ""))
	if (numberValue < 0)
		numberValue = (360 + numberValue);
	
	return numberValue;
}

function OpenEmailAlertsPopup(url)
{
	var win = Vor.HtmlUtils.openWindow(url, {name: 'emailalerts', width : 780, height : 450, scrollbars : 'yes', resizable : 'yes', toolbar : 'no', menubar :' no', location : 'no'});
	
	win.focus();
	
	
	return false;
}