//Document ready function
$(document).ready(function() {
 
	 $("#grass_type_1").click(function () {
		$('#picker_content').fadeOut('fast', function() {
				$('#picker_content').load('sections/index_picker.php?product_id=3');
		});
	});
	
	$("#grass_type_2").click(function () {
		$('#picker_content').fadeOut('fast', function() {
				$('#picker_content').load('sections/index_picker.php?product_id=2');
		});
	});
	
	$("#grass_type_3").click(function () {
		$('#picker_content').fadeOut('fast', function() {
				$('#picker_content').load('sections/index_picker.php?product_id=1');
		});
	});
	
	$("#grass_type_4").click(function () {
		$('#picker_content').fadeOut('fast', function() {
				$('#picker_content').load('sections/index_picker.php?product_id=14');
		});
	});
	
	$("#grass_type_5").click(function () {
		$('#picker_content').fadeOut('fast', function() {
				$('#picker_content').load('sections/index_picker.php?product_id=15');
		});
	});
	
	$('#picker_content').ajaxSuccess(function() {
	  $('#picker_content').fadeIn('fast');
	  });


$('#grass_type_3').CreateBubblePopup(); 
$('#grass_type_3').mouseover(function(){
var grassType = $(this);
//show the bubble popup with new options
grassType.ShowBubblePopup({
		position : 'bottom',
		align	 : 'center',
		tail	 : {align: 'center'},
		innerHtml: '<div style="padding: 3px 6px 3px 6px; text-align: left;"><p style="font-size: 16px;">Shortcrop</p><p style="color: #F00; font-size: 16px;"> Out of Stock </p><p style="font-size: 13px;"> for pathways and borders, "just cut" look </p></div>',
		innerHtmlStyle: {
			   color:'#333333', 
			   'text-align':'center',
			 },
		themeName: 	'green',
		themePath: 	'javascript/jquerybubblepopup-theme'								 
	});
});


$('#grass_type_2').CreateBubblePopup(); 
$('#grass_type_2').mouseover(function(){
var grassType2 = $(this);
//show the bubble popup with new options
grassType2.ShowBubblePopup({
		position : 'bottom',
		align	 : 'center',
		tail	 : {align: 'center'},
		innerHtml: '<div style="padding: 3px 6px 3px 6px; text-align: left;"><p style="font-size: 16px;">Active</p><p style="font-size: 13px;"> hard wearing for sport and heavy footfall </p></div>',
		innerHtmlStyle: {
			   color:'#333333', 
			   'text-align':'center',
			 },
		themeName: 	'green',
		themePath: 	'javascript/jquerybubblepopup-theme'								 
	});
});


$('#grass_type_1').CreateBubblePopup(); 
$('#grass_type_1').mouseover(function(){
var grassType3 = $(this);
//show the bubble popup with new options
grassType3.ShowBubblePopup({
		position : 'bottom',
		align	 : 'center',
		tail	 : {align: 'center'},
		innerHtml: '<div style="padding: 3px 6px 3px 6px; text-align: left;"><p style="font-size: 16px;">Astro Tiles</p><p style="font-size: 13px;"> portable interlocking grass mats </p></div>',
		innerHtmlStyle: {
			   color:'#333333', 
			   'text-align':'center',
			 },
		themeName: 	'green',
		themePath: 	'javascript/jquerybubblepopup-theme'								 
	});
});
		

$('#grass_type_4').CreateBubblePopup(); 
$('#grass_type_4').mouseover(function(){
var grassType4 = $(this);
//show the bubble popup with new options
grassType4.ShowBubblePopup({
		position : 'bottom',
		align	 : 'center',
		tail	 : {align: 'center'},
		innerHtml: '<div style="padding: 3px 6px 3px 6px; text-align: left;"><p style="font-size: 16px;">Lush</p><p style="font-size: 13px;"> Landscape quality "realistic" looking grass </p></div>',
		innerHtmlStyle: {
			   color:'#333333', 
			   'text-align':'center',
			 },
		themeName: 	'green',
		themePath: 	'javascript/jquerybubblepopup-theme'								 
	});
});


$('#grass_type_5').CreateBubblePopup(); 
$('#grass_type_5').mouseover(function(){
var grassType5 = $(this);
//show the bubble popup with new options
grassType5.ShowBubblePopup({
		position : 'bottom',
		align	 : 'center',
		tail	 : {align: 'center'},
		innerHtml: '<div style="padding: 3px 6px 3px 6px; text-align: left;"><p style="font-size: 16px;">Astro Rolls</p><p style="font-size: 13px;"> bowling & putting green smooth finish </p></div>',
		innerHtmlStyle: {
			   color:'#333333', 
			   'text-align':'center',
			 },
		themeName: 	'green',
		themePath: 	'javascript/jquerybubblepopup-theme'								 
	});
});


});
	



