var add_path_pl = '/mod/gui/koszyk_projekt.gif';
var add_path1_pl = '/mod/gui/koszyk_projekt_1.gif';
var add_path2 = '/mod/gui/koszyk_projekt_2.gif';
var del_path_pl ='/mod/gui/koszyk_usun.gif';
var del_path1_pl = '/mod/gui/koszyk_usun_1.gif';

var add_path_eng = '/mod/gui/koszyk_projekt_eng.gif';
var add_path1_eng = '/mod/gui/koszyk_projekt_1_eng.gif';
var del_path_eng ='/mod/gui/koszyk_usun_eng.gif';
var del_path1_eng = '/mod/gui/koszyk_usun_1_eng.gif';

var lynx_d = {};
lynx_d.has = function(x){return this[x]!=undefined};

function toggle_adv_search(sh,hd){
	//alert('toggle');
	if(document.all)var mode = 'inline';
	else var mode = 'table-row-group';
	var decision = (document.getElementById("adv_search").style.display=='none')?mode:'none';
	document.getElementById("adv_search").style.display = decision;
	document.getElementById("adv_search_butt").value = ((decision=='none')?sh:hd);
}

function show_gal_page(page){
  
	new LynxRequest({url:'/index.php',catBack:true,returnCall:refresh_gal_page,
		params:{mode:'dynamic',callFunc:'get_staff_table',gal_page:page}});
}

function refresh_gal_page(args){
  // mod by Piotr Szymaniak
	//replaceElement($j('#gal_table')[0],args);

  $j('#gal_table').html(args);
	//alert($j('#gal_table').html());
}

function show_fav_page(page,sort){
	if(sort==undefined)sort='';
	new LynxRequest({url:'/index.php',catBack:true,returnCall:refresh_fav_page,
		params:{mode:'dynamic',callFunc:'get_fav_table',fav_page:page,fsort:sort}});
}

function refresh_fav_page(args,jsPar,serverPar){
	$j('#fav_dial').val(serverPar[0]);
	//replaceElement($j('#fav_table')[0],args);
	//alert(args);
	
	
	
	$j('#fav_table').html(args);
}

function add_to_favs(uid,oid,butt,lang){
	new LynxRequest({url:'/index.php', params:{mode:'dynamic', callFunc:'user_add_fav', uid:uid, oid:oid},
		returnCall:fav_add_row, jsParams:[uid]});
	
	butt.src=add_path2;
	butt.onmouseover = butt.onmouseout = butt.onclick = null;
	
	new LynxRequest({url:'/index.php',catBack:true,returnCall:refresh_fav_page,
		params:{mode:'dynamic',callFunc:'get_fav_table',fav_page:'0',fsort:''}});
		
}

function traverse(tree) {
    if(tree.hasChildNodes()) {
        document.write('<ul><li>');
        document.write('<b>'+tree.tagName+' : </b>');
        var nodes=tree.childNodes.length;
        for(var i=0; i<tree.childNodes.length; i++)
            traverse(tree.childNodes(i));
        document.write('</li></ul>');
    }
    else
        document.write(tree.text);
}

function initTraverse(file) {
    loadXML(file);
    var doc=xmlDoc.documentElement;
    traverse(doc);
}

function fav_add_row(xml, jsPar){
  //alert(xml);
	if(!lynx_d.has('lang'))lynx_d.lang = $TV(xml,'_lang');
	var person = $T(xml,'person');
	if(person.length>0)fav_render_row(person[0],jsPar[0],true);
	
	
	var del = $TV(xml,'to_delete');
	if(del.length>0)$j('#pfav'+del).remove();
	var page_link = $T(xml,'page_link');
	if(page_link.length>0)add_page_link(page_link[0]);
	$j('#fav_dial').val($j('count',xml).text());
	//alert($j('#fav_dial').val());
}

function remove_from_favs(uid,oid,loc,lang){
	var lr = new LynxRequest('/index.php');
	lr.addParams([
	['mode','dynamic'],['callFunc','user_remove_fav'],['uid',uid],['oid',oid]
	]);
	if(loc==false){
		lr.returnCall = fav_remove_row;
		lr.addJsParams(oid,uid);
		lr.makeRequest();
		var butt = document.getElementById('oid'+oid);
		if(!butt || !butt.tagName)return;
		var tmp = $T(butt,'img');
		butt = tmp[tmp.length-1];
		if(lang=='pl'){
			butt.onmouseover = function(){butt.src=add_path1_pl;};
			butt.onmouseout = function(){butt.src=add_path_pl;};
			butt.src=add_path_pl;
		}else{
			butt.onmouseover = function(){butt.src=add_path1_eng;};
			butt.onmouseout = function(){butt.src=add_path_eng;};
			butt.src=add_path_eng;
			new LynxRequest({url:'/index.php',catBack:true,returnCall:refresh_fav_page,
		    params:{mode:'dynamic',callFunc:'get_fav_table',fav_page:'0',fsort:''}});
		}
		butt.onclick = function(){add_to_favs(uid,oid,butt);return false;};
	
	}else{
	   //alert(loc);
	  window.location.href =loc;
		lr.returnCall = function(){};
		lr.catBack = true;
		lr.makeRequest();
	}
}

