function findPos(obj){
	var curleft=curtop=0;
	if(obj.offsetParent){
		curleft=obj.offsetLeft;
		curtop=obj.offsetTop;
		while(obj=obj.offsetParent){
			curleft+=obj.offsetLeft;
			curtop+=obj.offsetTop;
		}
	}
	return[curleft,curtop];
}

var hover_triangle_up=$('hover_triangle_up');
var hover_triangle_left=$('hover_triangle_left');
var hover_play_icon=$('hover_play_icon');

if(ml=$('media_listing')){
	var items=ml.getElementsByTagName('div');
	for(q=0;q<items.length;q++){
		if(items[q].className=="item"){
			items[q].onmouseover=function(){accent(this,true)}
			items[q].onmouseout=function(){accent(this)}
		}
	}

	function accent(div,show){
		if(show){
			a=div.getElementsByTagName('a');
			if(hover_triangle_left.parentNode!=a[0]||hover_play_icon.parentNode!=a[0]){
				hover_triangle_left.parentNode.removeChild(hover_triangle_left);
				a[0].appendChild(hover_triangle_left);
				hover_play_icon.parentNode.removeChild(hover_play_icon);
				a[0].appendChild(hover_play_icon);
			}
			pos=findPos(div);
			div.className="item_hover";
			hover_triangle_left.style.display="block";
			hover_triangle_left.style.left=113+"px";
			hover_triangle_left.style.top=37+"px";
			hoverPlay(div,false,Array(8,7));
		}else{
			div.className="item";
			hover_triangle_left.style.display="none";
			hoverPlay(div,true);
		}
	}
}

if(mlh=$('media_listing_hor')){
	var media_listing_hor_groups=Array();

	function mlhAccent(a,hide_play_icon){
		var htu=media_listing_hor_groups[a.getAttribute('group')];
		if((htu.parentNode!=a||hover_play_icon.parentNode!=a)){
			if(htu.parentNode)htu.parentNode.removeChild(htu);
			a.appendChild(htu);
			hover_play_icon.parentNode.removeChild(hover_play_icon);
			a.appendChild(hover_play_icon);
		}
		pos=findPos(a);
		htu.style.display="block";
		htu.style.left=pos[0]+47+"px";
		htu.style.top=pos[1]+72+"px";
		var group_a=$('post_info_group_'+a.getAttribute('group'));
		group_a.href=a.href;
		group_a.title=a.title;
		spans=group_a.getElementsByTagName('span');
		spans[0].innerHTML=a.title;
		spans[1].innerHTML=a.getAttribute('descr');
		if(!hide_play_icon){
			hoverPlay(a,false,pos)
		}
	}

	var divs=mlh.getElementsByTagName('div');
	for(q=0;q<divs.length;q++){
		if(divs.className="thumbs"){
			var as=divs[q].getElementsByTagName('a');
			for(w=0;w<as.length;w++){
				if(as[w].getAttribute('group')){
					if(!w){
						media_listing_hor_groups[as[0].getAttribute('group')]=hover_triangle_up.cloneNode(false);
						mlhAccent(as[0],true);
					}
					as[w].onmouseover=function(){mlhAccent(this)}
					as[w].onmouseout=function(){hoverPlay(this,true)}
				}
			}
		}
	}
	hover_triangle_up.parentNode.removeChild(hover_triangle_up);
}

if(fmt=$('fm_thumbs')){
	var fm_thumbs=fmt.getElementsByTagName('a');
	var fm_current_title=$('fm_title');
	var fm_current_descr=$('fm_descr');
	for(q=0;q<fm_thumbs.length;q++){
		fm_thumbs[q].onmouseover=function(){fmAccent(this)}
		fm_thumbs[q].onmouseout=function(){hoverPlay(this,true)}
	}

	function fmAccent(a,hide_play_icon){
		if(hover_triangle_up.parentNode!=a||hover_play_icon.parentNode!=a){
			hover_triangle_up.parentNode.removeChild(hover_triangle_up);
			a.appendChild(hover_triangle_up);
			hover_play_icon.parentNode.removeChild(hover_play_icon);
			a.appendChild(hover_play_icon);
		}
		pos=findPos(a);
		hover_triangle_up.style.display="block";
		hover_triangle_up.style.left=pos[0]+47+"px";
		hover_triangle_up.style.top=pos[1]+72+"px";
		fm_current_title.parentNode.href=a.href;
		fm_current_title.parentNode.title=a.title;
		fm_current_title.innerHTML=a.title;
		fm_current_descr.innerHTML=a.getAttribute('descr');
		if(!hide_play_icon){
			hoverPlay(a,false,pos)
		}
	}

	fmAccent(fm_thumbs[0],true);
}

function hoverPlay(a,hide,pos,offset){
	if(hide){
		hover_play_icon.style.display='none';
	}else{
		if(!pos){
			pos=findPos(a);
		}
		if(offset){
			pos[0]+=offset[0];
			pos[1]+=offset[1];
		}
		hover_play_icon.style.left=pos[0]+'px';
		hover_play_icon.style.top=pos[1]+'px';
		hover_play_icon.style.display='block';
	}
}

function hideTripleDots(divs,width){
	var max=divs.length;
	for(var q=0;q<max;q++){
		d=divs[q];
		if(d.scrollWidth>width){
		alert(d.scrollWidth);
			d.nextSibling.style.display="block";
			d.style.width=width+'px';
		}
	}
}

window.onload=function(){
//	if(divs=$('recently_updated_blogs')){
//		hideTripleDots(divs.getElementsByTagName('i'),75);
//	}
//	hideTripleDots('.related_media .cutted_text', 140);
//	hideTripleDots('.recently_updated .cutted_text', 60);

	if((ml=$('media_listing'))&&ml.className!='short'){
		var items=ml.getElementsByTagName('div');
		for(q=0;q<items.length;q++){
			if(items[q].className=="item"){
				var h1s=items[q].getElementsByTagName('h1');
				h1=h1s[0];
				var infos=items[q].getElementsByTagName('div');
				info=infos[0];
				var diff=h1.offsetLeft+h1.offsetWidth-info.offsetLeft+5;
				if(diff>0){
					h1.parentNode.style.paddingTop="7px";
					h1.style.width=(h1.offsetWidth-diff)+"px";
					h1.style.display="block";
				}
			}
		}
	}
}
