google.load("search", "1");

function OnLoad() {


	// Attach branding
	google.search.Search.getBranding(document.getElementById("branding"));
		
	// Create a search control
	var searchControl = new google.search.SearchControl();
		
	//open in expand mode
	options = new google.search.SearcherOptions();
	options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
	options.setRoot(document.getElementById("returnResults"));
		
	
	//set up websearch Limit to GNCC Racing
	var siteSearch = new google.search.WebSearch();
	siteSearch.setUserDefinedLabel("GNCCRacing.com");
	siteSearch.setUserDefinedClassSuffix("siteSearch");
	siteSearch.setSiteRestriction("gnccracing.com");
	searchControl.addSearcher(siteSearch, options);
	
	
	searchControl.setSearchStartingCallback(this, OnLoad.prototype.OnSearchStarting);

	// Tell the searcher to draw itself and tell it where to attach
	searchControl.draw(document.getElementById("searchcontrol"));
	
	$("div.gsc-clear-button").click(
	  function () {
	  	 $("#branding").css({display:"none"});
		
	  }
	 );


}
OnLoad.prototype.OnSearchStarting = function(sc, searcher, query) {
  $("#branding").css({display:"inline"});
}
google.setOnLoadCallback(OnLoad);
	
//Animate main menu (also fixes IE 6
function mainmenu(){

$(" #nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}
 
var t = ''; 
$rotate = true;
 
$(document).ready(function() {
	$('.articleBody p[style]').each(function() {
		if ($(this + ' + .fullImage') && ($(this).attr('style') == 'text-align: center;') || ($(this).attr('style') == 'TEXT-ALIGN: center')) { 
			$(this).next().addClass('divCenter');
		}
	});					   
						   
	//Activate jQuery Menu Style
	mainmenu();
	//Activate PNG Fix
	if (jQuery.fn.pngFix) $(document).pngFix();
	//Activate FancyBox
	$(".articleImage a, .lightbox a, a.lightbox").fancybox({
		'hideOnContentClick': true,
		'overlayOpacity': 0,
		'overlayShow':	true,
		zoomSpeedIn:		250,
		zoomSpeedOut:		250,
		frameWidth: 1000,
		frameHeight: 800

	});
	
	new Image().src ='/images/icons/plus.png';

	t = setTimeout ( "rotateNormal()", 8000 );
	

	
});



$(".articleImage a").hover(
  function () {
	$(this).after('<div class="plus"><img src="/images/icons/plus.png" alt="enlarge" \/><\/div>');
	if (jQuery.fn.pngFix) $(document).pngFix();
  }, 
  function () {
	$('.plus').remove();

  }
);

//Rotator
$('#slides a').hide();
$('#slides a:first').show();
$disable = false;
$disable2 = true;

function rotator($next) {
	$disable = true;	
	$('#slides a:visible').fadeOut(2000,
		function() {
			t = setTimeout ( "rotateNormal()", 8000 );
			$disable = false;
		});
	
	$next.fadeIn(2000);
	
	$('.sidebar li.current').removeClass('current');
	
	$count = $next.prevAll('a').size();
	$sidebar = $('.sidebar li:eq('+$count+')');
	$sidebar.addClass('current');  
		 
}

function rotateNormal() {
	
	if($('#slides a:visible').next().length > 0) {
		$next = $('#slides a:visible').next();
	
	}else{
		$next = $('#slides a:first');
	}
	
	rotator($next);
}

$('.sidebar a').click(function(){
		if($disable == false) {
			clearTimeout (t);
			
			$count = $(this).parent().prevAll('li').size();
			$next = $('#slides a:eq('+$count+')');
			
			rotator($next);
		}
		return false;
	});

$('.sidebar a').hover(function() {
		$current = $(this).parent('li');
		$current.animate({ marginLeft: "0" }, 500, function() {
				$current.children('img').slideDown();														   
			});	
   },
   
   function() {
	   	$current = $(this).parent('li')
	   	$current.children('img').slideUp(function() {
	   			$(this).parent('li').animate({ marginLeft: "-301px" }, 500);
			});
   });

$('#slides a').hover(
	function(){
		if($disable == false) {
			clearTimeout(t);
			$disable2 = false;
		}
	},
	
	function(){
		if($disable2 == false) {
			t = setTimeout ( "rotateNormal()", 2000 );
			
			$disable2 = true;
		}
	});