var t;
var currentexpandedlistdiv = '';
var LastSeenExpandedListItemID = 0;

function startCount(categoryid) {
	var time = document.getElementById('reviewrotations_' + categoryid).value;
	t = setTimeout("changeReviewContent(" + categoryid + ")", time);
}

function stopCount() {
	clearTimeout(t);
}

function changeReviewContent(categoryid) {
	var sfEls = document.getElementById("shortreviewsbuttonsdiv_" + categoryid).getElementsByTagName("table");
	var tchilds = sfEls[0].tBodies[0].childNodes[0];
	var ind = 0;
	var ind1 = 0;
	var objectid = 0;

	if (currentreviewdiv == '') {
		for (var i=0; i<tchilds.childNodes.length; i++) {
			if (tchilds.childNodes[i].childNodes[0].style.visibility == 'visible') {
				ind = i;
				objectid = tchilds.childNodes[i].childNodes[0].id.replace('imagetop_', '');
			}
		}
	}
	else {
		for (var i=0; i<tchilds.childNodes.length; i++) {
			if (tchilds.childNodes[i].childNodes[0].id == 'imagetop_' + currentreviewdiv) {
				ind = i;				
			}
		}
		
		if (ind == (tchilds.childNodes.length-1))				
			objectid = tchilds.childNodes[0].childNodes[0].id.replace('imagetop_', '');
		else
			objectid = tchilds.childNodes[(ind+1)].childNodes[0].id.replace('imagetop_', '');
	}	

	tchilds.childNodes[ind].childNodes[0].style.visibility = 'hidden';
	tchilds.childNodes[ind].childNodes[1].childNodes[0].style.backgroundImage = 'url(\'/app_cm2/images/button_noactiv_0.gif\')';
	tchilds.childNodes[ind].childNodes[1].childNodes[1].style.backgroundImage = 'url(\'/app_cm2/images/button_noactiv_2.gif\')';
	tchilds.childNodes[ind].childNodes[1].childNodes[2].style.backgroundImage = 'url(\'/app_cm2/images/button_noactiv_1.gif\')';			
	tchilds.childNodes[ind].childNodes[1].childNodes[2].style.color	= '#f7a35e';
	document.getElementById('shortreviewscontentid_' + currentreviewdiv).style.display = 'none';	

	ind1 = ((ind == (tchilds.childNodes.length-1)) ? 0 : (ind+1));
	tchilds.childNodes[ind1].childNodes[0].style.visibility = 'visible';
	tchilds.childNodes[ind1].childNodes[1].childNodes[0].style.backgroundImage = 'url(\'/app_cm2/images/button_activ_0.gif\')';
	tchilds.childNodes[ind1].childNodes[1].childNodes[1].style.backgroundImage = 'url(\'/app_cm2/images/button_activ_2.gif\')';
	tchilds.childNodes[ind1].childNodes[1].childNodes[2].style.backgroundImage = 'url(\'/app_cm2/images/button_activ_1.gif\')';			
	tchilds.childNodes[ind1].childNodes[1].childNodes[2].style.color = '#ffffff';
	
	document.getElementById('shortreviewscontentid_' + objectid).style.display = 'block';	
	
	currentreviewdiv = objectid;
	stopCount();
	startCount(categoryid);	
}