function ResizeProducts(){
	/* Calculate Page Width */
	var pageWidth = document.body.clientWidth;
	var bannerWidth = 315;
	var linksWidth = 175;
	var miscWidth = 30;
	var tableWidth = pageWidth - bannerWidth - linksWidth - miscWidth;
	if (tableWidth < 460){ tableWidth = 460; }
	//----------------------------------------------------------------
	
	var product_wrapper_width = 150;
	var maxProducts = Math.floor(tableWidth / product_wrapper_width);
	
	document.getElementById("products1_wrap").setAttribute("width", tableWidth);
	document.getElementById("products2_wrap").setAttribute("width", tableWidth);
	
		HideProducts("newest", maxProducts, tableWidth);
	
}



 function HideProducts ( productType, maxCurrentProducts, tableWidth ){
	  var isIE=/*@cc_on!@*/false;//IE detector
	  var elStyle=isIE?'cssText':'style'; 	  
	  var maxInColumn = 10;
	  var productsShowing = Math.floor(tableWidth / 155);
	  if (productsShowing < 3){ productsShowing = 3; }
	  maxInColumn++;
	  
		
	  var i;
	  if (productsShowing <= 3 && tableWidth <= 460){ var productWidth = 138; } else {
	  var productWidth = (tableWidth / productsShowing) - 15; }
  			  
	  for (i = 1; i <= maxInColumn; i++){
			   			   
			  var productID_1 = "newest" + "_" + i;
			  var productID_2 = "education" + "_" + i;
			  
			  
			  productID = document.getElementById(productID_1);
			  productID2 = document.getElementById(productID_2);
			  
			 if (i <= productsShowing){
				 
					if (isIE){   
					if (productID){ productID.style.cssText = "display: inline; width: " + productWidth + "px"; }
					if (productID2){ productID2.style.cssText = "display: inline; width: " + productWidth + "px"; }
						} else {
					if (productID){ _setStyle(productID, "display: inline;  width: " + productWidth + "px"); }
					if (productID2){ _setStyle(productID2, "display: inline;  width: " + productWidth + "px"); }
					}
					
			  } else {
				  
				if (i != 3){
				    if (isIE){   
					    if (productID){ productID.style.cssText = "display: none;"; }
					    if (productID2){ productID2.style.cssText = "display: none;"; }
				     } else {
					     if (productID){ _setStyle(productID, 'display: none;'); }
					     if (productID2){ _setStyle(productID2, 'display: none;'); }
					 }
				 }
			  } 
			  
		  } // end of for loop
 }
 
 function ChangeProductWidth(productID, productID2, productWidth){
	 productID.style.cssText = "display: inline; width: " + productWidth + "px";
	 productID2.style.cssText = "display: inline; width: " + productWidth + "px";
 }
 
 
function ExpandText (eID, eTextSmall, eTextLarge, eType){
	var text_id = document.getElementById(eID);
	var readLessText =  '<a href="#" onClick="ExpandText(\'' + eID + '\', \'' + eTextSmall + '\', \'' + eTextLarge + '\', 2); return false"> (read less) </a>';
	if (eType == 1){
		text_id.innerHTML = eTextLarge;
	} else {
		text_id.innerHTML = eTextSmall + '<a href="#" onClick="ExpandText(\'' + eID + '\', \'' + eTextSmall + '\', \'' + eTextLarge + '\', 1);"> (read more) </a>';
	}
}



// rollover image functions
function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}

function EnlargeImage(mouseX, mouseY, imgName){
	
	var enlarge_box = document.getElementById("enlarge_image");
	var enlarged_image = 'enlarged_image';
	
	var mouseXFinal = mouseX + 5;
	var mouseYFinal = mouseY + 25;
	
	 if (isIE){   
			enlarge_box.style.cssText = 'display: inline; position: absolute; top: ' + mouseYFinal + 'px; left: ' + mouseXFinal + 'px;';
		} else {
			_setStyle(enlarge_box, 'display: inline; position: absolute; top: ' + mouseYFinal + 'px; left: ' + mouseXFinal + 'px;');
		}
	 document[enlarged_image].src= imgName.src;
}

function HideEnlargedImage(){
	var enlarge_box = document.getElementById("enlarge_image");
	  if (isIE){   
	  		enlarge_box.style.cssText = 'display: none; position: absolute; top: 0px; left: 0px;';
		} else {
			_setStyle(enlarge_box, 'display: none; position: absolute; top: 0px; left: 0px;');
		}
}

var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  
document.Show.MouseX.value = tempX;
document.Show.MouseY.value = tempY;
return true;
}


