/******************************************************** 
Done by Prasad Babu on 01-dec-2006
to implement the expand-collapse effect in brand section
This changes the hide content shows in slides
*********************************************************/

var brand_slideSpeed = 8; // Higher value = faster
var brand_timer = 5;      // Lower value = faster
var objectIdToSlideDown = false;
var brand_activeId = false;
var brand_slideInProgress = false;

var product_slideSpeed = 8; // Higher value = faster
var product_timer = 5;      // Lower value = faster
var objectIdToSlideDown1 = false;
var product_activeId = false;
var product_slideInProgress = false;

var classified_slideSpeed = 8; // Higher value = faster
var classified_timer = 5;      // Lower value = faster
var objectIdToSlideDown2 = false;
var classified_activeId = false;
var classified_slideInProgress = false;

/***************** brand_news_tabs **************************/
function showHideContent(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);
		objectIdToSlideDown = false;

	if (answerDiv != null) 
	{
		if(!answerDiv.style.display || answerDiv.style.display=='none')
		{
			if(brand_activeId &&  brand_activeId!=numericId)
			{
				objectIdToSlideDown = numericId;
				slideContent(brand_activeId,(brand_slideSpeed*-1));
			}else{
				answerDiv.style.display='block';
				answerDiv.style.visibility = 'visible';
				slideContent(numericId,brand_slideSpeed);
			}
		}else{
			slideContent(numericId,(brand_slideSpeed*-1));
			brand_activeId = false;
		}
	}
}

function slideContent(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('slideContent(' + 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';
				slideContent(objectIdToSlideDown,brand_slideSpeed);
			}else{
				brand_slideInProgress = false;
			}
                }else{
                        brand_activeId = inputId;
                        brand_slideInProgress = false;
                }
        }
}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++)
	{
		if(divs[no].className=='brand_sub')
		{
			divs[no].onclick = showHideContent;
			divs[no].id = 'brand_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV')
			{
				answer = answer.nextSibling;
			}
			answer.id = 'brand_a'+divCounter;
			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++;
		}
	}
}

/***************** prodcat_news_tabs **************************/

function showHideContent1(f,inputId)
{
	if(product_slideInProgress)return;
	product_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('product_a' + numericId);
	objectIdToSlideDown1 = false;

	if (answerDiv != null) 
	{
		if(!answerDiv.style.display || answerDiv.style.display=='none')
		{
			if(product_activeId &&  product_activeId!=numericId)
			{
				objectIdToSlideDown1 = numericId;
				slideContent1(product_activeId,(product_slideSpeed*-1));
			}else{
				answerDiv.style.display='block';
				answerDiv.style.visibility = 'visible';
				slideContent1(numericId,product_slideSpeed);
			}
		}else{
			slideContent1(numericId,(product_slideSpeed*-1));
			product_activeId = false;
		}
	}
}

function slideContent1(inputId,direction)
{
	var obj =document.getElementById('product_a' + inputId);
	var contentObj = document.getElementById('product_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 + ')',product_timer);
	}else{
		if(height<=1)
		{
			obj.style.display='none';
			if(objectIdToSlideDown1 && objectIdToSlideDown1!=inputId)
			{
				document.getElementById('product_a' + objectIdToSlideDown1).style.display='block';
				document.getElementById('product_a' + objectIdToSlideDown1).style.visibility='visible';
				slideContent1(objectIdToSlideDown1,product_slideSpeed);
			}else{
				product_slideInProgress = false;
			}
		}else{
			product_activeId = inputId;
			product_slideInProgress = false;
		}
	}
}
function initShowHideDivs1()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++)
	{
		if(divs[no].className=='brand_sub1')
		{
			divs[no].onclick = showHideContent1;
			divs[no].id = 'product_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV')
			{
				answer = answer.nextSibling;
			}
			answer.id = 'product_a'+divCounter;
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='content_product';
			contentDiv.id = 'product_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}

/***************** prodcat_brands_classifieds **************************/

function showHideContent2(e,inputId)
{
	if(classified_slideInProgress)return;
	classified_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('classified_a' + numericId);
	objectIdToSlideDown2 = false;
	
	if (answerDiv != null) 
	{
		if(!answerDiv.style.display || answerDiv.style.display=='none')
		{
			if(classified_activeId &&  classified_activeId!=numericId)
			{
				objectIdToSlideDown2 = numericId;
				slideContent2(classified_activeId,(classified_slideSpeed*-1));
			}else{
				answerDiv.style.display='block';
				answerDiv.style.visibility = 'visible';
				slideContent2(numericId,classified_slideSpeed);
			}
		}else{
			slideContent2(numericId,(classified_slideSpeed*-1));
			classified_activeId = false;
		}
	}
}
function slideContent2(inputId,direction)
{
	var obj =document.getElementById('classified_a' + inputId);
	var contentObj = document.getElementById('classified_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 + ')',classified_timer);
	}else{
		if(height<=1)
		{
			obj.style.display='none';
			if(objectIdToSlideDown2 && objectIdToSlideDown2!=inputId)
			{
				document.getElementById('classified_a' + objectIdToSlideDown2).style.display='block';
				document.getElementById('classified_a' + objectIdToSlideDown2).style.visibility='visible';
				slideContent2(objectIdToSlideDown2,classified_slideSpeed);
			}else{
				classified_slideInProgress = false;
			}
		}else{
			classified_activeId = inputId;
			classified_slideInProgress = false;
		}
	}
}
function initShowHideDivs2()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++)
	{
		if(divs[no].className=='brand_sub2')
		{
			divs[no].onclick = showHideContent2;
			divs[no].id = 'classified_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV')
			{
				answer = answer.nextSibling;
			}
			answer.id = 'classified_a'+divCounter;
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='content_classified';
			contentDiv.id = 'classified_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}

