var docType = "HTML";
var isSafari = navigator.appVersion && navigator.appVersion.indexOf("Safari",0)>=0;
var IE  = (document.all) ? true : false;                      // ie4+
if(navigator.userAgent.indexOf("Opera") != -1) var O = true;  // Opera
// JavaScript Document
var agent = navigator.userAgent;
//alert(agent);
var version = parseFloat(navigator.appVersion);
var isOpera = agent.indexOf("Opera") > -1;
var isIE = agent.indexOf("compatible") > -1 && agent.indexOf("MSIE") > -1 && !isOpera;
var isGecko = agent.indexOf("Gecko") > -1;
var isFF = isGecko && agent.indexOf("Firefox") > -1;
var isNetscape=navigator.appName.indexOf("Netscape")!=-1;
var isIE7 = agent.indexOf("MSIE 7") > -1;

function dialog(url, _width, _height) {
	if (IE) window.event.cancelBubble = true; //Kad neeitu i ta linka kuri paspaudeme
	if (IE) window.event.returnValue = false; //paspaudej - ir nieko negrazino tau!!!
	var pav;
	nr_temp=Math.floor(Math.random()*1000);
	if (arguments[3]) pav=arguments[3];
		else pav=nr_temp;
	if (arguments[4]) scrollbar="yes";
		else scrollbar="no";
	window.open(url, pav, "top=100, left=100, width="+_width+", height="+_height+", menubar=no, resizeable=yes, scrollbars="+scrollbar+", staus=1, toolbar=no, location=no, directories=no");
}
var agent = navigator.userAgent;
var isGecko = agent.indexOf("Gecko") > -1;
var isFF = isGecko && agent.indexOf("Firefox") > -1;

// opredeliajem browser
	var N   	= (document.layers) ? true : false;                     // netscape 4
	var IE  	= (document.all) ? true : false;                        // ie4+
	var DOM 	= ((document.getElementById) && (!IE)) ? true : false;  // DOM1 browser (Netscape 6...)
	var MOZILLA	= DOM && navigator.appName=="Netscape" 					// Mozilla čėč Netscape 6.*
	var OPERA 	= window.opera && DOM 									//Opera 5+
	var OPERA6 	= OPERA && window.print 								//Opera 6+
	var OPERA7 	= OPERA && document.readyState 							//Opera 7+
	OPERA = navigator.appName=="Opera";
    var isSafari = navigator.appVersion && navigator.appVersion.indexOf("Safari",0)>=0;

function document_all(temp_id) {
		if(N) 	return document.layers(temp_id);
		if(DOM) return document.getElementById(temp_id);
			 	return document.all[temp_id];
}

// doc - document object
// sName - cookie name
// sValue - cookie value

function check_it() {
	var temp, out=false, re;
	if (IE) {
		event.returnValue =false;
		event.cancelBubble=true;
	}
	var arr = new Array("name", "text", "email");
	for (var i=0; i<arr.length; i++) {
		if (!document.getElementById(arr[i]).value || (document.getElementById("email").value && arr[i]=="email") || (document.getElementById("name").value == "Vardas *") || (document.getElementById("email").value == "El. paštas *") || (document.getElementById("text").value == "Tekstas *"))	{
			out=true;
			if (document.getElementById("email").value && arr[i]=="email"){
				temp = document.getElementById("email").value;
				re = new RegExp("([0-9a-zA-Z._-]+@[0-9a-zA-Z_-]+[.][a-zA-Z._-]+)", "g");
				var arr = temp.replace(re, "SUPER FILIA");
				if (arr != "SUPER FILIA") {
					out=true;
					alert(email_text);
					document.getElementById("email").value="";
					document.getElementById("email").focus();
					break;
				} else {out=false; break;}
			}
			else{
				alert(alert_text);
				document.getElementById(arr[i]).focus();
				break;
			}
		}
	}
 /*
	for(var i=0; i<arr.length; i++) {
		if (!document.getElementById(arr[i]).value)	{
				out=true;
				alert("<? echo $LANG["req"][$ln] ?>");
				document.getElementById(arr[i]).focus();
				break;
		}
	}
	if (document.getElementById("email").value && !out){
		temp = document.getElementById("email").value;
		re = new RegExp("([0-9a-zA-Z._-]+@[0-9a-zA-Z_-]+[.][a-zA-Z._-]+)", "g");
		var arr = temp.replace(re, "SUPER FILIA");
		if (arr != "SUPER FILIA") {
				out=true;
				alert("<? echo $LANG["req"][$ln] ?>");
				document.getElementById("email").value="";
				document.getElementById("email").focus();
		}
	}
 */
	if (IE)
		if (!out)
			event.returnValue=true;
}


