$(document).ready(function() { 


if($.browser.mozilla){
	var Browserversion = $.browser.version;
	var Varray = Browserversion.split('.');
	var importantBit = Varray[Varray.length-2];
	//alert(Browserversion);
	//$("#nav li a").css({"font-family": "helvetica, sans-serif", "font-size": "18px"});

	if (importantBit < 2){
		$("#nav li a").css({"font-family": "helvetica, sans-serif", "font-size": "18px"});
				

	 }
}



/* Accordian for newslist */
$(".framegallery li:nth-child(6n)").css({"margin-right":"0"});

    $('.newsblock .content').hide();
    $('.newsblock').css({"cursor":"pointer"});
    
    $('.newsblock .content').each(function(){
    	var firstp = $(this).children("p:first").text();
    	var subS = firstp.substring(0,120);
    	var place = $("<p/>").addClass("summary").text(subS +" (More...)");
    	$(this).before(place);

    });


$(function(){
$('.lightboxGallery').each(function(){
$('.lightbox', this).lightBox();
});
});
$("#bottomContact").andyModal({
overlay:"#fff",
close:"X",
width:"300",
opacity:0.2,
fadetimeIn:200,
fadetimeOut:200,
topHeading:"h2",
maxheight:"50%",
defaulttitle:"Message"
});

 
     $(".newsblock .content").hide();
    $('.newsblock').click(function () {
               
               var parent = $(this);
               var parentclass = $(parent).attr("Class");
               var item = $(parent).children(".content");
               
               if ($(parent).is(".open")){
               $(".newsblock").removeClass("open");
                   $(item).slideUp();
                   $(".summary").show();
               }
               else{
               $(".newsblock").removeClass("open");
               $(parent).addClass("open");
                   $('.newsblock .content').slideUp();
                   $(".open .summary").fadeOut(200);

               $(item).slideDown(250);
               
               }

    });


    

$(".frames").Cslider({
			speed: 200,//speed of the slide
			height: 225,// minimum height
			fadeSpeed: 100, //fade in/out speed
			textbox: ".content", // nested holder for the text
			moreText: "more...",
			lessText: "less...",
			TruncateLength: 225, // how many characters you want it to count before looking for the next splitpoint
			splitpoint: '<h4>'// Tag character or string you want to split before.
			});
			
			
			
			
			$(document).pngFix();
			
			$(".newsgallery a").lightBox();
			
			$(".ridergallery a").lightBox();

    







$("tr:odd").addClass("odd");

$(".rider").click(function(){
	window.location=$(this).find("a").attr("href");return false; 
});
function MakeImage150 (){
			var width = 150;
			var height = 150;
			var thisheight = $(this).height();
			var thiswidth = $(this).width();
			var offset = (thisheight-150)/2;
			var margin = "-" + offset + "px";
			
			
			if (thisheight > thiswidth){ // if image is portrait
	
						//$(this).css({"width": width});//set the width to 
						$(this).css({"margin-top": margin, "width": width});

			}
			if(thisheight < thiswidth){ // if image is landscape
						$(this).css({"height": height});//set the width to 
						$(this).attr("height", 120);
						$(this).css({"margin-top": margin, "height": height});
						var ratio = height/thisheight;
						$(this).attr("height", height);
						var newwidth = thiswidth*ratio;
						var rwidth = Math.round(newwidth);
						$(this).attr("width", rwidth);
						
			}

}

/*
function equaliseCols(){
var Height = $(this).height();

if($(this).children("img")){

 Height = Height+150;
 
}
		if(Height > largestHeight){
			largestHeight = Height;
			//alert("case 1: "+ largestHeight);
			}else
			{
			Height = largestHeight;
			//alert("case 2: "+ largestHeight);

			}

}
*/


		
		var wrapper = $("<div/>").addClass("wrapper");

		$("#rightcol img").wrap(wrapper).load(MakeImage150);	
		$(".oneWide img").wrap(wrapper).load(MakeImage150);	



$("ul#footernav li a:last").css({"border-right":"0 none"});

		var largestHeight = 0;

		$("#main .twoWide").each(function(){
		var Height = $(this).height();
		if(Height > largestHeight){
		largestHeight = Height;
		}else{
		Height = largestHeight;
		}
		});
		$("#main .twoWide").height	(largestHeight);
		
		
		
		
		$("#main .oneWide").each(function(){
		var Height = $(this).height();
if($(this).children("img")){

 Height = Height+150;
 
}
		if(Height > largestHeight){
			largestHeight = Height;
			//alert("case 1: "+ largestHeight);
			}else
			{
			Height = largestHeight;
			//alert("case 2: "+ largestHeight);
			}

});
		
		$("#main .oneWide").css({"height":largestHeight});
		//alert("largestHeight: "+largestHeight)
		



var dheight = $(document).height();
var dwidth = $(document).width();
//alert(dheight);
var pop = $("<div id='overlay'/>");
$("#overlay").live("click", removepop);
$("#close").live("click", removepop);

function removepop(){
$(pop).animate({"opacity": 0}, 800, function(){
$(pop).remove();

});
}

$('a#contactmenu').click(function(){
var dheight = $(document).height();
var dwidth = $(document).width();

$("#bottom").before(pop);
$("#formbox").css({
	"position":"relative",
	"z-index" : 5
	});
$("#overlay").css({
	"height":dheight,
	"width": dwidth
	});
$("#overlay").animate({"opacity": 0.7}, 2000);

});

$("span.A").css({"position":"absolute"});
$("span.racebred").css(
{
	"display":"block",
	"position": "absolute",
	"right": 0

});

});
