/*
setImage - funkcja podmieniajaca obrazek na inny   np. po najechaniu na niego myszka
wywołanie: <img src="/images/menu/1_test.jpg" name="test"  onmouseover="setImage(this.name,'/images/menu/2_test.jpg')" onmouseout="setImage(this.name,'/images/menu/1_test.jpg')" />
docName - parametr 'name' elementu 'img'
filePath - ścieżka do nowego pliku  (np.: /images/menu/obrazek.jpg)
*/
function setImage(docName,filePath)
{
	eval("document."+docName+".src =\""+filePath+"\"");
}
/*********************************************************************************************/
function setImage2(docName,filePath)
{
	eval("form."+docName+".src =\""+filePath+"\"");
}
/*********************************************************************************************/
function setImage_menu(docID,filePath)
{
	eval("document.getElementById(\"+docID+\").src=\""+filePath+"\"");
}

/**************************************** galeria - portfolio ***************************************/
var photos=new Array();
var urls=new Array();
var titles=new Array();
var which=0;
var katalog;

katalog="/portfolio/images/";
photos[0]=katalog+"neuralnets.png";		urls[0]="http://neuralnets.eu";				titles[0]="www.neuralnets.eu";
photos[1]=katalog+"pro-creative.png";	urls[1]="http://www.pro-creative.pl/";		titles[1]="www.pro-creative.pl";
photos[2]=katalog+"uj_centrum.png";		urls[2]="http://www.uj.edu.pl/Polonia";		titles[2]="www.uj.edu.pl/Polonia";
photos[3]=katalog+"uj_sl.png";			urls[3]="http://www.uj.edu.pl/SL";			titles[3]="www.uj.edu.pl/SL";
photos[4]=katalog+"artneon.png";		urls[4]="http://www.artneon.pl";			titles[4]="www.artneon.pl";


function backward(){
	if ((which>0) && (which<photos.length-1)){
		which--
		document.images.photo1.src=photos[which]
		document.images.photo2.src=photos[which+1]
		document.images.photoView.src=photos[which+1]
		document.images.photo3.src=photos[which+2]

		document.images.photoView.alt=urls[which+1]
		document.getElementById('photoText').innerHTML=titles[which+1]
	}
	else if (which==0){
		which=photos.length-1
		document.images.photo1.src=photos[which]
		document.images.photo2.src=photos[0]
		document.images.photoView.src=photos[0]
		document.images.photo3.src=photos[1]

		document.images.photoView.alt=urls[0]
		document.getElementById('photoText').innerHTML=titles[0]
	}
	else if (which==photos.length-1){
		which=photos.length-2
		document.images.photo1.src=photos[which]
		document.images.photo2.src=photos[which+1]
		document.images.photoView.src=photos[which+1]
		document.images.photo3.src=photos[0]

		document.images.photoView.alt=urls[which+1]
		document.getElementById('photoText').innerHTML=titles[which+1]
	}
}

function forward(){
	if (which<photos.length-3){
		which++
		document.images.photo1.src=photos[which]
		document.images.photo2.src=photos[which+1]
		document.images.photoView.src=photos[which+1]
		document.images.photo3.src=photos[which+2]

		document.images.photoView.alt=urls[which+1]
		document.getElementById('photoText').innerHTML=titles[which+1]
	}
	else if (which==photos.length-3){
		which++
		document.images.photo1.src=photos[which]
		document.images.photo2.src=photos[which+1]
		document.images.photoView.src=photos[which+1]
		document.images.photo3.src=photos[0]

		document.images.photoView.alt=urls[which+1]
		document.getElementById('photoText').innerHTML=titles[which+1]
	}
	else if (which==photos.length-2){
		which++
		document.images.photo1.src=photos[which]
		document.images.photo2.src=photos[0]
		document.images.photoView.src=photos[0]
		document.images.photo3.src=photos[1]

		document.images.photoView.alt=urls[0]
		document.getElementById('photoText').innerHTML=titles[0]
	}
	else if (which==photos.length-1){
		which=0
		document.images.photo1.src=photos[0]
		document.images.photo2.src=photos[1]
		document.images.photoView.src=photos[1]
		document.images.photo3.src=photos[2]

		document.images.photoView.alt=urls[1]
		document.getElementById('photoText').innerHTML=titles[1]
	}
}

function setPhoto(photo){
	document.images.photoView.src=photo
}
/*********************************************************************************************/
function getSelection(ta)
{

	var bits = [ta.value,'','',''];
    if(document.selection)
    {
		var vs = '#$%^%$#';
        var tr=document.selection.createRange();
        if(tr.parentElement()!=ta) return null;
        bits[2] = tr.text;
        tr.text = vs;
        fb = ta.value.split(vs);
        tr.moveStart('character',-vs.length);
        tr.text = bits[2];
        bits[1] = fb[0];
        bits[3] = fb[1];
      }
    else
      {

	  if(ta.selectionStart == ta.selectionEnd) { return null; }
		bits=(new RegExp('([^]{'+ta.selectionStart+'})([^]{'+(ta.selectionEnd - ta.selectionStart)+'})([^]*)')).exec(ta.value);
		//alert(bits[0]+"|||||"+bits[1]+"|||||"+bits[2]+"|||||"+bits[3]);
      }
     return bits;
}