function change(obj){
	arr= new Array(2005, 2004, 2003)
	document.getElementById(obj.id).style.fontSize = "20px";
	for (i=0; i<arr.length; i++)
		if (obj.id != arr[i])
			document.getElementById(arr[i]).style.fontSize = "11px";
	//div part
	document.getElementById("projects").innerHTML = document.getElementById(obj.id + "_projects").innerHTML;
}


function change_src(temp) {
	document.all["pr"].src="galery/__photo10/"+temp+".jpg";
}
/*function change_src(temp) {
	document.all["pr"].src="images/thumbs/"+temp+".jpg";
}*/


//// FOR ADVERTISEMENT
/*function advert(pixel, forward) {
	if (forward) {
		if (pixel!=(iki_pixels+1)) {
			clearInterval(t_adver_show);
			document.getElementById("advert").style.top = pixel + "px";
			document.getElementById("advert").style.left = (plius_peft + document.body.clientWidth / 2 - width / 2) + "px";
			t_adver_show = setInterval('advert(' + (pixel+1) + ', true)',  speed);
		}
		else {
	    	clearInterval(t_adver_show);
			t_hide = setInterval('hide()',  5000);
		}
	}
	else {
		if (pixel>=nuo_pixels) {
			clearInterval(t_adver_hide);
			document.getElementById("advert").style.top = pixel + "px";
			t_adver_hide = setInterval('advert(' + (pixel-2) + ', false)',  speed);
		}
		else {
			clearInterval(t_adver_hide);
	    	clearInterval(t_show);
			t_show = setInterval('show()',  5000);
		}
	}
}


function show(){
	clearInterval(t_show);
	t_adver_show = setInterval('advert('+ nuo_pixels + ', true)',  speed);
}


function hide(){
	clearInterval(t_hide);
	t_adver_hide = setInterval('advert(' + iki_pixels + ', false)',  speed);
}*/
function advert(obj, pixel, forward) {
	if (forward) {
		if (pixel!=(iki_pixels+1)) {
			obj.top = pixel;
			move = setTimeout('advert(obj, ' + (pixel+1) + ', true)',  speed);
		}
		else {
			move = setTimeout('advert(obj, ' + iki_pixels + ', false)',  5000);
		}
	}
	else {
		if (pixel>=nuo_pixels) {
			obj.top = pixel ;
			move = setTimeout('advert(obj, ' + (pixel-2) + ', false)',  speed);
		}
		else {
			move = setTimeout('advert(obj, '+ nuo_pixels + ', true)',  5000);
		}
	}
}
//////////////////////

function rec_paging(page) {
	var frm = document.getElementById('paging_form');
	if (frm) {
		frm.page.value = page;
		frm.submit();
	}
}


////////////////////////////////////

function get_width() {
	return Math.max(Math.round(document.body.clientWidth/2), 390) - 176;
}

function get_menu(obj) {
	var temp_obj=obj;
	for (i=0; i<3; i++)
		temp_obj = (IE) ? temp_obj.parentElement : temp_obj.parentNode;
	return temp_obj.offsetLeft + Math.max(Math.round(document.body.clientWidth/2)-394, -5);
}

function get_height() {
	return Math.max(Math.round(document.body.clientHeight/2), 280) - 195;
}

///// menu

var im_src=new Array('arrow','arrow.over','arrow.menu','arrow.menu.over', 'plus.gif', 'minus.gif', 'bullet.gif');
var im=new Array();
for (i=0; i<im.length; i++) {
	im[i]=new Image();
	im[i].src="images/"+im_src[i]+".gif";
}

var last_obj = new Object();
var menu_obj = new Object();
var menu_arr = new Array();
var menu_nr=1;
var menu_top = 161;

						 //new menu   parent    naujo_nr
