function FG_fixfloats() {
  lastParent = 0;
  galleryitems = jQuery(".productItem");
  galleryitems.each(function(i){
    if(this.parentNode != lastParent) {
      lastTop = 0;
      rowHeight = 0;
      rowStart = i;
      lastParent = this.parentNode;
    }
    this.style.height = "auto";
    this.style.clear="none";
    if(this.offsetTop != lastTop) {
      this.style.clear="left";
      rowHeight = this.offsetTop - lastTop - (this.style.marginTop + this.style.marginBottom);
      for(j=rowStart;j<i;j++) {
        galleryitems.get(j).style.height = rowHeight+"px";
      }
      lastTop = this.offsetTop;
      rowStart = i;
    } 
  });
}

function alignPopups()
{
	var popups = jQuery( '.productLargeImage' );
	
	popups.each( function() {
		
		var offset = jQuery(this).offset();
		
		// keep it to the left or right
		if( ( offset.left + jQuery(this).width() ) > ( jQuery(window).width() - 20 ) )
		{
			jQuery(this).css( {left: '-420px'} );
		}
	} );
}

function showPopup( divId )
{
	var popup = jQuery( '#' + divId );
	
	popup.parent().css( {'zIndex': 1000} );
	
	// first keep our popup from going above or below the browser window
	var offset = popup.offset();
	var scrollTop = jQuery(window).scrollTop();
	
	if( ( offset.top + 410 ) > ( scrollTop + jQuery(window).height() ) )
	{
		var newTop = ( popup.css( 'top' ).replace( 'px', '' ) - ( ( offset.top + 410 ) - ( scrollTop + jQuery(window).height() ) + 20 ) );
		popup.css( {top: newTop + 'px' } );
	}
	
	if( offset.top < ( 20 + scrollTop ) )
	{
		var newTop = ( popup.css( 'top' ).replace( 'px', '' ) - ( offset.top - scrollTop ) ) + 20;
		popup.css( {top: newTop + 'px' } );
	}
	
	// now keep it to the left or right
	if( ( offset.left + popup.width() ) > ( jQuery(window).width() - 20 ) )
	{
		popup.css( {left: '-420px'} );
	}
	
	// now show the popup
	popup.css( {visibility: 'visible'} );
}

function hidePopup( divId )
{
	jQuery('#' + divId).css(  {visibility: 'hidden'}  );
	jQuery( '#' + divId).parent().css( {'zIndex': 0} );
	// and reset the top value to the original
	jQuery('#' + divId).css( {top: '-200px'} );
}

function showColor( id, image )
{
	jQuery('#productItemImageLarge' + id).attr( 'src', 'images/popuploader.gif' );
	showPopup( 'productLargeImage' + id );
	jQuery('#productItemImageLarge' + id).attr( 'src', 'images/products/' + image + 'l.png' );
}

function hideColor( id, imageId )
{
	hidePopup( 'productLargeImage' + id );
	jQuery('#productItemImageLarge' + id).attr( 'src', 'images/popuploader.gif' );
}

