var cur_woj;
function swapLayers(id) {
  if (cur_woj) hideLayer(cur_woj);
  showLayer(id);
  cur_woj = id;
}

function showLayer(id) {
  var woj = getElemRefs(id);
  if (woj && woj.css) woj.css.display = "block";
}

function hideLayer(id) {
  var woj = getElemRefs(id);
  if (woj && woj.css) woj.css.display = "none";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}




var _drag_drop = false;
$(document).ready(function() {
	if(!_drag_drop)
		return true;
	domOperations = {
		
		_list: new Array,	
		_speed : "slow",
		
		init: function() {
			eval($.cookie('order'));
			if(typeof(a) == 'object') {
				this.load(a);
			}
			var div_list = $('div.lap3_gradient').get();
			for(i in div_list) {		
				if(typeof(div_list) == 'object') {
					this._list[i] = div_list[i];
					if(div_list[i].id != undefined && $.cookie(div_list[i].id) != null) {						
						if(parseInt($.cookie(div_list[i].id)) > 0)
							showLi($(div_list[i]).children('.content_container').children('.content').children(),$.cookie(div_list[i].id));
					} 
				}
			}			
		},		
		
		check: function(div) {
			id = div[0].id;
			for(i in this._list)
				if(this._list[i].id == id)
					return this._list[i];
		},
		
		checkNo: function(div) {				
			id = div[0].id;
			for(i in this._list)
				if(this._list[i].id == id)
					return i*1;
		},
		
		doUpButtons: function(a_list) {						
			$(a_list).bind('click', function() { 
					domOperations.goUp($(this.parentNode.parentNode.parentNode));
				});
		}, 
		
		doDownButtons: function(a_list) {
			$(a_list).bind('click', function() { 
					domOperations.goDown($(this.parentNode.parentNode.parentNode));
				});
		},				
				
		goUp: function(el) {
			no = this.checkNo(el);
			if(no == 0)
				return;
			next = no -1;	
			a = this;
			$(this._list[next]).fadeOut(this._speed);		
			$(this._list[no]).fadeOut(this._speed, function() {				
 						$(a._list[no]).fadeIn(a._speed).insertBefore($(a._list[next]));
				$(a._list[next]).fadeIn(a._speed);
				_tmp = a._list[next];
				a._list.splice(next,2,el[0],_tmp);
			});			
			$.cookie('order', domOperations.toSave(), {expires: 30});
		},
						
		goDown: function(el) {
				
		
			no = this.checkNo(el);
			
			if(no == this._list.length-1)
				return ;
			next = no +1;
			a = this;
			$(this._list[next]).fadeOut(this._speed);
			$(this._list[no]).fadeOut(this._speed, function() {		
				$(a._list[next]).fadeIn(a._speed).insertBefore($(a._list[no]));
				$(a._list[no]).fadeIn(a._speed);					
				_tmp = a._list[next];
				a._list.splice(no,2,_tmp,el[0]);
			});
			$.cookie('order', domOperations.toSave(), {expires: 30});
		},
		
		load: function(ar) {
			for(i=ar.length;i>=0;i--) {
				$('#'+ar[i]).prependTo($('#c_right'));
			}
		},
		
		toSave: function() {
			var div_list = $('div.lap3_gradient');
			for(i in div_list)		
				this._list[i] = div_list[i];
			var string = new Array();
			for(i=0;i<this._list.length-1;i++) {
				string[i] = "'"+this._list[i].id+"'";	
			}
			_string='a = [ '+string.join(', ')+' ]';
			return _string;
		}
	};
	
	domOperations.init();
	domOperations.doUpButtons($('div.scrolls > a.up'));
	domOperations.doDownButtons($('div.scrolls > a.down'));
	
	$('div#c_right').Sortable(
    {
        accept :	'lap3_gradient',
        opacity:	0.4,
        fx:	1,
        axis:	'vertically',
        revert:	true,
		ghosting:	true,
		onchange:	function() {
			$.cookie('order', domOperations.toSave(), {expires: 30});
		}
    });
	
	function showLi(ul,n) {
		$.cookie(ul.parent().parent().parent()[0].id,n, {expires: 30});
		$.each(ul.parent().parent().parent().children('.info').children('.n').children('a'),function(i,el) {
			$(el).removeClass();
			if(el.href.substring(el.href.length-1) == n) {
				$(el).addClass('selected');
			}
		});
		var li = ul.children('li');
		for(i=1;i<=8;i++)
		{
			if(i < n) {
				$(li[i]).css('display','block');
			}
			else
				$(li[i]).css('display','none');
		}
	}
	
	$('div.n > a[@href*=#1]').click(function(){		
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 1);
	});
	
	$('div.n > a[@href*=#2]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 2);
	});
	
	$('div.n > a[@href*=#3]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 3);
	});
	
	$('div.n > a[@href*=#4]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 4);
	});
	
	$('div.n > a[@href*=#5]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 5);
	});
	
	$('div.n > a[@href*=#6]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 6);
	});
	
	$('div.n > a[@href*=#7]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 7);
	});
	
	$('div.n > a[@href*=#8]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 8);
	});
	
	$('div.n > a[@href*=#9]').click(function(){
		showLi($(this).parent().parent().parent().children('.content_container').children('.content').children('ul'), 9);
	});
	
	$('div.h3 > a.adapt').click(function() {
		/*if($(this).parent().parent().children('.info').css('display') == 'block') {
			$(this).parent().parent().children('.info').css('display','none');
		} else {
			$(this).parent().parent().children('.info').css('display','block');
		}*/
		$(this).parent().parent().children('.info').animate({height: 'toggle', opacity: 'toggle'}, "slow");
	});
	
	$('div.lap3_gradient > .h3').ToolTip({className: 'inputsTooltip', position: 'mouse', delay: 200}).mouseover(function(){
		ile = $.cookie('ile');
		ile++;
		$.cookie('ile', ile);
		if(ile > 3) {
			$('div.lap3_gradient > .h3').attr('title', '');
		}
	});
	
		
	$('div.count > div.name > a[@href*=#1]').click(function() {
		$('div.count > div.name > a').removeClass();
		$(this).addClass('count_select')
		$('div.content > div').css('display','none');
		$('div.content > div#news1').css('display','block');
	});
	
	$('div.count > div.name > a[@href*=#2]').click(function() {
		$('div.count > div.name > a').removeClass();
		$(this).addClass('count_select')
		$('div.content > div').css('display','none');
		$('div.content > div#news2').css('display','block');
	});
	
	$('div.count > div.name > a[@href*=#3]').click(function() {
		$('div.count > div.name > a').removeClass();
		$(this).addClass('count_select')
		$('div.content > div').css('display','none');
		$('div.content > div#news3').css('display','block');
	});
	
	$('div.topmenu1 > a').click(function() {
			var href = this.href.substring(this.href.indexOf('#')+1);
			$('.submenu1').css('display', 'none');
			$('.submenu2').css('display', 'none');
			$('.submenu3').css('display', 'none');
			$('.submenu4').css('display', 'none');
			$.each($('div.topmenu > a > img'), function() {
				this.src = this.src.replace('_a.gif', '.gif');
			});
			$(this).children()[0].src = $(this).children()[0].src.replace('.gif', '_a.gif');
			if(href == 'serwisybranzowe') {
				$('.submenu1').css('display', 'block');
				//$(this).children()[0]
			}
			else if(href == 'calaoferta')
				$('.submenu2').css('display', 'block');
			else if(href == 'markaabc')
				$('.submenu3').css('display', 'block');
			else
				$('.submenu4').css('display', 'block');
	});
	
	$('div.submenu1 > a > img').click(function() {
		$.each($('div.submenu1 > a > img'), function () {
			this.src = this.src.replace('_a.gif', '.gif');
		});
		this.src = this.src.replace('.gif', '_a.gif');		
		return false;
	});	
	$('div.submenu2 > a > img').click(function() {
		$.each($('div.submenu2 > a > img'), function () {
			this.src = this.src.replace('_a.gif', '.gif');
		});
		this.src = this.src.replace('.gif', '_a.gif');
		return false;
	});	
	$('div.submenu3 > a > img').click(function() {
		$.each($('div.submenu3 > a > img'), function () {
			this.src = this.src.replace('_a.gif', '.gif');
		});
		this.src = this.src.replace('.gif', '_a.gif');
	
		return false;
	});	
	
	if($.browser.opera) {
		$('div.content > ul > li > a').click( function () {
			return false;
		});
	}
});