function menu_over(tr_obj, menu_name, obj_name, temp_nr) {
	var x, y, tr_obj, temp, offset_x=(IE) ? 0: 5;
	if (IE)	event.cancelBubble=true; //!!
	menu_obj = document_all("menu_"+menu_name);
		menu_kill(temp_nr);
		menu_arr[temp_nr]=menu_obj;
	tr_obj.className="menu_tr_over";
	if (arguments.length<5) { //From sub menu
		last_obj = document_all("menu_"+obj_name);
		if (IE) x = last_obj.style.pixelLeft  + last_obj.clientWidth + offset_x;
		else {
			temp=last_obj.style.left;
			x=temp.substr(0, temp.length-2)*1 + tr_obj.offsetWidth + offset_x + "px";//last_obj.style.width;
		}
		if (IE) y = last_obj.style.pixelTop   + tr_obj.offsetTop;
		else {
			temp=last_obj.style.top;
			y=temp.substr(0, temp.length-2)*1 + tr_obj.offsetTop + "px";
		}
	} else { //From main menu
		x = arguments[4];
		y = menu_top + tr_obj.offsetTop;
	}
	if (is_object(menu_obj)) { //draw menu
		menu_obj.style.left=x;
		menu_obj.style.top =parseInt(y)-10+"px";
	}
}


function menu_make (menu_name) { //shot name
	var all="", arrow, tr_over, arr, row;
		var re = new RegExp("([_]+)", "g");
			var temp_len = menu_name.replace(re, "");
		temp_nr = menu_name.length - temp_len.length; //kiek "_";
	all ="<DIV ID=\"menu_"+menu_name+"\" class=air onmouseover=\"event.cancelBubble=true;\" width=1 height=1>";  //ID=>IE,
	all+="<TABLE cellpadding=0 cellspacing=0><TR><TD valign=top><IMG src=\"images/spacer.gif\"  width=5 height=29></TD><TD>";
	all+="<TABLE cellpadding=0 cellspacing=0 style='border: 0px solid #013364; background-color: #288EC1;'>";
	all+=row="<TR class=menu_tr height=10><TD colspan=3></TD></TR>";
	for (var i=1; i<arguments.length; i++) {
		arr=arguments[i];
		if (!arr[2]) arr[2]=arrow="";
				else arrow="class=arrow_menu";
		tr_over="onmouseover=\"menu_over(this, '"+arr[2]+"','"+menu_name+"',"+(temp_nr+1)+");\"";
		//all+="<TR class=menu_tr height=2><TD colspan=3></TD></TR>";
		all+="<TR ID=tr_"+arr[2]+" "+tr_over+" class=menu_tr onmouseout=\"menu_out(this);\" onclick=\"menu_click('"+arr[1]+"');\" height=19><TD width=15></TD><TD>"+arr[0]+"</TD><TD width=22 "+arrow+"></TD></TR>";
		//all+="<TR class=menu_tr height=2><TD colspan=3></TD></TR>";
	}
	all+=row;
	all+="</TABLE>";
	all+="</TD></TR></TABLE>";
	all+="</DIV>";
	document.writeln(all);
}


function menu_kill(temp_nr, evn) {
	if (!IE && !temp_nr && (evn.target.tagName=="TD" || evn.target.tagName=="A")) //for body
			return false; //panasiai kaip cancelBubble
	if (temp_nr>10) temp_nr=1;
	for (var i=temp_nr; i<=menu_nr; i++) {
		temp_obj = menu_arr[i];
		if (is_object(temp_obj)) {
			temp_obj.style.left="-1000px";
			menu_arr[i].last_tr.className="menu_tr";
		}
	}
	menu_nr=temp_nr; //sumaziname menu_nr, kad greiciau veiktu po to
}


function menu_out (tr_obj) {
	///2004-07-29
	if (is_object(menu_arr[menu_nr]))
		 menu_arr[menu_nr].last_tr=tr_obj; //nuoroda i paskutini pazymeta "tr"
	else
		 tr_obj.className="menu_tr";
}


function menu_click(temp_href) {
	window.document.location.href=temp_href;
}


function is_object(temp_obj) {
	return (temp_obj=="[object]" || temp_obj=="[object HTMLDivElement]");
}


//////// for resizing iframe height /////////
function adjustIFrameSize (iframeWindow) {
	if (iframeWindow.document.height) {
		var iframeElement = parent.document.getElementById(iframeWindow.name);
		iframeElement.style.height = iframeWindow.document.height + 'px';
//		iframeElement.style.width = iframeWindow.document.width + 'px';
	}
	else if (document.all) {
		var iframeElement = parent.document.all[iframeWindow.name];
		if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') {
			iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 3 + 'px';
//			iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
		}
		else {
			iframeElement.style.height = iframeWindow.document.body.scrollHeight + 3 + 'px';
//			iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
		}
  	}
}

