// JavaScript Document
/*
# class login
# validated login form
*/
GI.AjaxBlockUpdate = {
	
	/*
	# int pid
	# product ID
	*/
	intProductId : 0,
	
	/*
	# string hoverClassName
	# class name to apply when tab is in hover state
	*/
	hoverClassName : 'homeHeroPromoTab hoverState',
	
	/*
	# string stdClassName
	# class name to apply when tab is in normal state
	*/
	stdClassName : '',
	
	/*
	# string selectedClassName
	# class name to apply when tab is in selected state
	*/
	selectedClassName : 'productDetailTabbedMenuSelect',
	
	/*
	# string tabContainer
	# 
	*/
	tabContainer : 'subTabContainer',
	
	/*
	# string blockContainer
	# 
	*/
	blockContainer : 'productDetailTabbedContentBlock',
	
	/*
	# array backgrounds
	# contains file name for each image
	*/
	sections : ['taba','tabb','tabc'],
	
	/*
	# bool currentIndex
	# int current array index
	*/
	currentIndex : null,
	
	/*
	# method bool apply()
	# apply index on user request
	*/
	apply : function(state,index){
		
		if(state==null)return false;
		if(index==null)return false;
		
		var domTarget = $(this.sections[index]);
		
		if(index==this.currentIndex)return false;
		
		switch(state){
		case 1:
		  /*
		  # apply the hover state
		  */
		  domTarget.className = this.hoverClassName;
		  break;  
		  
		case 2:
			
		  /*
		  # first clear the selected tag from a's
		  */
		  var tabLinks = $(this.tabContainer).getElementsByTagName('a');
		  for(var a=0;a<tabLinks.length;a++)tabLinks[a].className='';
		  
		  /*
		  # apply the selected state
		  */
		  domTarget.className += ' '+this.selectedClassName;
		  
		  /*
		  # now call the content update
	 	  */
		  this.setLoading();
		  this.update(this.intProductId, index);
		  
		  /*
		  # finaly set the currentIndex flag
		  */
		  this.currentIndex = index;
		  
		  break;
		  
		default:
		  /*
		  # apply the standard state
		  */
		  domTarget.className = this.stdClassName;
		}
		
		return true;
		
	},
	
	/*
	#
	*/
	setLoading : function(){
	  $(this.blockContainer).innerHTML = '<img src="/templates/wrapper/default/images/IMG-loading.gif" alt="Loading" width="32" height="32" />';
	  $(this.blockContainer).align = 'center';
	},
	
	/*
	# method bool send(int pid, array index)
	#
	*/
	update : function(intProductId,index){
		new Ajax.Request('/product/ajax-product-detail-update/'+intProductId+'/'+index,{
			onSuccess: function(transport) {
				$('productDetailTabbedContentBlock').innerHTML = transport.responseText;
			},
			onFailure: function(){
				alert('Product content could not be updated');
			}
		});
	}
}