/*
  ***********************************************

    plik: okno.js
    opis: znajdują się tu funkcje do
          wyświetlania 'popup-ów' czyli małych
          okienek - o zdefiniowanych
          indywidualnie parametrach

  ***********************************************
*/

var Okno = null;
var Okno2 = null;

// funkcja zwraca ustawienia okna
function ustawienia_okna(Width,Height,X,Y,scroll){
	return "width=" + Width + ","
	+ "height=" + Height + ","
	+ "location=no,"
	+ "menubar=no,"
	+ "resizable=no,"
	+ "scrollbars="+scroll+","
	+ "status=no,"
	+ "titlebar=no,"
	+ "toolbar=no,"
	+ "hotkeys=no,"
	+ "dependent=no,"
	+ "directories=no,"
	+ "fullscreen=no,"
	+ "channelmode=no,"
	+ "screenx=" + X + ","
	+ "screeny=" + Y + ","
	+ "left=" + X + ","
	+ "top=" + Y;
}


// funkcja otwiera nowe okno z podanym adresem
function okno(URL,Tytul,Width,Height,src,scroll,poz_x,poz_y){
	var Xokno;

	if(scroll==null) scroll = 1;
	if(poz_x==null) poz_x = 0;
	if(poz_y==null) poz_y = 0;

	if (navigator.appName == "Netscape" && eval(src) && eval(src +".closed")) eval(src +"=null");
	else 
	if ((navigator.appName != "Opera") && (eval(src)!=null) && (typeof(eval(src))!='object')) {eval(src+".close()");}

	poz_x = poz_x ? poz_x : (screen.width-Width)/2;
	poz_y = poz_y ? poz_y : (screen.height-Height)/2;
	poz_y -= 22;

	
	Xokno=window.open(URL,Tytul,ustawienia_okna(Width,Height,poz_x,poz_y,scroll));
  	Xokno.resizeTo(Width, Height);
 	Xokno.moveTo(poz_x, poz_y);
	Xokno.focus();
	eval(src +"=Xokno");
}