/*
*   NEW IMAGE SHOWING AND POPUP METHODS
*   By Viacheslav and Marius 2008-03-05
*   Function openPopup may be used for other than showing image purposes
*   openPopup( opacity, background_color, html_code_of_popup );
*   opacity and background_color is for the surrounding area.
*   opacity must be a value from 0 to 100
*   background color is given as a CSS style (ex.: #FFFF00)
*   if no html code is given then only overlay will be visible
*/

/*
// REPEATED BLOCK BEGIN


function getBodyWidth() {
	if( (isFF || isNetscape || isIE7 || isOpera) && docType == "XHTML" )
        return document.documentElement.scrollWidth;
    return document.body.scrollWidth;
}
function getBodyHeight() {
	if( (isFF || isNetscape || isIE7 || isOpera) && docType == "XHTML" )
        return document.documentElement.scrollHeight;
    return document.body.scrollHeight;
}
function getScrollLeft() {
	if( !isIE )
	    return window.pageXOffset;
	return ( docType == "XHTML" )?document.body.parentNode.scrollLeft:document.body.scrollLeft;
}
function getScrollTop() {
	if( !isIE )
	    return window.pageYOffset;
	return ( docType == "XHTML" )?document.body.parentNode.scrollTop:document.body.scrollTop;
}
function getVisibleBodyWidth() {
	if( isOpera || docType != "XHTML" )
	    return document.body.clientWidth;
    return document.body.parentNode.clientWidth;
}
function getVisibleBodyHeight() {
	if( isOpera || docType != "XHTML" )
	    return document.body.clientHeight;
    return document.body.parentNode.clientHeight;
}
function getElementWidth( elm ) {
	return elm.offsetWidth;
}
function getElementHeight( elm ) {
	return elm.offsetHeight;
}
function getElementLeft( elm ) {
	var x = 0, p = elm;
	do x += p.offsetLeft; while(p = p.offsetParent);
	return x;
}
function getElementTop( elm ) {
	var y = 0, p = elm;
	do y += p.offsetTop; while(p = p.offsetParent);
	return y;
}
function mouseX(e) {
	return e.pageX?e.pageX:(e.clientX + getScrollLeft()) - ((isIE && !isOpera)?2:0);
}
function mouseY(e) {
	return e.pageY?e.pageY:(e.clientY + getScrollTop()) - ((isIE && !isOpera)?2:0);
}

var CurrentPopup = null;
var InnerPopupBlock = null;
var SizingTimer = null;
var OriginalWidth = 0;
var OriginalHeight = 0;

function checkPopup() {
	var width, height, w1,w2,h1,h2;
	if( !CurrentPopup ) {
	    clearTimeout( SizingTimer );
	    return;
	}
	w1 = OriginalWidth;
	w2 = getVisibleBodyWidth();
	h1 = OriginalHeight;
	h2 = getVisibleBodyHeight();
	width = ((w1>w2)?w1:w2);
	height = ((h1>h2)?h1:h2);
	CurrentPopup.style.width = width + "px";
	CurrentPopup.style.height = height + "px";
	//CurrentPopup.style.background = CurrentPopup.setBG;
	
	InnerPopupBlock.style.display = "block";
	w1 = getElementWidth( InnerPopupBlock );
	h1 = getElementHeight( InnerPopupBlock );
	var x = (getScrollLeft() + ((w2-w1) / 2));
	var y = (getScrollTop() + ((h2-h1) / 2));
	InnerPopupBlock.style.left = x + "px";
	InnerPopupBlock.style.top = y + "px";
	
	var dst = 2;
	var dvs = CurrentPopup.getElementsByTagName("div");
	dvs[0].style.left = 0; dvs[0].style.top = 0;
	dvs[0].style.width = x - dst; dvs[0].style.height = height;
	dvs[1].style.left = x + w1 + dst; dvs[1].style.top = 0;
	dvs[1].style.width = width - (x + w1) - dst; dvs[1].style.height = height;
	dvs[2].style.left = x - dst; dvs[2].style.top = 0;
	dvs[2].style.width = w1 + dst*2; dvs[2].style.height = y - dst;
	dvs[3].style.left = x - dst; dvs[3].style.top = y + h1 + dst;
	dvs[3].style.width = w1 + dst*2; dvs[3].style.height = height - (y + h1) - dst;
	
	dvs[4].style.left = x - dst; dvs[4].style.top = y - dst;
	dvs[4].style.width = w1 + dst*2; dvs[4].style.height = h1 + dst*2;
	
	for (var i = 0; i < dvs.length; i++) {
		if (i < (dvs.length - 1)) {
			dvs[i].style.background = CurrentPopup.setBG;
		} else {
			dvs[i].style.backgroundColor = "#ffffff";
		}
	}
	
}

function closePopup() {
	if( !CurrentPopup )
	    return;
    clearTimeout( SizingTimer );
    SizingTimer = null;
	if( InnerPopupBlock.parentNode )
		InnerPopupBlock.parentNode.removeChild( InnerPopupBlock );
	if( CurrentPopup.parentNode )
		CurrentPopup.parentNode.removeChild( CurrentPopup );
	delete InnerPopupBlock;
	delete CurrentPopup;
	InnerPopupBlock = CurrentPopup = null;
	if( window.event ) {
    	window.event.cancelBubble = true;
    	window.event.returnValue = false;
	}
    return false;
}

function openPopup( opacity, bg, html, center_noclick, surrounding_noclick ) {
	var div, div2, width, height, w1,w2,h1,h2;
	if( CurrentPopup )
	    closePopup();

	div = document.createElement( "DIV" );
	div.style.zIndex = "100000";
	div.style.position = "absolute";
	div.style.left = "0";
	div.style.top = "0";
	//div.style.visibility = "hidden";
	w1 = OriginalWidth = getBodyWidth();
	w2 = getVisibleBodyWidth();
	h1 = OriginalHeight = getBodyHeight();
	h2 = getVisibleBodyHeight();
	width = ((w1>w2)?w1:w2);
	height = ((h1>h2)?h1:h2);
	div.style.width = width + "px";
	div.style.height = height + "px";
	// ---------------------------------
	var dv = new Array(
		document.createElement("div"),
		document.createElement("div"),
		document.createElement("div"),
		document.createElement("div"),
		document.createElement("div")
	);
	for (var i = 0; i < dv.length; i++) {
		if (i < (dv.length - 1)) {
			if (IE && !O)
			    dv[i].style.filter = "alpha(opacity=" + opacity + ")";
			else
				dv[i].style.opacity = Math.floor(opacity) / 100;
		}
		dv[i].style.position = "absolute";
		dv[i].style.left = "0";
		dv[i].style.top = "0";
		div.appendChild(dv[i]);
	}
	// ---------------------------------

	//if( IE && !O )
	//    div.style.filter = "alpha(opacity=" + opacity + ")";
	//else
	//    div.style.opacity = Math.floor(opacity) / 100.0;

		div.setBG = bg;
	if( !surrounding_noclick ) {
		div.style.cursor = "pointer";
		div.onclick = closePopup;
	}

	div2 = document.createElement( "DIV" );
	div2.innerHTML = html;
	div2.style.position = "absolute";
	div2.style.zIndex = "100001";
	div2.style.display = "none";
	div2.style.left = "-10000px";
	div2.style.top = "-10000px";
	if( !center_noclick ) {
		div2.style.cursor = "pointer";
		div2.onclick = closePopup;
	}

	InnerPopupBlock = div2;
	CurrentPopup = div;
	document.body.appendChild( div );
	document.body.appendChild( div2 );
	SizingTimer = setInterval( "checkPopup();", 50 );
	
}

function popupImage( src, w, h, opacity, bg, do_start ) {
	var img;
	if( !opacity ) opacity = 50;
	if( !bg ) bg = "black";
	if( !do_start ) {
		openPopup( opacity, bg, "<div style='position:relative; background:white; width:42px; height:42px;'><div style='position:relative; padding:5px;'><img src=\"images/loading.gif\" width=\"32\" height=\"32\" /></div></div>" );
		setTimeout( "popupImage( '" + src + "', " + w + ", " + h + ", " + opacity + ", '" + bg + "', true );", 10 );
	} else {
	    img = new Image();
		img.doWidth = w;
		img.doHeight = h;
		img.onload = function() {
		    var w, h;
		    if( !InnerPopupBlock )
		        return;
		    if( !this.doWidth ) this.doWidth = this.width;
		    if( !this.doHeight ) this.doHeight = this.height;
		    InnerPopupBlock.style.display = "none";
   		    InnerPopupBlock.innerHTML = "<div style='position:relative; background:white; width:" + (this.doWidth+10) + "px; height:" + (this.doHeight+10) + "px;'><div style='position:relative; padding:5px;'><img src=\"" + this.src + "\" width=\"" + this.doWidth + "\" height=\"" + this.doHeight + "\" /></div></div>";
		}
	    img.src = src;
	}
	if( window.event ) {
    	window.event.cancelBubble = true;
    	window.event.returnValue = false;
	}
    return false;
}

// REPEATED BLOCK END
*/