function fav_remove_row(xml, jsPar){
	if(!lynx_d.has('lang'))lynx_d.lang = $j('_lang',xml).text();
	$j('#pfav'+jsPar[0]).remove();
	$j("person",xml).each(function(){fav_render_row(this,jsPar[1],false)});
	$j("page_link",xml).each(rem_page_link);
	$j('#fav_dial').val($j('count',xml).text());
}

function rem_page_link(){
	$j('#fav_table div.page_navig div.center a:last-child').remove();
}

function add_page_link(p_link){
	var cont=$j("content",p_link).text(),page=$j('page',p_link).text(),cls=$j('class',p_link).text();
	$j('#fav_table div.page_navig div.center a:last-child').after(
		$j("<a></a>").text(cont).click(show_fav_page.curry(page,'')).addClass(cls).attr('href','#')
	);
}

function fav_render_row(xml, uid, begin){//in remove set begin=false
	var pid = $TV(xml, 'id_osoba');
	var fid = $TV(xml, 'id_fav');
	var rezerwacja = $TV(xml,'rezerwacja');
	rezerwacja = rezerwacja.replace(/,/g,"<br />");
	var f1 = function(){document.location="/index.php?ac=staff&func=view&pid="+pid+"&gmode=1"};
	
	var td_lang = new Array();
	var langs = $T($T(xml,'langs')[0],'lang');
	for(var j=0,len=langs.length;j<len;j++){
		td_lang.push(makeElement({tag:'div',className:(j>0)?'d_lang':'',
			content:[$TV(langs[j],'name')],
			child:[makeElement({tag:'br'}),
				makeElement({tag:'img',src:'/mod/star_psp_s'+$TV(langs[j],'level')+'.gif'})]}));
	}
	var row1 = makeRow(
		{click:f1,child:[
			makeElement({tag:'img',src:'/index.php?ac=thumb&x=80&y=100&image_path=gfx/zdjecia/'+$TV(xml,'photo'),
			load:function(){lp.adjustHeight(1)}})]},
		{click:f1,content:[pid]},
		{click:f1,content:[$TV(xml,'imie'),'.....']},
		{click:f1,content:[rezerwacja]},
		{click:f1,content:[$TV(xml,'wiek')]},
		{click:f1,content:[$TV(xml,'wzrost'),' cm']},
		{click:f1,className:'td_lang',child:td_lang},
		{child:[makeElement(
			{tag:'img',src:$TV(xml,'del_path'),className:'c_func_butt',title:$TV(xml,'del_title'),
			click:function(){remove_from_favs(uid,pid,false,lynx_d.lang);return false},
			mouseover:function(){this.src=$TV(xml,'del_path1')},
			mouseout:function(){this.src=$TV(xml,'del_path')}})]});
	row1.style.cursor = 'pointer';
	row1.onmouseover=function(){this.style.backgroundColor="#f7d279"};
	row1.onmouseout=function(){this.style.backgroundColor="transparent"};
	
	var row2 = makeRow([{colspan:'8',child:[
		makeTable([
			makeRow(
				{className:'notes_desc',content:[(lynx_d.lang=='pl'?'Uwagi:':'Notes:')]},
				{className:'notes',content:[$TV(xml,'fav_uwagi')]},
				{className:'price_desc',content:[(lynx_d.lang=='pl'?'Cena:':'Net price:')]},
				{className:'price',content:[$TV(xml,'cena')]} ) ],{className:'modlist'} ) ]}]);
	
	var row3 = $j("<tr></tr>");
	
	var row4 = makeRow([{colspan:'9',child:[
		makeElement({tag:'hr',className:'line1'})]}]);
	
	var parent = $j('#fav_table > table:first');
	var to_insert = $j('<tbody id="pfav'+pid+'"></tbody>').append(row1).append(row2).append(row3).append(row4);
	var pos = $TV(xml,'position');
	if(pos.length>0)parent.find('> tbody:eq('+Number(pos)+')').after(to_insert);
	else if(begin==true)parent.find('> tbody:first').after(to_insert);
	else parent.append(to_insert);
}

function setFavDial(n){
	$j('#fav_dial').val(n);
}


var hld=null;
//@cc_on var sld_ie=1;

function show_lang_desc(opt){
	//alert("stf");
	var desc = document.getElementById('short_lang_desc');
	var prt = opt.parentNode;
	/*@cc_on
	if(desc.style.display!='none' && sld_ie!=1){
		hld_engine();
		return;
	}
	sld_ie=0;
	prt = opt;
	@*/
	if(hld!=null){window.clearTimeout(hld);hld=null;}
	var pos = getAbsPos(prt);
	desc.style.top = pos[1];
	desc.style.left = pos[0] - 210;
	/*@cc_on
	desc.style.top = pos[1] - 300;
	desc.style.left = pos[0] - 530;
	@*/
	//alert(pos[0]+' '+pos[1]+' '+prt.tagName);
	desc.style.display = 'block';
}

