//JS script for Joomla template
var siteurl = '';

function JV_FullHeight() {
	var right_col = $('jv-right');
	var left_col = $('jv-left');
	var content_col = $('jv-maincontentwrapper');
	var footer = $('jv-footer');
	
	var right_height = right_col.getCoordinates().height;
	var left_height = left_col.getCoordinates().height;
	var content_height = content_col.getCoordinates().height;

	var maxheight = Math.max(right_height,left_height,content_height);

	right_col.setStyle('height',maxheight+200);
	left_col.setStyle('height',maxheight+200);
	content_col.setStyle('height',maxheight+200);
	footer.setStyle('position','absolute');
	footer.setStyle('bottom','0');
}
function JVSetWidthSubMenu(){
	//alert('start');
	var parent_ul = $('jv-cssmenu');
	//alert(parent_ul);
	var parent_li = parent_ul.getElements('li');
	var li_childs;
	parent_li.each(function(item,index){
		var _width  = item.offsetWidth -6;

		if(item.hasClass('havechild'))
		{
			li_childs = item.getElements('li');
			li_childs.each(function(_item){
				_item.setStyle('width',_width);
			});
		}
	});
}
function processModules() {
	var _list = $$('.moduletable');
	var list_module_pink = $$('.moduletable-pink');
	var list_module_green = $$('.moduletable-green');
	var list_module_orange = $$('.moduletable-orange');
	var temphtml = '';
	var _child = null;
	var _child_th = null;
	if (_list) {
		_list.each(function(e) {
			_child = e.getElementsByTagName('td')[0];
			_child_th = e.getElementsByTagName('th')[0];
			temphtml = _child.innerHTML;
			if (_child_th) {
				temphtml = '<div class="module"><div><div><div><div class="moduletitle">' + _child_th.innerHTML + '</div>' + temphtml + '</div></div></div></div>';
				_child.innerHTML = temphtml;	
			} 
			e.setStyle('visibility','visible');
		});
	}
	if (list_module_pink) {
		list_module_pink.each(function(e) {
			_child = e.getElementsByTagName('td')[0];
			_child_th = e.getElementsByTagName('th')[0];
			temphtml = _child.innerHTML;
			if (_child_th) {
				temphtml = '<div class="module-pink"><div><div><div><div class="moduletitle">' + _child_th.innerHTML + '</div>' + temphtml + '</div></div></div></div>';
				_child.innerHTML = temphtml;
			}
			e.setStyle('visibility','visible'); 
			
		});
	}
	if (list_module_green) {
		list_module_green.each(function(e) {
			_child = e.getElementsByTagName('td')[0];
			_child_th = e.getElementsByTagName('th')[0];
			temphtml = _child.innerHTML;
			if (_child_th) {
				temphtml = '<div class="module-green"><div><div><div><div class="moduletitle">' + _child_th.innerHTML + '</div>' + temphtml + '</div></div></div></div>';
				_child.innerHTML = temphtml;
			}
			e.setStyle('visibility','visible'); 
		});
	}
	if (list_module_orange) {
		list_module_orange.each(function(e) {
			_child = e.getElementsByTagName('td')[0];
			_child_th = e.getElementsByTagName('th')[0];
			temphtml = _child.innerHTML;
			if (_child_th) {
				temphtml = '<div class="module-orange"><div><div><div><div class="moduletitle">' + _child_th.innerHTML + '</div>' + temphtml + '</div></div></div></div>';
				_child.innerHTML = temphtml;
			}
			e.setStyle('visibility','visible');
		});
	}
}
function SizeProcess() {
	var _content = $('jv-maincontentwrapper');
	var _right 	 = $('jv-right');
	var found    = false;
	$$('#jv-right img').each (function (e) {
		if (e.width > 160) {
			_content.setStyle('width','435px');
			_right.setStyle('width','256px');
		}
	});
	$$('#jv-right iframe').each (function (e) {
		if (e.width > 160) {
			_content.setStyle('width','435px');
			_right.setStyle('width','256px');
		}
	});
}

window.addEvent ('load', function() {
	setTimeout(JV_FullHeight,1000);
	processModules();
	//setTimeout(ImgProcess,400);
	//setInterval(SizeProcess, 500);
	JVSetWidthSubMenu();
});
function ImgProcess(){
	var list_h3 = $$('div.module');
	//var list_module_pink = $$('div.module-pink');
	//var list_module_green = $$('div.module-green');
	//var list_module_orange = $$('div.module-orange');
	//list_h3 = list_h3.concat(list_module_pink);
	//list_h3 = list_h3.concat(list_module_green);
	//list_h3 = list_h3.concat(list_module_orange);
	var temphtml = '';
	var _parent = null;
	if (list_h3) {
		list_h3.each(function(e){
			_child = e.getElementsByTagName('div')[0];
			if (e.innerHTML.indexOf('moduletitle') != -1) _child.setStyle('border','solid 1px #32AA32');
		});
	}
}
window.addEvent ('load', function() {
	setTimeout(ImgProcess,300);
});