function previewFlash(url, v_width, v_height) {
	if (!v_width) v_width = 425;
	if (!v_height) v_height = 344;
	var code = '' +
		'<div style="border: 8px solid #ffffff; position: relative; z-index: 100009; background-color: #ffffff;">' +
		'<object id="preview_flash" name="youtube_player" type="application/x-shockwave-flash" data="' + url + '" ' +
			' style="position: relative; background-color: #ffffff; z-index: 100010;" width="'+v_width+'" height="'+v_height+'">' +
			'<param name="movie" value="' + url + '"></param>' +
			'<param name="allowFullScreen" value="true"></param>' +
		'</object>' +
		'</div>' +
		'';
	openPopup(30, '#000', code, true, false);
	var t = setTimeout("activateYouTubeIE('preview_flash')", 1000);
	return false;
}

function previewVideo(video_url, v_width, v_height, lng ) {
	return previewFlash( "images/video_player.swf?lng="+lng+"&vid="+escape(video_url)+"&vidimg=&autoplay=1", v_width, v_height );
}


function previewYouTube(id, v_width, v_height, v_lang, v_title) {
	//YjHanM9tPvQ
	if (!v_lang) v_lang = "en";
	if (!v_width) v_width = 480; else v_width = v_width*1;
	if (!v_height) v_height = 385; else v_height = v_height*1;
	if ((!v_title) || (v_title=="false") || (v_title=="true")) v_title = "Youtube video";
	var url = 'http://www.youtube.com/v/' + id + '&hl='+v_lang+'&fs=1&rel=0';
/*	var code = '' +
		//'<table><tr><td></td><td><img src="images/youtube_close.png" onclick="closePopup"></td></tr><tr><td>' +
		'<div onclick="closePopup()" style="position:relative; left:496px; cursor:pointer"><img src="images/youtube_close.png"></div>' +
		'<div style="border: 8px solid #ffffff; position: relative; z-index: 100009; background-color: #ffffff;">' +
		'<object id="youtube_player" name="youtube_player" type="application/x-shockwave-flash" data="' + url + '" ' +
			' style="position: relative; background-color: #ffffff; z-index: 100010;" width="'+v_width+'" height="'+v_height+'">' +
			'<param name="movie" value="' + url + '"></param>' +
			'<param name="allowFullScreen" value="true"></param>' +
		'</object>' +
		'</div>' +
		//'</td><td></td></tr></table>';
		'';*/
	var code =
		'<div style="position: relative; z-index: 100009; background-color: #ffffff; display:block; width:'+(v_width+16)+'; height:'+(v_height+40)+'">' +
		'<div style="padding:8px;">' +
		'<img src="images/youtube_close.png" onClick="closePopup()" style="cursor:pointer; float:right; margin-bottom:8px;">' +
		'<div style="text-align:center;"><a href="http://www.youtube.com/watch?v='+id+'&fmt=18" target="_blank" style="font:12px Tahoma;">'+v_title+'</a></div>' +
		'<object id="youtube_player" name="youtube_player" type="application/x-shockwave-flash" data="' + url + '" ' +
			' style="position: relative; background-color: #ffffff; z-index: 100010;" width="'+v_width+'" height="'+v_height+'">' +
			'<param name="movie" value="' + url + '"></param>' +
			'<param name="allowFullScreen" value="true"></param>' +
		'</object>' +
		'</div>' +
		'</div>';
	if (IE)
		openPopup(100, '#888', code, true, false);
	else
		openPopup(30, '#000', code, true, false);
	var t = setTimeout("activateYouTubeIE('"+id+"')", 1000);
	return false;
}

