(function(){

/*
	Class: GridViewItem 
	The base class for a collection of navigation components 
*/
function GridViewItem()
{
	this.htmlObj = null;

	SBui.GridViewItem.superclass.constructor.call(this);
}

//GridViewItem extends ItemView.  
YAHOO.lang.extend( GridViewItem, window['SB']['ui']['ItemView']);

GridViewItem.prototype.toString = function() { return "[SB.ui.GridViewItem]"; }

//Group: Basic Methods 
/*
	Function: setConfig
	Establishes the basic setup for the GridViewItem.
	
	inConfig - A configuration array (key/value)

	Configuration Array Options:
	id - the id of the div to use as a template (default:none)
*/
GridViewItem.prototype.setConfig = function( inConfig )
{
	inConfig.id = "sb_ui_grid_item_2"; 
	inConfig.dd = "sb_box_grid_view_2"; 

	SBui.GridViewItem.superclass.setConfig.call(this, inConfig);

	var arr = YUIDom.getElementsByClassName( "sb_grid_item_image", "img", this.htmlObj );
	if( arr[0] )
	{
		var img = arr[0];
		var width_factor = 1.0;
		var height_factor = 1.0;
			
		if( inConfig.width > 200 )
		{
			width_factor = ( 200 / inConfig.width );	
		}
	
		if( (width_factor * inConfig.height) > 200 )
		{
			height_factor = ( 200 / (inConfig.height * width_factor));	
		}
	
		img.style.width = (height_factor * (width_factor * inConfig.width)) + "px";
		img.style.height = (height_factor * (width_factor * inConfig.height)) + "px";
		img.style.msInterpolationMode = "bicubic";
		img.style.verticalAlign = "middle";

		if( inConfig.url.match(/http/) )
			if( this.item_obj.thumb )
			{
				img.src = this.item_obj.thumb;
			}
			else
			{
				img.src = inConfig.url;
			}
		else
			img.src = "/item/image?id="+this.item_obj.id;

		YUIEvent.addListener( img, "click", this.showLightBox, this, true );
	}


	var arr2 = YUIDom.getElementsByClassName( "itemdetail_gridview_id", "div", this.htmlObj );
	if(arr2[0]) {
		YUIEvent.addListener( arr2[0], "click", this.showLightBox, this, true );
	}
	
	var arr3 = YUIDom.getElementsByClassName( "itemdetail_gridview_vs", "div", this.htmlObj );
	if(arr3[0]) {
		YUIEvent.addListener( arr3[0], "click", this.viewSource, this, true );

	}
	
	if( !inConfig.item_obj.link )
	{
		YUIDom.getElementsByClassName( "itemdetail_gridview_vs", "div", this.htmlObj, function(el) { el.style.display="none";  } ); 
	}

	arr = YUIDom.getElementsByClassName( inConfig.dd, "div", this.htmlObj );
	{
		YUIEvent.addListener( arr[0], "mouseout", this.toggleHUD, this, true );
		YUIEvent.addListener( arr[0], "mouseover", this.toggleHUD, this, true );
	}

	this.hud_showing = false;
};

GridViewItem.prototype.toggleHUD = function( inEvent )
{
	var targ = YUIEvent.getTarget(inEvent);
	if( this.hud_showing )
	{
		YUIDom.getElementsByClassName('sb_box_grid_view_body_footer_2', 'div', this.htmlObj )[0].style.display='none';
		var el = YUIDom.getAncestorByClassName( targ, "sb_box_grid_view_2" );
		if( el ) el.style.borderColor='#ccc';
		this.hud_showing = false;
	}
	else
	{
		YUIDom.getElementsByClassName('sb_box_grid_view_body_footer_2', 'div', this.htmlObj )[0].style.display='block'; 
		var el = YUIDom.getAncestorByClassName( targ, "sb_box_grid_view_2" );
		if( el ) el.style.borderColor='#FFA026';
		this.hud_showing = true;
	}
};

GridViewItem.prototype.dragStart = function()
{
	YUIDom.getElementsByClassName('sb_box_grid_view_body_footer_2', 'div', this.htmlObj )[0].style.display='none';
};

GridViewItem.prototype.viewSource = function(e)
{
	YUIEvent.stopPropagation(e);
	window.open(this.p_config.link, "theSource" );
}

window['SB']['ui']['GridViewItem'] = GridViewItem;

})();