function showReviewContent(categoryid, objectid) {
	stopCount();
	
	if (currentreviewdiv != objectid) {	
		document.getElementById('imagetop_' + objectid).style.visibility = 'hidden';
		document.getElementById('image0_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_activ_0.gif\')';
		document.getElementById('image2_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_activ_2.gif\')';
		document.getElementById('image1_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_activ_1.gif\')';
		//document.getElementById('image1_' + objectid).style.color = '#ffffff';
	}
}

function hideReviewContent(categoryid, objectid) {
	var sfEls = document.getElementById("shortreviewsbuttonsdiv_" + categoryid).getElementsByTagName("table");
	var tchilds = sfEls[0].tBodies[0].childNodes[0];
	for (var i=0; i<tchilds.childNodes.length; i++) {
		if (currentreviewdiv != objectid) {
			document.getElementById('imagetop_' + objectid).style.visibility = 'hidden';
			document.getElementById('image0_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_noactiv_0.gif\')';
			document.getElementById('image2_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_noactiv_2.gif\')';
			document.getElementById('image1_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_noactiv_1.gif\')';
			document.getElementById('image1_' + objectid).style.color = '#f7a35e';
			
		}
	}
	
	startCount(categoryid);
}

function checkReviewContent(categoryid, objectid) {	
	var sfEls = document.getElementById("shortreviewsbuttonsdiv_" + categoryid).getElementsByTagName("table");
	var tchilds = sfEls[0].tBodies[0].childNodes[0];
	for (var i=0; i<tchilds.childNodes.length; i++) {
		tchilds.childNodes[i].childNodes[0].style.visibility = 'hidden';
		tchilds.childNodes[i].childNodes[1].childNodes[0].style.backgroundImage	= 'url(\'/app_cm2/images/button_noactiv_0.gif\')';
		tchilds.childNodes[i].childNodes[1].childNodes[1].style.backgroundImage	= 'url(\'/app_cm2/images/button_noactiv_2.gif\')';
		tchilds.childNodes[i].childNodes[1].childNodes[2].style.backgroundImage	= 'url(\'/app_cm2/images/button_noactiv_1.gif\')';			
		tchilds.childNodes[i].childNodes[1].childNodes[2].style.color = '#f7a35e';
	}
	
	var divEls = document.getElementById("shortreviewsdivid_" + categoryid).getElementsByTagName("div");
	for (var i=0; i<divEls.length; i++) {
		if (divEls[i].id.indexOf("shortreviewscontentid_") != -1)
			divEls[i].style.display = 'none';
	}
		
	document.getElementById('imagetop_' + objectid).style.visibility = 'visible';
	document.getElementById('image0_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_activ_0.gif\')';
	document.getElementById('image2_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_activ_2.gif\')';
	document.getElementById('image1_' + objectid).style.backgroundImage = 'url(\'/app_cm2/images/button_activ_1.gif\')';
	document.getElementById('image1_' + objectid).style.color = '#ffffff';
	document.getElementById("shortreviewscontentid_" + objectid).style.display = 'block';	
			
	currentreviewdiv = objectid;
}

function showFullContent(id) {
	document.getElementById('morebutton_' + id).style.display = 'none';
	document.getElementById('fullcontent_' + id).style.display = 'block';
	document.getElementById('hidebutton_' + id).style.display = 'block';		
}
function hideFullContent(id) {
	document.getElementById('morebutton_' + id).style.display = 'block';
	document.getElementById('fullcontent_' + id).style.display = 'none';
	document.getElementById('hidebutton_' + id).style.display = 'none';		
}

function showFullContent(componentid, pageid) {
	document.getElementById('morebutton_' + componentid + '_' + pageid).style.display = 'none';
	document.getElementById('fullcontent_' + componentid + '_' + pageid).style.display = 'block';
	document.getElementById('hidebutton_' + componentid + '_' + pageid).style.display = 'block';		
}

function hideFullContent(componentid, pageid) {
	document.getElementById('morebutton_' + componentid + '_' + pageid).style.display = 'block';
	document.getElementById('fullcontent_' + componentid + '_' + pageid).style.display = 'none';
	document.getElementById('hidebutton_' + componentid + '_' + pageid).style.display = 'none';	
	document.getElementById('fullcontent_' + componentid + '_' + pageid).innerHTML = '';	
}

function showHideExpandedListContent(objectid, listid, themesystemname) {
	if (themesystemname == '')
		themesystemname = 'main';
	var item = document.getElementById('expandedlist_' + objectid);
	if (item.style.display == 'block') {
		item.style.display = 'none';
		item.previousSibling.firstChild.firstChild.src = '/themes/' + themesystemname + '/images/plus.gif';
		return;
	}
	var list = document.getElementById('expandedlist_' + listid);
	var imgs = list.getElementsByTagName('img');
	for (var i=0; i<imgs.length; i++)
		imgs[i].src = '/themes/' + themesystemname + '/images/plus.gif';
	var divs = list.getElementsByTagName('div');
	for (var i=0; i<divs.length; i++) {
		if (divs[i].id.indexOf('expandedlist_') == 0)
			divs[i].style.display = 'none';
	}
	
	var i=0;
	while (item.className != 'expandedlist') {
		item.previousSibling.firstChild.firstChild.src = '/themes/' + themesystemname + '/images/minus.gif';
		item.style.display = 'block';
		item = item.parentNode;
		i++;
		if (i == 20)
			break;
	}

	window.location='#expandedlisthreflocation_' + objectid;
}

function replaceNullString(text) {
	var t = text;
	var re = new RegExp(' ','g');
	var a = t.replace(re, '');
	return (a);
}

var mainRefInterval = 0;
var mainRefTimeout = null;
function showMainRef(id) {
	if (mainRefTimeout)
		clearTimeout(mainRefTimeout);
	$('div.mbox_c').each(function(ind, obj) {
		if (obj.id != 'mref_' + id) {
			$(obj).addClass('mrefnonactive');
			$(obj).removeClass('mrefactive');
		}
		else {
			$(obj).addClass('mrefactive');
			$(obj).removeClass('mrefnonactive');
		}
	});
	if (mainRefInterval > 0)
		mainRefTimeout = setTimeout("rotateMainRef();", mainRefInterval * 1000);
}

function rotateMainRef(interval) {
	if (interval > 0) {
		mainRefInterval = interval;
		mainRefTimeout = setTimeout("rotateMainRef();", mainRefInterval * 1000);
	}
	else {
		var ind = 0;
		var items = $('div.mbox_c');
		items.each(function(index, obj) {
			if ($(obj).hasClass('mrefactive'))
				ind = index;
		});
		ind++;
		if (items.size() <= ind)
			ind = 0;
		
		showMainRef(items[ind].id.substring(5));
	}
}

$(document).ready(function(){    
	$(".lightbox").lightbox({
	    fitToScreen: true,
	    imageClickClose: false
    });    
});