function activateYouTubeIE(id) {
	var ytp = document.getElementById('youtube_player');
	if (ytp) {
		ytp.focus();
		//ytp.SetVariable("setVideoQuality", 2);
	}
}

/*
*   NEW IMAGE SHOWING AND POPUP METHODS
*   By Viacheslav 2008-03-05
*   Function openPopup may be used for other than showing image purposes
*   openPopup( opacity, background_color, html_code_of_popup );
*   opacity and background_color is for the surrounding area.
*   opacity must be a value from 0 to 100
*   background color is given as a CSS style (ex.: #FFFF00)
*   if no html code is given then only overlay will be visible
*/
function getBodyWidth() {
	if( (isFF || isNetscape || isIE7 || isOpera) && docType == "XHTML" )
        return document.documentElement.scrollWidth;
    return document.body.scrollWidth;
}
function getBodyHeight() {
	if( (isFF || isNetscape || isIE7 || isOpera) && docType == "XHTML" )
        return document.documentElement.scrollHeight;
    return document.body.scrollHeight;
}
function getScrollLeft() {
	if( !isIE )
	    return window.pageXOffset;
	return ( docType == "XHTML" )?document.body.parentNode.scrollLeft:document.body.scrollLeft;
}
function getScrollTop() {
	if( !isIE )
	    return window.pageYOffset;
	return ( docType == "XHTML" )?document.body.parentNode.scrollTop:document.body.scrollTop;
}
function getVisibleBodyWidth() {
	if( isOpera || docType != "XHTML" )
	    return document.body.clientWidth;
    return document.body.parentNode.clientWidth;
}
function getVisibleBodyHeight() {
	if( isOpera || docType != "XHTML" )
	    return document.body.clientHeight;
    return document.body.parentNode.clientHeight;
}
function getElementWidth( elm ) {
	return elm.offsetWidth;
}
function getElementHeight( elm ) {
	return elm.offsetHeight;
}
function getElementLeft( elm ) {
	var x = 0, p = elm;
	do x += p.offsetLeft; while(p = p.offsetParent);
	return x;
}
function getElementTop( elm ) {
	var y = 0, p = elm;
	do y += p.offsetTop; while(p = p.offsetParent);
	return y;
}
function mouseX(e) {
	return e.pageX?e.pageX:(e.clientX + getScrollLeft()) - ((isIE && !isOpera)?2:0);
}
function mouseY(e) {
	return e.pageY?e.pageY:(e.clientY + getScrollTop()) - ((isIE && !isOpera)?2:0);
}