//<!--

/*
 BIBLIOTEKA DO OBSŁUGI FORMULARZY
 Copyright (C) 2003 Davidion - Dawid Jakubowski
*/

function Form_Prompt(command,msg){ if(msg != '') msg = "\n\n"+msg; if(confirm("Na pewno chcesz usun±ć wybran± pozycję?"+msg)) location = command; }

var Form_const_mail = /^(([a-z0-9_]|\-|\.)+\@([a-z0-9_]|\-|\.)+\.[a-z]{2,4}(;|,)? ?)+$/i;

function Form_Del_Confirm(command,msg)
{
  if(msg != '') msg = "\n\n"+msg;
  if(confirm("Na pewno chcesz usun±ć wybran± pozycję?"+msg)) location = command;
}

function Form_Add_Var(text,reg,required,new_style)
{

  this.text = text;
  this.reg = reg;

  if(typeof required == "undefined" || required == false)
    this.required = false;
  else
    this.required = true;
  if(typeof new_style != "undefined") this.new_style = new_style;
}

function Form_Check(check)
{


  for (var i in check)
  {
    if(check[i].constructor == Array)
    {
      var wymagane = false;
      var grupa = false;
      var komunikat = '';
      var el = null;
      for(var j in check[i])
      {

if(check[i][j].required && !wymagane) {wymagane = true; komunikat = check[i][j].text; el=document.getElementById(j);}
        if( Form_Check_Parse(check[i],j,true) ) grupa = true;
      }
      if(wymagane && !grupa)
      {
        alert(komunikat);
        el.select();
        el.focus();
        return false;
      }
      else
      {
        for(var j in check[i])
        {
          var el = document.getElementById(j);
          var pr = el.parentNode;
          if(typeof el.old_style == "undefined") el.old_style = el.style.cssText;
          if(typeof pr.old_style == "undefined") pr.old_style = pr.style.cssText;
          el.style.cssText = el.old_style;
          pr.style.cssText = pr.old_style;
        }
      }
    }
    else
    {
      if(!Form_Check_Parse(check,i)) return false;
    }
  }
  return true;
};


function Form_Check_Parse(check,i,group)
{
   var new_style = (typeof check[i].new_style == "undefined") ? "background-color: #EE8888" : check[i].new_style;
   var el = document.getElementById(i);
   var pr = el.parentNode;
   if(typeof el.old_style == "undefined") el.old_style = el.style.cssText;
   if(typeof pr.old_style == "undefined") pr.old_style = pr.style.cssText;
   el.style.cssText = el.old_style;
   pr.style.cssText = pr.old_style;

     if( (typeof el.value != "undefined" && el.value != '' && !check[i].required) || check[i].required || group)
     {

       switch(el.type)
       {
         case 'select-one':
             if(el.selectedIndex == -1 || el.selectedIndex == 0)
             {
               el.style.cssText = el.old_style +';'+ new_style;
               if(!group)
               {
                 alert(check[i].text);
                 el.focus();
               }
               return false;
             }
           break;
         case 'select-multiple':

             if(el.selectedIndex == -1)
             {
               el.style.cssText = el.old_style +';'+ new_style;
               if(!group)
               {
                 alert(check[i].text);
                 el.focus();
               }
               return false;
             }
           break;

         case 'checkbox':
             if(!el.checked)
             {
               if(ie)
                 el.style.cssText = new_style;
               else
                 pr.style.cssText = pr.old_style +';'+new_style;

               if(!group)
               {
                 alert(check[i].text);
                 el.select();
                 el.focus();
               }
               return false;
             }
           break;

         case 'radio':
           var el = document.getElementsByName(i);
           var ret = false;
             for (var j=0;j<el.length; j++) if(el[j].checked) ret = true;
             if(!ret)
             {
               if(ie)
               {
                 if(typeof el[0].old_style == "undefined") el[0].old_style = el[0].style.cssText;
                 el[0].style.cssText = el[0].old_style;
                 el[0].style.cssText = new_style;
               }
               else
               {
                 pr = el[0].parentNode
                 if(typeof pr.old_style == "undefined") pr.old_style = pr.style.cssText;
                 pr.style.cssText = pr.old_style;
                 pr.style.cssText = new_style;
               }

               if(!group)
               {
                 alert(check[i].text);
                 el[0].select();
                 el[0].focus();
               }
               return false
             }
           break;

         case 'text':
         case 'file':
         case 'textarea':
         case 'password':
             if (!check[i].reg.test(el.value)) 
             {
               el.style.cssText = new_style;
               if(!group)
               {
                 alert(check[i].text);
                 el.select();
                 el.focus();
               }
               return false;
             }
           break;
       }
     }
  return true;
}

//-->