function matchPTags(str)
{
	str = ' ' + str + ' ';
    ot = str.split(/\[[B|U|I].*?\]/i);
    ct = str.split(/\[\/[B|U|I].*?\]/i);
    return ot.length==ct.length;
}

function addPTag(ta,pTag)
{

	bits = getSelection(ta);
	if(bits)	// gdy zaznaczono tekst
	{
		if(!matchPTags(bits[2]))
	    {
			alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
	        return;
	    }

		if(pTag == '|' || pTag == 'Space' || pTag == 'BR')
		{
			ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '' + bits[3];
		}
		else if(pTag!='A')
		{
			ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
		}
		else   //dla linków:
		{
			var href=prompt("Podaj adres strony:","http://");
			if (href!=null && href!="" && href!="http://")
			{
				ta.value = bits[1] + '[A href="' + href + '"]' + bits[2] + '[/A]' + bits[3];
			}
		}
	}
	else	//gdy brak zaznaczenia
	{
		var bits = [ta.value,'','',''];
	    if(document.selection)
	    {
			ta.focus();
			var tr=document.selection.createRange();

		}
		else
		{
			bits=(new RegExp('([^]{'+ta.selectionStart+'})([^]{'+(ta.selectionEnd - ta.selectionStart)+'})([^]*)')).exec(ta.value);
		}

		if(pTag == '|' || pTag == 'Space' || pTag == 'BR')
		{
			if(document.selection)
			{
				tr.text =  '[' + pTag + ']';
			}
			else
			{
				ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '' + bits[3];
			}
		}
		else if(pTag!='A')
		{
			if(document.selection)
			{
				tr.text =  '[' + pTag + ']' + '[/' + pTag + ']';
			}
			else
			{
				ta.value = bits[1] + '[' + pTag + ']' + bits[2] + '[/' + pTag + ']' + bits[3];
			}
		}
		else 	//dla linków:
		{
			var href=prompt("Podaj adres strony:","http://");
			if (href!=null && href!="" && href!="http://")
			{
				var anchor=prompt("Opis linku:","");
				if (anchor!=null && anchor!="")
				{
					if(document.selection)
					{
						tr.text =  '[A href="' + href + '"]' + anchor + '[/A]' ;
					}
					else
					{
						ta.value = bits[1] + '[A href="' + href + '"]' + anchor + '[/A]' + bits[3];
					}
				}
			}
		}

	}

}
/*********************************************************************************************/
function displayImage(url,title,opcje_w,opcje_h)
{
	var centerWidth = (window.screen.width - opcje_w) / 2;
    var centerHeight = (window.screen.height - opcje_h) / 2;

	noweOkno = window.open( url , title,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+ opcje_w +', height='+ opcje_h + ',left=' + centerWidth + ',top=' + centerHeight);
}
/*********************************************************************************************/
function openNewWindow(url,title,opcje_w,opcje_h)
{
	var centerWidth = (window.screen.width - opcje_w) / 2;
    var centerHeight = (window.screen.height - opcje_h) / 2;

	noweOkno = window.open(url,title,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+ opcje_w +', height='+ opcje_h + ',left=' + centerWidth + ',top=' + centerHeight);
}
/*********************************************************************************************/
// sprawdzenie wypelnienia wszystkich pol formularza
function sprawdz(formularz)
{
	   for (i = 0; i < formularz.length; i++)
       {
              var pole = formularz.elements[i];
              if ((pole.type == "text" || pole.type == "password" || pole.type == "textarea" ) && pole.value == "")
              {
					alert("Proszę wypełnić wszystkie pola formularza.");
					return false;
              }
       }
       return true;
}
/*********************************************************************************************/
/*********************************************************************************************/
function scrollTop() {
	if (window.pageYOffset != undefined) return window.pageYOffset;
	if (document.documentElement.scrollTop != undefined) return document.documentElement.scrollTop;
	if (document.body.scrollTop != undefined) return document.body.scrollTop;
	return 0;
}

function show(what) {

	//document.getElementById('big_img').src = '../img/loading.gif';
	//document.getElementById('img_desc').innerHTML = 'Wczytywanie...';
	document.getElementById('img_div').style.display='block';
	document.getElementById('img_div').style.top = scrollTop() + 100 + 'px';

	var img = new Image;
	img.onload = document.getElementById('big_img').src = what;
}

function hide() {
	document.getElementById('img_div').style.display='none';
}
/*********************************************************************************************/
/************** GOOGLE MAPS ***************************************************************/

function createMarker(point, number) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(number);});
return marker;
}

function initialize() {
	map = new GMap2(document.getElementById("google_map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl(G_NORMAL_MAP,G_SATELLITE_MAP));
	map.setCenter(new GLatLng(50.080993,19.956107), 14);

var point = new GLatLng(50.081693,19.954107);
map.addOverlay(createMarker(point, '<b>BobSTUDIO</b><br />Pracownia Architektoniczna<br />biuro@bobstudio.eu<br />tel. 880 953 861'));

map.setMapType(G_MAP_TYPE);
}

/********************************************************************************************/