var CurrentPopup = null;
var InnerPopupBlock = null;
var SizingTimer = null;
var OriginalWidth = 0;
var OriginalHeight = 0;

function checkPopup() {
	var width, height, w1,w2,h1,h2;
	if( !CurrentPopup ) {
	    clearTimeout( SizingTimer );
	    return;
	}
	w1 = OriginalWidth;
	w2 = getVisibleBodyWidth();
	h1 = OriginalHeight;
	h2 = getVisibleBodyHeight();
	width = ((w1>w2)?w1:w2);
	height = ((h1>h2)?h1:h2);
	CurrentPopup.style.width = width + "px";
	CurrentPopup.style.height = height + "px";
	CurrentPopup.style.background = CurrentPopup.setBG;

	InnerPopupBlock.style.display = "block";
	w1 = getElementWidth( InnerPopupBlock );
	h1 = getElementHeight( InnerPopupBlock );
	InnerPopupBlock.style.left = (getScrollLeft() + ((w2-w1) / 2)) + "px";
	InnerPopupBlock.style.top = (getScrollTop() + ((h2-h1) / 2)) + "px";
}

function closePopup() {
	if( !CurrentPopup )
	    return;
    clearTimeout( SizingTimer );
    SizingTimer = null;
	if( InnerPopupBlock.parentNode )
		InnerPopupBlock.parentNode.removeChild( InnerPopupBlock );
	if( CurrentPopup.parentNode )
		CurrentPopup.parentNode.removeChild( CurrentPopup );
	delete InnerPopupBlock;
	delete CurrentPopup;
	InnerPopupBlock = CurrentPopup = null;
	if( window.event ) {
    	window.event.cancelBubble = true;
    	window.event.returnValue = false;
	}
    return false;
}

