/**
 * Apparel Site. This js offer functions for the apparel Template, specially
 * for the wList item with the template product.
 * version: 1.0
 * author: Ihsan B. Bikmaz 2008 (c) namics ag
 */

 
// global Variable to check id the product divs are already loaded
var blnProductDivLoaded = false;

function makeLIclickable()
{
	$('ul.linklist li a').each( function()
	{
		$(this).parent().click( this.onclick )
	});
}

/**
 * This function loads the Products asynchron
 * @param {object} me 		Pointer to the clicked object
 * @param {string} file		File to load dynamically
 */
function loadProducts( me, file )
{
	// Now we undeline the active Image text
	// therefore we must first remove underlines from all (passive) than add underline to the active
	$("p.active").removeClass().addClass("passive");
	$(me).children("p").removeClass().addClass("active");
	
	
	// Here I check if the product divs are loaded..
	// if so, i set the loader image into the div
	if ( blnProductDivLoaded )
	{
		$("div.elementPortlet").after( '<div id="temp"></div>' );
		$('#productcontentloader').html('<img src="/ISBD/img/ajax-loader.gif" />');
	}
	else
	{
		$('<div id="temp" class="text" style="margin-top:10px">Loading.. <img src="/ISBD/img/ajax-loader.gif" /></div>').appendTo( "#middle" );
	}

	
	// now we set up the request
	if ( !blnProductDivLoaded && typeof $('#productcontentloader').get(0) == "undefined" )
	{
		var strHtml = createBox( '' );
		$( strHtml ).appendTo( "#middle" );
		$("#productcontentloader").load( file+" #productcontent");
		$("#temp, #productcontent").remove();
		blnProductDivLoaded = true;
	}
	else
	{
		$("#productcontentloader").load( file+" #productcontent");
	}
	makeLIclickable();
}




/**
 * Creates a text box element
 * @param {string} html	The html with whicht the textbox is filled
 */
function createBox( html )
{
	var strHtml =  '<div class="text">'
				  +'  <div class="blueboxwrappertop">'
				  +'    <div class="blueboxwrapper">'
				  +'      <div class="blueboxwrapperbottom" style="display: block;">'
				  +'        <div style="display:inline; height:100%" id="productcontentloader">'+ html + '</div>'
				  +'        <br clear="all"/>'
				  +'      </div>'
				  +'    </div>'
				  +'  </div>'
				  +'</div>';
				  
	return strHtml;
}