var GalpageIndex=1;
var GalImgsPerPage=56;

$(document).ready(function(){	
	$('.contentleft').corner("10px");
	$('.contentright').corner("10px");;
	$('.sec265').corner("10px");
	$('.sec580').corner("10px");
	$('#tleader').corner("10px");
	$('.t_col').corner("10px");
	$('#thumbcontainer').corner("10px top br");
	
	$('.pagelist li a').corner("bottom 10px");
	$('.pgetoplist li a').corner("top 10px");
	
	$('#pumpblog').html("<p>Loading news...</p>");	
	
	$('.galhead_left').eq(0).children('img').hide().eq(0).show();
	$('.galhead_left').eq(1).children('img').hide().eq(0).show();
	$('.galhead_left').eq(2).children('img').hide().eq(0).show();
	
	$('#thumbcontainer a').lightBox();
	$('.t_col a').lightBox();
	
	$('#gsr_vid').flash(
        { src: 'http://www.youtube.com/v/a6fM6fXvDqE&hl=en&fs=1',
          width: 257,
          height: 155 },
        { version: 8 }
    );
	
	$('#dsvid').flash(
        { src: 'http://www.youtube.com/v/51o2GlE1Ez0&hl=en&fs=1',
          width: 257,
          height: 155 },
        { version: 8 }
    );
	
	$('#thvid').flash(
        { src: 'http://www.youtube.com/v/b8ELF31D1qM&hl=en&fs=1',
          width: 257,
          height: 155 },
        { version: 8 }
    );
	
	$('#static_vid').flash(
        { src: 'http://www.youtube.com/v/OuxAw1zH1pI&hl=en&fs=1',
          width: 257,
          height: 155 },
        { version: 8 }
    );
	
	
	$('#idsvid').flash(
        { src: 'http://www.youtube.com/v/Tqmw8rhrXrE&hl=en&fs=1&',
          width: 257,
          height: 155 },
        { version: 8 }
    );
	
	$('#pbvid').flash(
        { src: 'http://www.youtube.com/v/7_7kQ5Anzps&hl=en&fs=1',
          width: 257,
          height: 155 },
        { version: 8 }
    );
	
	$('#atbvid').flash(
        { src: 'http://www.youtube.com/v/cSoCAdvkSI4&hl=en&fs=1&',
          width: 257,
          height: 155 },
        { version: 8 }
    );
	
	$('#sk8parkrepaint').flash(
        { src: 'http://www.youtube.com/v/79U1kSgv4G0&hl=en&fs=1&',
          width: 580,
          height: 320 },
        { version: 8 }
    );
	
	$.post("scripts/php/loadnewsdls.php",{reinfo:"news"},function(data){
		$('#listnews').html(data).css("backgroundPosition","-200px center");
		$('.pgenewscontainer').corner("10px");
		
	});
	
	$.post("scripts/php/loadnewsdls.php",{reinfo:"dls"},function(data){
		$('#listdownloads').html(data).css("backgroundPosition","-200px center");
		
		//$('.contentleft').height($('.contentright').height());
		
		$('.pgenewscontainer2').corner("10px");
		
		$('a').click(function(){
			if($(this).attr('rel')=="nw")
			{
				window.open($(this).attr('href'));
				return false;
			}
		});
	});
	
	$.post("scripts/php/pumptrackblog.php",{postfunc: "return_blog"},function(data){
		$('#pumpblog').html(data);					  
	});
	
	$.post("scripts/php/returnwinning.php",{postfunc:"return_winningts"},function(data){
		$('#tleader').html(data);
		$('#tleader').corner("10px");
	});
	
	/*$.post("scripts/php/returnwinning.php",{postfunc:"return_winner"},function(data){
		$('.t_winner').html(data);
		$('.t_col').corner("10px");
	});*/
	
	
	$('#signupform').submit(function(){
		$('#returninfo').text("Processing...").fadeIn(300);
		inpemail=$('#txtbox').val();
		if(inpemail!="" && CheckEmail(inpemail))
		{
			$.post("scripts/php/subscribe.php",{emailadd: inpemail},function(data){
				AnimateNote($('#returninfo'),data);
				$('#txtbox').val("");
			});
		}
		else
		{
			AnimateNote($('#returninfo'),"Please enter a valid email address.");
			$('#txtbox').val("");
		}
		return false;								 
	});
	
	$('#contactform').submit(function(){
		$('#returncontact').text("Processing...").fadeIn(300);
		
		t1=$('.txtbox').eq(0).val();
		t2=$('.txtbox').eq(1).val();
		t3=$('.txtbox').eq(2).val();
		
		if(t1!="" && CheckEmail(t2))
		{
			$.post("scripts/php/contact.php",{f1: t1, f2: t2, f3: t3},function(data){
				AnimateNote($('#returncontact'),data);
				$('.txtbox').val("");
			});
		}
		else
		{
			AnimateNote($('#returncontact'),"Please ensure you have entered you name and email address.");	
		}
		return false;								  
	});
	
	$('.pagelist li a').click(function(){
		GalpageIndex=$('.pagelist li a').index(this)+1;
		
		GalTo=GalImgsPerPage*GalpageIndex;
		if(GalTo>GalMax){GalTo=GalMax;}
		GalFrom=GalTo-GalImgsPerPage+1;
		GalOutput="";
		for(i=GalFrom;i<=GalTo;i++)
		{
			GalOutput=GalOutput+"<a href=\"gallery/"+GalLocation+"/large/"+i+
			".jpg\"><img src=\"gallery/"+GalLocation+"/thumbs/"+i+".jpg\" alt=\"\" /></a>\n"
		}
		$('#thumbcontainer').html(GalOutput);
		$('#Galpgeno').text("Page "+GalpageIndex+"...");
		$('#thumbcontainer a').lightBox();
		GalOutput="";
		return false;
	});
	
	$(window).bind("load",function(){
		
		$('a').click(function(){
			if($(this).attr('rel')=="nw")
			{
				//window.open($(this).attr('href'));
				return false;
			}
		});
		
		$('.galhead_left').eq(0).c5crossfade();
		$('.galhead_left').eq(1).c5crossfade();
		$('.galhead_left').eq(2).c5crossfade();
		
		$('#exwdtshirtview').lightBox();
		
		$('.navigation li a').mouseover(function(){
			if(selectpage!=$('.navigation li a').index(this))
			{
				$(this).css("backgroundPosition","center bottom");										 
			}										 
		});
		
		$('.navigation li a').mouseout(function(){
			if(selectpage!=$('.navigation li a').index(this))
			{
				$(this).css("backgroundPosition","center top");												 
			}																	 
		});
		
		$('.navigation li a').eq(selectpage).css("backgroundPosition","center bottom");
		
		$.post("scripts/php/returntshirts.php",{postfunc:"return_ts"},function(data){
			
			$('.c5hslideviewwindow').css("backgroundPosition","-200px center");
			
			$('.c5hslideviewwindow').html(data);	
			$('.c5hslidercontentholder').css("left","-"+$('.c5hslideviewwindow').width()+"px").eq(0).css("left","0");
			$('.votebutton').click(function(){
				$('#tvoteresult').text("Processing...").show();
				Tselectindex=$(this).attr("rel");
				$.post("scripts/php/tvote.php",{selectindex: Tselectindex},function(data){
					$('#tvoteresult').text(data);
					$('#tvoteresult').animate({
						top:"0px"						  
					},3000,function(){
						$(this).fadeOut(300);	
					});
				});
				return false;
			});
		});
	});

});

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");

	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}
}

function AnimateNote(element, note)
{
	element.text(note).animate({
		top:"0px"	
	},3000,function(){
		$(this).fadeOut(300);	
	});
}