window.gAnimations = new Array();

function anim(pId, pMarg) {
	if(!window.gAnimations[pId]) {
		window.gAnimations[pId] = true;
		$('#nmn-'+pId).animate({marginTop: pMarg}, 200, 'linear', function() {  });
		window.gAnimations[pId] = false;
	}
}

window.slide = true;
window.lastActive = 0;
window.hasTimeouts = false

window.activeTimeout = '';

function setActiveOpinion2(pId, pAll)
{
	if(window.slide) {
		window.hasTimeouts = false;
		setActiveOpinion(pId, pAll);
	}
	else {
		if(!window.hasTimeouts) {
			window.hasTimeouts = true;
			clearTimeout(window.activeTimeout);
			window.activeTimeout = setTimeout('setActiveOpinion2('+next+', '+pAll+')', 15 * 1000);
		}
	}
}

function setActiveOpinion(pId, pAll)
{
	try {
		window.lastActive = pId;
		
		$('.bullet').removeClass('bulletActive');
		$('.frontNewsBlock').hide();
		
		ind = 4;
		
		for(i = 0; i < ind; i++) {
			$('#fnbb-'+(pId+i)).addClass('bulletActive');
			
			$('#fnb-'+(pId+i)).fadeIn();
		}
		
		if(pId + ind <= pAll)
			to = pId + ind - 1;
		else
			to = pAll;
		
		$('.current').html(pId + ' / ' + to);
		
		if(pId + 4 <= pAll)
			next = pId + 4;
		else
			next = 1;
		
		if(!window.hasTimeouts) {
			window.hasTimeouts = true;
			clearTimeout(window.activeTimeout);
			window.activeTimeout = setTimeout('setActiveOpinion2('+next+', '+pAll+')', 15 * 1000);
		}
	}
	catch(e) {
		alert('Something went wrong');
	}
}

function setNextOpinion(pNext, pAll)
{
	ind = window.lastActive;
	
	if(pNext && ind + 4 > pAll) {
		ind = 1;
	}
	else if(!pNext && ind - 4 < 1) {
		ind = pAll;
	}
	else {
		if(pNext)
			ind = window.lastActive + 1;
		else
			ind = window.lastActive - 1;
	}
	
	setActiveOpinion(ind, pAll);
}

function openwindow(url, width, height) {
	// hack for IE 7
	if(navigator.appVersion.indexOf('MSIE 7') != -1) {
		height += 20;
	}

	xposition = 20; yposition = 20;
	if ((parseInt(navigator.appVersion) >= 4 )){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}

	args = "width=" + width + ","
		    + "height=" + height + ","
			+ "location=0,"
			+ "menubar=0,"
			+ "resizable=0,"
			+ "scrollbars=no,"
			+ "status=0,"
			+ "titlebar=0,"
			+ "toolbar=0,"
			+ "hotkeys=0,"
			+ "screenx=" + xposition + ","  //NN Only
			+ "screeny=" + yposition + ","  //NN Only
			+ "left=" + xposition + ","     //IE Only
			+ "top=" + yposition;           //IE Only
	ww = window.open(url, 'Manager', args);
}

function toggleEditor(id) {
	if (!tinyMCE.getInstanceById(id)) {
		$('#'+id).addClass('tinymce_area');
		tinyMCE.execCommand('mceAddControl', false, id);
	}
	else {
		$('#'+id).removeClass('tinymce_area').addClass('inputTextarea');
		tinyMCE.execCommand('mceRemoveControl', false, id);
	}
}

try {
	$(function() {
		$('.imgPopup').lightBox();
	});
}
catch(e) {}

function correctPNG() 
{
	for(var i=0; i<document.images.length; i++)
	 {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		     {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
			 var strNewHTML = "<img src=\"/img/blank.gif\" " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\" />" 
			 img.outerHTML = strNewHTML
			 i = i-1
		     }
	 }
}
if(window.attachEvent)
	window.attachEvent("onload", correctPNG);