// возвращает cookie если есть или undefined
function getCookie(name) {
	var matches = document.cookie.match(new RegExp(
	  "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
	))
	return matches ? decodeURIComponent(matches[1]) : undefined 
}

// уcтанавливает cookie
function setCookie(name, value, props) {
	props = props || {}
	var exp = props.expires
	if (typeof exp == "number" && exp) {
		var d = new Date()
		d.setTime(d.getTime() + exp*1000)
		exp = props.expires = d
	}
	if(exp && exp.toUTCString) { props.expires = exp.toUTCString() }

	value = encodeURIComponent(value)
	var updatedCookie = name + "=" + value
	for(var propName in props){
		updatedCookie += "; " + propName
		var propValue = props[propName]
		if(propValue !== true){ updatedCookie += "=" + propValue }
	}
	document.cookie = updatedCookie

}

// удаляет cookie
function deleteCookie(name) {
	setCookie(name, null, { expires: -1 })
}

currentLabel="";
function getLabelInfo(labelID,b){currentLabel=labelID; idLabel=setTimeout("showLabelInfo()",50);document.getElementById(currentLabel+"_box").innerHTML=document.getElementById(currentLabel+"_content").innerHTML;}

function closeLabelInfo() {clearInterval(idLabel);}
function showLabelInfo(){
	display_none("videoLink");
	for(i=0;i<helpShow.length;i++) {
		display_none(helpShow[i]+'_box');display_none(helpShow[i]+'_closeBox'); display_none(helpShow[i]+'_label');
		}
	document.getElementById(currentLabel+"_box").style.left=(parseInt(document.getElementById(currentLabel+"_label").style.left)+parseInt(document.getElementById(currentLabel+"_label").style.width)+0)+"px";
	document.getElementById(currentLabel+"_box").style.display='block';
	document.getElementById(currentLabel+"_box").style.top=(parseInt(document.getElementById(currentLabel+"_label").style.top)-getElementPosition(currentLabel+"_box").height/3)+"px";
	dLabelY=getElementPosition(currentLabel+"_box").top; BOXWidth=getElementPosition(currentLabel+"_box").width;
	if(dLabelY<10) document.getElementById(currentLabel+"_box").style.top=(parseInt(document.getElementById(currentLabel+"_box").style.top)+10+Math.abs(dLabelY))+"px";
	document.getElementById(currentLabel+"_closeBox").style.top=document.getElementById(currentLabel+"_box").style.top;
	document.getElementById(currentLabel+"_closeBox").style.left=(parseInt(document.getElementById(currentLabel+"_box").style.left)+BOXWidth-18)+"px";
	display_block(currentLabel+"_closeBox");
}

function closeLabel(a){
display_none(a+'_box');display_none(a+'_closeBox');
for(i=0;i<helpShow.length;i++) {display_block(helpShow[i]+'_label');}
display_block("videoLink");
}


function getElementPosition(elemId){
	var elem = document.getElementById(elemId); var w = elem.offsetWidth;  var h = elem.offsetHeight; var l = 0; var t = 0;
	while (elem) {l += elem.offsetLeft; t += elem.offsetTop; elem = elem.offsetParent;}
return {"left":l, "top":t, "width": w, "height":h};
}

function display_none(n) {document.getElementById(n).style.display = 'none'}
function display_block(n) {document.getElementById(n).style.display = 'block'}

function showImageDescription(a){
	document.getElementById('tDESC').innerHTML=document.getElementById('DESC'+a).innerHTML;
}
function galleryLinkTranslate(a){
	if((a+"").indexOf("?pageID")!=-1) {location.href=a;}
	else if((a+"").indexOf("http://")+1) {location.href=a;}
	else localGallery(""+a);
	}

function ShowFlashVideo(a){
DivId='dID'+Math.random(); document.write('<div id='+DivId+'></div>');
var params = {};var attributes = {}; var flashvars = {}; params.wmode = 'transparent'; params.allowfullscreen = 'true'; flashvars.FV=''; 
swfobject.embedSWF(a,DivId,'100','100','6', '', flashvars, params, attributes)
}

function showFlashGuide(a,DivId,fW,fH){	//для стандартной ситуации - переключение гида
if(a!="off") {
	display_none(DivId+"ICO"); display_block(DivId+"CONTAINER");
	var params={}; var attributes={}; var flashvars={}; params.wmode='transparent';			
	swfobject.embedSWF(a,(DivId+"FLASH"),fW,fH,"6",'',flashvars, params, attributes);
	document.cookie="hideGuide=0";
	}
else {display_none(DivId+"CONTAINER"); display_block(DivId+"ICO"); document.cookie="hideGuide=1";}
}

helpShow=new Array();
//helpShow[0]='adminPanel';