function hide_lang_desc(){
	if(document.all)return;
	hld = window.setTimeout(hld_engine,500);
}

function hld_engine(){
	var desc = document.getElementById('short_lang_desc');
	desc.style.display = 'none';
}

//******************************************************88
//*********************************************************

function search_switch(butt){
	if(butt==undefined)butt = $('shbutton');
	if(butt.src.match('/mod/gui/wyszukaj42.gif')!=null){
		butt.src = '/mod/gui/wyszukaj4.gif';
		butt.onmouseover = function(){butt.src = '/mod/gui/wyszukaj4over.gif'};
		butt.onmouseout = function(){butt.src = '/mod/gui/wyszukaj4.gif'};
	}else{
		butt.src = '/mod/gui/wyszukaj42.gif';
		butt.onmouseover = function(){butt.src = '/mod/gui/wyszukaj42over.gif'};
		butt.onmouseout = function(){butt.src = '/mod/gui/wyszukaj42.gif' };
	}
}

var StaffData = {
	showEduInfo: false
};

$j(function(){
	$j("input.edu-info").livequery('click',function(){
		$j("tr.edu-row").toggle();
		StaffData.showEduInfo = !StaffData.showEduInfo;
	});
	$j("tr.edu-row").livequery(function(){
		if(StaffData.showEduInfo)$j(this).show();
	});
	$j('#dbg_form input[@name=imie]').tooltip({track:true,bodyHandler:function(){return 'test'}});
});



function rezerwacje_hostessy_click(){
  $('#hostessa_rezerwacje').show();
  $('#rezerwacje_hostessy').addClass('active');
  $('#hostessa_opinie').hide();
  $('#opinie_hostessy').removeClass('active');
  $('#hostessa_informacje').hide();
  $('#informacje_hostessy').removeClass('active'); 
  $('#hostessa_informacje_cart').hide();
  $('#informacje_hostessy_cart').removeClass('active'); 
}

function opinie_hostessy_click(){
  $('#hostessa_rezerwacje').hide();
  $('#hostessa_opinie').show();
  $('#hostessa_informacje').hide();
  $('#hostessa_informacje_cart').hide();
  $('#opinie_hostessy').addClass('active');
  $('#informacje_hostessy').removeClass('active');
  $('#informacje_hostessy_cart').removeClass('active');
  $('#rezerwacje_hostessy').removeClass('active');
}

function informacje_hostessy_click(){
  $('#hostessa_rezerwacje').hide();
  $('#hostessa_opinie').hide();
  $('#hostessa_informacje').show();
  $('#hostessa_informacje_cart').show();
  $('#informacje_hostessy').addClass('active');
  $('#informacje_hostessy_cart').addClass('active');
  $('#opinie_hostessy').removeClass('active');
  $('#rezerwacje_hostessy').removeClass('active');
}






 /*
hostessy_picture_viewer
head_picture
picture_list
picture
 */
  



jQuery(document).ready(function($){
  $('#hostessy_picture_viewer .picture_list .picture').click(function(){
    var gid = $(this).attr('gid');
    var width = $(this).attr('widthp');
    var height = $(this).attr('heightp');
    $('#hostessy_picture_viewer .head_picture img').css('width', width+'px').css('height', height+'px');
    $('#hostessy_picture_viewer .head_picture').css('background', gid + ' center no-repeat');
    $('#hostessy_picture_viewer .head_picture a').attr('href', gid.replace('280', '560').replace('400', '800').replace('url(\'', '').replace('\')', ''));
    
  });
  
  
  
  
  
  
  jQuery(".hostessa_o_mnie").corner("8px");
  jQuery(".hostessa_o_mnie_bg").corner("8px");
  
  var status_miniature=false;
  
  
  
  
  $('.hostessa_miniature').hover(
  function (e) {
     if(status_miniature) $('.miniatura_preview').remove();
     $(this).parent().css('position', 'relative');
     var src=$(this).attr('src').replace("96", "160").replace("120", "200");
     $(this).parent().append('<div class="miniatura_preview"><img src="'+src+'"/></div>');
        
  },
  function () {

    if(!status_miniature) $('.miniatura_preview').remove();
      
  });
  
  

  
  
  jQuery(function() {
    jQuery('.head_picture a').lightBox({
        maxHeight: 500,
        maxWidth: 700,
        imageBtnPrev: 'gfx/lightbox/lightbox-btn-prev.gif',
	      imageBtnNext: 'gfx/lightbox/lightbox-btn-next.gif',
        imageBtnClose: 'gfx/lightbox/close.png'
    });
  });
  
  
  jQuery('.picture_list img').click(function(){
  
    var gid=$(this).attr('gid');
    $('.pic_link').hide();
    $('#'+gid).show();
    
  
  });
  

  
});























	

