var mostpopular_slideSpeed = 8; // Higher value = faster
var mostpopular_timer = 5;      // Lower value = faster
var objectIdToSlideDown = false;
var mostpopular_activeId = false;
var mostpopular_slideInProgress = false;


var prodcat_slideSpeed = 8; // Higher value = faster
var prodcat_timer = 5;      // Lower value = faster
var prodcat_activeId = false;
var prodcat_slideInProgress = false;



var brand_slideSpeed = 8; // Higher value = faster
var brand_timer = 5;      // Lower value = faster
var brand_activeId = false;
var brand_slideInProgress = false;

/***************** mostpopular_news_tabs **************************/
function showHideContent(e,inputId)
{
	if(mostpopular_slideInProgress)return;
	mostpopular_slideInProgress = true;
	if(!inputId)inputId = this.id;
		inputId = inputId + '';
		var numericId = inputId.replace(/[^0-9]/g,'');
		var answerDiv = document.getElementById('mostpopular_a' + numericId);
		//alert("answerDiv	:"+answerDiv);
		objectIdToSlideDown = false;

	if (answerDiv != null) 
	{
		if(!answerDiv.style.display || answerDiv.style.display=='none')
		{
			//alert("I M Here");
			if(mostpopular_activeId &&  mostpopular_activeId!=numericId)
			{
				objectIdToSlideDown = numericId;
				slideContent(mostpopular_activeId,(mostpopular_slideSpeed*-1));
			}else{
				answerDiv.style.display='block';
				answerDiv.style.visibility = 'visible';
				slideContent(numericId,mostpopular_slideSpeed);
			}
		}else{
			slideContent(numericId,(mostpopular_slideSpeed*-1));
			mostpopular_activeId = false;
		}
	}
}

function slideContent(inputId,direction)
{
	var obj =document.getElementById('mostpopular_a' + inputId);
	var contentObj = document.getElementById('mostpopular_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)
	height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight)
	{
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1)
	{
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction)
	{
		setTimeout('slideContent(' + inputId + ',' + direction + ')',mostpopular_timer);
	}else{
		if(height<=1)
		{
			obj.style.display='none';
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId)
			{
				document.getElementById('mostpopular_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('mostpopular_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,mostpopular_slideSpeed);
			}else{
				mostpopular_slideInProgress = false;
			}
                }else{
                        mostpopular_activeId = inputId;
                        mostpopular_slideInProgress = false;
                }
        }
}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++)
	{
		if(divs[no].className=='mosthead')
		{
			divs[no].onclick = showHideContent;
			divs[no].id = 'mostpopular_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV')
			{
				answer = answer.nextSibling;
			}
			answer.id = 'mostpopular_a'+divCounter;
			var contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='content_mostpopular';
			contentDiv.id = 'mostpopular_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}
/********************************************************/
/***************** ProdCat **************************/
function showHideContent1(e,inputId)
{
	if(prodcat_slideInProgress)return;
	prodcat_slideInProgress = true;
	if(!inputId)inputId = this.id;
		inputId = inputId + '';
		var numericId = inputId.replace(/[^0-9]/g,'');
		var answerDiv = document.getElementById('prodcat_a' + numericId);
		//alert("answerDiv	:"+answerDiv);
		objectIdToSlideDown = false;

	if (answerDiv != null) 
	{
		if(!answerDiv.style.display || answerDiv.style.display=='none')
		{
			//alert("I M Here");
			if(prodcat_activeId &&  prodcat_activeId!=numericId)
			{
				objectIdToSlideDown = numericId;
				slideContent1(prodcat_activeId,(prodcat_slideSpeed*-1));
			}else{
				answerDiv.style.display='block';
				answerDiv.style.visibility = 'visible';
				slideContent1(numericId,prodcat_slideSpeed);
			}
		}else{
			slideContent1(numericId,(prodcat_slideSpeed*-1));
			prodcat_activeId = false;
		}
	}
}

function slideContent1(inputId,direction)
{
	var obj =document.getElementById('prodcat_a' + inputId);
	var contentObj = document.getElementById('prodcat_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)
	height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight)
	{
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1)
	{
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction)
	{
		setTimeout('slideContent1(' + inputId + ',' + direction + ')',prodcat_timer);
	}else{
		if(height<=1)
		{
			obj.style.display='none';
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId)
			{
				document.getElementById('prodcat_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('prodcat_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent1(objectIdToSlideDown,prodcat_slideSpeed);
			}else{
				prodcat_slideInProgress = false;
			}
                }else{
                        prodcat_activeId = inputId;
                        prodcat_slideInProgress = false;
                }
        }
}

function initShowHideDivs1()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++)
	{
		if(divs[no].className=='prodhead')
		{
			divs[no].onclick = showHideContent1;
			divs[no].id = 'prodcat_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV')
			{
				answer = answer.nextSibling;
			}
			answer.id = 'prodcat_a'+divCounter;
			var contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='content_prodcat';
			contentDiv.id = 'prodcat_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}


/*************************************************************************/

/***************** Brand **************************/
function showHideContent2(e,inputId)
{
	if(brand_slideInProgress)return;
	brand_slideInProgress = true;
	if(!inputId)inputId = this.id;
		inputId = inputId + '';
		var numericId = inputId.replace(/[^0-9]/g,'');
		var answerDiv = document.getElementById('brand_a' + numericId);
		//alert("answerDiv	:"+answerDiv);
		objectIdToSlideDown = false;

	if (answerDiv != null) 
	{
		if(!answerDiv.style.display || answerDiv.style.display=='none')
		{
			//alert("I M Here");
			if(brand_activeId &&  brand_activeId!=numericId)
			{
				objectIdToSlideDown = numericId;
				slideContent2(brand_activeId,(brand_slideSpeed*-1));
			}else{
				answerDiv.style.display='block';
				answerDiv.style.visibility = 'visible';
				slideContent2(numericId,brand_slideSpeed);
			}
		}else{
			slideContent2(numericId,(brand_slideSpeed*-1));
			brand_activeId = false;
		}
	}
}

function slideContent2(inputId,direction)
{
	var obj =document.getElementById('brand_a' + inputId);
	var contentObj = document.getElementById('brand_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)
	height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight)
	{
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1)
	{
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction)
	{
		setTimeout('slideContent2(' + inputId + ',' + direction + ')',brand_timer);
	}else{
		if(height<=1)
		{
			obj.style.display='none';
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId)
			{
				document.getElementById('brand_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('brand_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent2(objectIdToSlideDown,brand_slideSpeed);
			}else{
				brand_slideInProgress = false;
			}
                }else{
                        brand_activeId = inputId;
                        brand_slideInProgress = false;
                }
        }
}

function initShowHideDivs2()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++)
	{
		if(divs[no].className=='brandhead')
		{
			divs[no].onclick = showHideContent2;
			divs[no].id = 'brand_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV')
			{
				answer = answer.nextSibling;
			}
			answer.id = 'brand_a'+divCounter;
			var contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='content_brand';
			contentDiv.id = 'brand_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}