function openPopup( opacity, bg, html, center_noclick, surrounding_noclick ) {
	var div, div2, width, height, w1,w2,h1,h2;
	if( CurrentPopup )
	    closePopup();

	div = document.createElement( "DIV" );
	div.style.zIndex = "100000";
	div.style.position = "absolute";
	div.style.left = "0";
	div.style.top = "0";
	w1 = OriginalWidth = getBodyWidth();
	w2 = getVisibleBodyWidth();
	h1 = OriginalHeight = getBodyHeight();
	h2 = getVisibleBodyHeight();
	width = ((w1>w2)?w1:w2);
	height = ((h1>h2)?h1:h2);
	div.style.width = width + "px";
	div.style.height = height + "px";
	if( IE && !O )
	    div.style.filter = "alpha(opacity=" + opacity + ")";
	else
		div.style.opacity = Math.floor(opacity) / 100.0;
	div.setBG = bg;
	if( !surrounding_noclick ) {
		div.style.cursor = "pointer";
		div.onclick = closePopup;
	}

	div2 = document.createElement( "DIV" );
	div2.innerHTML = html;
	div2.style.position = "absolute";
	div2.style.zIndex = "100001";
	div2.style.display = "none";
	div2.style.left = "-10000px";
	div2.style.top = "-10000px";
	if( !center_noclick ) {
		div2.style.cursor = "pointer";
		div2.onclick = closePopup;
	}

	InnerPopupBlock = div2;
	CurrentPopup = div;
	document.body.appendChild( div );
	document.body.appendChild( div2 );
	SizingTimer = setInterval( "checkPopup();", 50 );
}

function popupImage( src, w, h, opacity, bg, do_start ) {
	var img;
	if( !opacity ) opacity = 50;
	if( !bg ) bg = "black";
	if( !do_start ) {
		openPopup( opacity, bg, "<div style='position:relative; background:white; width:42px; height:42px;'><div style='position:relative; padding:5px;'><img src=\"images/loading.gif\" width=\"32\" height=\"32\" /></div></div>" );
		setTimeout( "popupImage( '" + src + "', " + w + ", " + h + ", " + opacity + ", '" + bg + "', true );", 10 );
	} else {
	    img = new Image();
		img.doWidth = w;
		img.doHeight = h;
		img.onload = function() {
		    var w, h;
		    if( !InnerPopupBlock )
		        return;
		    if( !this.doWidth ) this.doWidth = this.width;
		    if( !this.doHeight ) this.doHeight = this.height;
		    InnerPopupBlock.style.display = "none";
   		    InnerPopupBlock.innerHTML = "<div style='position:relative; background:white; width:" + (this.doWidth+10) + "px; height:" + (this.doHeight+10) + "px;'><div style='position:relative; padding:5px;'><img src=\"" + this.src + "\" width=\"" + this.doWidth + "\" height=\"" + this.doHeight + "\" /></div></div>";
		}
	    img.src = src;
	}
	if( window.event ) {
    	window.event.cancelBubble = true;
    	window.event.returnValue = false;
	}
    return false;
}

var PositionTimer = null;
var bannerRepositionInProgress = false;
function repositionBanner() {
	if (bannerRepositionInProgress) return false;
	bannerRepositionInProgress = true
	var bnr = document.getElementById( "bfbnr" );
	if( !bnr )
	    return;
	var ew = getElementWidth( bnr );
	var eh = getElementHeight( bnr );
	var bw = getVisibleBodyWidth();
	var bh = getVisibleBodyHeight();
	var x = (bw - ew) / 2;
	var y = bh - eh;
	bnr.style.position = "absolute";
	bnr.style.width = bw + "px";
	bnr.style.left = getScrollLeft() + "px";
	bnr.style.top = (getScrollTop() + y) + "px";
	var bno = document.getElementById( "bbo" );
	if( bno )
		bno.style.width = bw + "px";
	bannerRepositionInProgress = false;
	if (!PositionTimer) {
		PositionTimer = setInterval( "repositionBanner();", 50 );
	}
}

function repositionBanner2() {
	var bnr = document.getElementById("bfbnr");
	if (!bnr) return;
	bnr.style.top = (getVisibleBodyHeight() - 150) + "px";
	bnr.style.width = getVisibleBodyWidth();
	bnr.style.height = "150px";
}

function getPosition(e) {
	var e = (!e) ? window.event : e;
	var cursor = {x:0, y:0};
	if (typeof(e.pageX)!="undefined" || typeof(e.pageY)!="undefined") {
		cursor.x = e.pageX + window.pageXOffset;
		cursor.y = e.pageY + window.pageYOffset;
	} 
	else if (typeof(e.clientX)!="undefined") {
		var de = document.documentElement;
		var b = document.body;
		cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
		cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	}
	return cursor;
}

var cnt = [];
var im = [];
function next_pic(proj_id, e) {
	posX = getElementLeft(document.getElementById('preview_'+proj_id));
	var coord = getPosition(e);
	var x = Math.abs(coord.x-posX);
	var section = Math.floor(x / (330/cnt[proj_id]));
	return section;
}
