
/* JS: mod_catalog_main*/
// funkce vybira select podle tridy, nutne pro IE
function getSelectsByClassName(cl) {
  var retnode = [];
  var elem = document.getElementsByTagName('select');
  for (var i = 0; i < elem.length; i++) {
    if (elem[i].className.indexOf(cl) != -1)
      retnode.push(elem[i]);
  }
  return retnode;
}

// funkce vybira td podle tridy, nutne pro IE
function getTdsByClassName(cl) {
  var retnode = [];
  var elem = document.getElementsByTagName('td');
  for (var i = 0; i < elem.length; i++) {
    if (elem[i].className.indexOf(cl) != -1)
      retnode.push(elem[i]);
  }
  return retnode;
}

// funkce nastavi priznak, ze formular se nema ukladat a odesle formular
function virtualSubmit(elem) {
  var virtual_submit = document.getElementsByName('virtual_submit');
  virtual_submit[0].value = "ok";
  elem.submit();
}

// sprava profilu - obsluzna funkce pri vyberu vlastnosti
// (disabluje/enabluje ostatni pole atd.)
function selectPropertyHandler(elem) {
  var property_id = elem.value.split('-')[0];
  var root = elem.value.split('-')[1];
  var obligatory_settings = document.getElementsByName('obligatory[]');
  var priority_setting = document.getElementsByName('priority_'+property_id)[0];
  var selected_properties = document.getElementsByName('selected_properties[]');
  var sort_settings = document.getElementsByName('sort[]');
  var preview_settings = document.getElementsByName('preview[]');
  var quick_search_settings = document.getElementsByName('quick_search[]');
  
  priority_setting.disabled = (elem.checked ? false : true);
  if (!elem.checked)
    priority_setting.value = '';
  for (var i=0;i<obligatory_settings.length;i++) {
    if (obligatory_settings[i].value==property_id) {
      obligatory_settings[i].disabled = (elem.checked ? false : true);
      if (!elem.checked)
        obligatory_settings[i].checked = false;
      break;
    }
  }
  for (var i=0;i<sort_settings.length;i++) {
    if (sort_settings[i].value==property_id) {
      sort_settings[i].disabled = (elem.checked ? false : true);
      if (!elem.checked)
        sort_settings[i].checked = false;
      break;
    }
  }
  for (var i=0;i<preview_settings.length;i++) {
    if (preview_settings[i].value==property_id) {
      preview_settings[i].disabled = (elem.checked ? false : true);
      if (!elem.checked)
        preview_settings[i].checked = false;
      break;
    }
  }
  if (quick_search_settings.length) {
    for (var i=0;i<quick_search_settings.length;i++) {
      if (quick_search_settings[i].value==property_id) {
        quick_search_settings[i].disabled = (elem.checked ? false : true);
        if (!elem.checked)
          quick_search_settings[i].checked = false;
        break;
      }
    }
  }
  
  if (root != '0') {
    for (var i=0;i<selected_properties.length;i++) {
      if (selected_properties[i]!=elem && selected_properties[i].value.split('-')[1]==root) {
        selected_properties[i].checked = (elem.checked ? true : false);
        obligatory_settings[i].disabled = (elem.checked ? false : true);
        sort_settings[i].disabled = (elem.checked ? false : true);
        preview_settings[i].disabled = (elem.checked ? false : true);
        if (quick_search_settings.length) {
          quick_search_settings[i].disabled = (elem.checked ? false : true);
        }
        var tmp_prop = document.getElementsByName('priority_'+selected_properties[i].value.split('-')[0])[0];
        tmp_prop.disabled = (elem.checked ? false : true);
        if (!elem.checked) {
          tmp_prop.value = '';
          obligatory_settings[i].checked = false;
          sort_settings[i].checked = false;
          preview_settings[i].checked = false;
          if (quick_search_settings.length) {
            quick_search_settings[i].checked = false;
          }
        } 
      }
    }
  }
}

/* sprava profilu - vyber povinnosti (u vyctovych typu, kdyz je neco povinne
   a ma to nadrazenou vlastnost, pak musi byt povinna i nadrazena vlastnost) */
function selectObligatoryHandler(elem) {
  var property_id = elem.value;
  var selected_properties = document.getElementsByName('selected_properties[]');
  var obligatory_settings = document.getElementsByName('obligatory[]');
  
  // hledame koren a poradi dane vlastnosti
  var root = '0';
  var order = '0';
  for (var i=0; i<selected_properties.length; i++) {
    if (selected_properties[i].value.split('-')[0] == property_id) {
      root = selected_properties[i].value.split('-')[1];
      order = selected_properties[i].value.split('-')[2];
      break;
    }
  }
  
  // pokud jsme aktualni vlastnost nastavili jako povinnou,
  // vsechny ji nadrazene vlastnosti musi byt povinne
  if (root!='0' && elem.checked && order!='0') {
    for (var i=0; i<selected_properties.length; i++) {
      if (selected_properties[i].value.split('-')[1]!='0' &&
        parseInt(selected_properties[i].value.split('-')[2]) < parseInt(order))
        obligatory_settings[i].checked = 'checked';
    }
  }
  
  // pokud jsme aktualni vlastnost nastavili jako nepovinnou,
  // vsechny ji podrizene vlastnosti musi byt nepovinne
  if (root!='0' && !elem.checked) {
    for (var i=0; i<selected_properties.length; i++) {
      if (selected_properties[i].value.split('-')[1]!='0' &&
        parseInt(selected_properties[i].value.split('-')[2]) > parseInt(order))
        obligatory_settings[i].checked = '';
    }
  }
}

// funkce pro vyctovy typ - obsluha selectu vyctoveho typu
function treeSelect(elem, xml) {
  var selects = getSelectsByClassName('form_select');
  var name = (elem.name + '-' + elem.value).substr(elem.name.lastIndexOf('_')+1);
  var hide = false;
  for (var i=0; i < selects.length; i++) {
    // skryjeme vsechny selecty za aktualne vybranym, dokud nenarazime na koren, ten ma v nazvu jen 2 znaky podtrzitka
    if (selects[i].name.split('_').length == (xml ? 3:2))
      hide = false;
    if (hide) {
      selects[i].selectedIndex = -1;
      var options = selects[i].getElementsByTagName('option');
      for (var j=0; j < options.length; j++) {
        options[j].selected = false;
      }
      selects[i].style.display='none';
    }
        
    // zobrazime nasledujici select
    if ((selects[i].name).indexOf(name)!=-1)
      selects[i].style.display='inline';
      
    if (selects[i].name==elem.name)
      hide = true;
  }     
}

// funkce pro presouvani mezi selecty klavesami u vyctoveho typu
function treeKeyHandler(e, elem, xml) {
  var keycode = (window.event) ? event.keyCode : e.keyCode;  
  var selects = getSelectsByClassName('form_select');
  for (var i=0; i < selects.length; i++)
    if (elem == selects[i])
      break;  
  var order = i;
  
  if (keycode == 39) // doprava
  {
    for (var i=order+1; i<selects.length; i++) {
      if (selects[i].style.display != 'none') {
        if (window.event)
          selects[i].getElementsByTagName('option')[0].selected = true;
        if (selects[i].name.split('_').length != (xml ? 3:2))
          selects[i].focus();
        break;
      }
    }
    return false;
  }
  else if (keycode==37) { // doleva
    for (var i=order-1; i>=0; i--) {
      if (selects[i].style.display != 'none') {
        if (selects[i+1].name.split('_').length != (xml ? 3:2))
          selects[i].focus();
        break;
      }
    }
    return false;
  }
  return true;
}

// na prezentaci uzivatel zmenil razeni
function changeSortOrder(elem) {
  document.getElementsByName('search_up_order')[0].click();
}

// pomocna funkce inArray
Array.prototype.inArray = function(valeur) {
  for (var i in this) { if (this[i] === valeur) return i; }
  return -1;
}

// uzivatel vybere rychle hledani
function quickSearch(elem) {
  // najdeme tabulku, ktera zacina predponou mod_catalog_item_table_
  var tbls = document.getElementsByTagName('table'); 
  for (i=0; i<tbls.length; i++) {
    if (tbls[i].className.search('mod_catalog_item_table_')=='0') {
      tbl = tbls[i];
      break;
    }
  }
  
  // zviditelnime ji
  tbl.style.display = '';
  
  // odstranime zpravu o nenalezenych zaznamech
  if (document.getElementById('quick_search_no_records')) {
    elem.parentNode.removeChild(document.getElementById('quick_search_no_records'));
  }
  
  // v tabulce najdeme tbody
  var tbdy = tbl.getElementsByTagName('tbody')[0];
  // zobrazime vsechny tr z tela tabulky
  var trs = tbdy.getElementsByTagName('tr');
  for (j=0; j<trs.length; j++) {
    trs[j].style.display = '';
  }
  
  var filters = elem.parentNode.getElementsByTagName('select');
  for (count=0; count<filters.length; count++) {
    property = filters[count].name.split('quick_search_property_')[1];
    options = filters[count].getElementsByTagName('option');      
    for (i=0; i<options.length; i++) {
      if (options[i].selected) {
        if ((pattern = options[i].value) != '#no_quick_search') {
        
          survivals = new Array();
          // budeme hledat retezec ulozeny v pattern
          tds = getTdsByClassName(property);
          for (j=0; j<tds.length; j++) {
            if (tds[j].innerHTML.search(pattern) != -1) {
              // nasli jsme dany radek, pridame ho do pole tech, co zustanou zobrazene
              survivals.push(tds[j].parentNode);
            }
          }
          
          // vsechny tr, ktere nejsou v survivals, skryjeme
          for (j=0; j<trs.length; j++) {
            if (survivals.inArray(trs[j]) == -1) {
              trs[j].style.display = 'none';
            }
          }
        
        }
        else {
          // nic nefiltrujeme
        }
        break;
      }
    }
  }
  
  var any_record = false;
  for (i=0; i<trs.length; i++) {
    if (trs[i].style.display != 'none') {
      any_record = true;
      break;
    }
  }
  
  // nebyl nalezen zadny zaznam => schovame tabulku, zobrazime zpravu
  if (!any_record) {
    tbl.style.display = 'none';
    var para = document.createElement('p');
    var strong = document.createElement('strong');
    var tpara = document.createTextNode('Na dané stránce nebyl nalezen žádný relevantní záznam.');
    strong.appendChild(tpara);
    para.appendChild(strong);
    elem.parentNode.appendChild(para);
    para.id = 'quick_search_no_records';
  }
}

// filtr objednavek v administraci
function orderFilter(elem) {
  var status = elem.value;
  var tbody = document.getElementById('list_table').getElementsByTagName('tbody')[0];
  var trs = tbody.getElementsByTagName('tr');
  
  // zobrazime vse
  for(var i=0; i<trs.length; i++) {
    trs[i].style.display = '';
  }
  
  if (status != '999') {
    // budeme filtrovat
    for(var i=0; i<trs.length; i++) {
      if (status != trs[i].getElementsByTagName('select')[0].value) {
        trs[i].style.display = 'none';
      }
    }
  }
}

// vrati pocet oznacenych checkboxu v prvnim sloupci tabulky list_table
function getSelCount() {
	var table = document.getElementById('list_table');
	if (!table) {
		alert('Table not found');
		return;
	}
	var cnt = 0;
	for (var i = 0; i < table.rows.length; i++) {
	    elm = table.rows[i].cells[0].childNodes[0];
	    if (elm && (elm.type == 'checkbox') && elm.checked) {
	        cnt++;
		}
	}
	return cnt;
}

// vrati chybu v pripade, ze getSelCount vrati 0
function checkSelection(message_error) {
	var cnt = getSelCount();
	if (cnt == 0) {
		alert(message_error);
		return false;
	} else {
		return true;
	}
}

// potvrzeni smazani vybranych polozek
function confirmSelDelete(message_del, message_error) {
	var cnt = getSelCount();
	if (cnt == 0) {
		alert(message_error);
		return false;
	} else {
		message_del = message_del.replace(/%1/, cnt);
		return confirm(message_del);
	}
}

// vyber/odznaceni vsech checkboxu
function select_all(dest_url, state) {
	var table = document.getElementById('list_table');
	if (!table) {
		alert('Table not found');
		return;
	}
	for (var i = 0; i < table.rows.length; i++) {
	    elm = table.rows[i].cells[0].childNodes[0];
	    if (elm && (elm.type == 'checkbox')) {
	        elm.checked = state;
		}
	}
}


/* JS: new_window*/

function openwin(elm, isImage) {

    if (!isImage) {
      window.open(elm.getAttribute("href"), "_blank");
      return true;
    }


    var msgWindow = window.open(elm.getAttribute("href"), "_blank", "toolbar=no");
    msgWindow.document.write("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>");
    msgWindow.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");
    msgWindow.document.write("<html>");
    msgWindow.document.write("<meta http-equiv='content-type' content='text/html; charset=utf-8'>");
    msgWindow.document.write("<head>");
    msgWindow.document.write("<title>Picture</title>");
    msgWindow.document.write("<style media='screen,tv,projection' type='text/css'> html, body {margin:0;padding:0} a, img {border: 0px solid #fff}</style>");
    msgWindow.document.write("<script type='text/javascript'>");
    msgWindow.document.writeln("    function getInnerHeight() { ");
    msgWindow.document.writeln("           if (window.innerHeight) {");
    msgWindow.document.writeln("             return window.innerHeight;");
    msgWindow.document.writeln("           } else {");
    msgWindow.document.writeln("             return document.documentElement.offsetHeight;"); // document.body.clientHeight;
    msgWindow.document.writeln("           }");
    msgWindow.document.writeln("    }");
    msgWindow.document.writeln("    function getInnerWidth() { ");
    msgWindow.document.writeln("           if (window.innerWidth) {");
    msgWindow.document.writeln("             return window.innerWidth;");
    msgWindow.document.writeln("           } else {");
    msgWindow.document.writeln("             return document.documentElement.offsetWidth;"); //document.body.clientWidth;
    msgWindow.document.writeln("           }");
    msgWindow.document.writeln("    }");
    msgWindow.document.writeln("    function imgSize(controlHeight,fotoMargin) {");
    msgWindow.document.writeln("      image=document.getElementById('image_elm');");
    msgWindow.document.writeln("      if (screen.height <= (image.height + 31)) {");
    msgWindow.document.writeln("        window.resizeTo(image.width + 12,screen.height - 100);");
    msgWindow.document.writeln("      } else {");
    msgWindow.document.writeln("        window.resizeTo(image.width+2*fotoMargin,image.height+controlHeight+fotoMargin);");
    msgWindow.document.writeln("        controlx = image.width+2*fotoMargin - getInnerWidth();");
    msgWindow.document.writeln("        controly = image.height+controlHeight+fotoMargin - getInnerHeight();");
    msgWindow.document.writeln("        window.resizeTo(image.width + controlx+2*fotoMargin, image.height + controly+controlHeight+fotoMargin);");
    msgWindow.document.writeln("      }");
    msgWindow.document.writeln("    }");
    msgWindow.document.write("</script>");
    msgWindow.document.write("</head>");
    msgWindow.document.write("<body style='margin:0;padding:0;background:#fff' onload='imgSize(0,0);'>");
    msgWindow.document.write("<a style='border:0px solid #fff;' href='#' onclick='window.close();'><img src='"+elm.getAttribute("href")+"' style='border:0px solid #fff;' id='image_elm' alt=''></a>");
    msgWindow.document.write("</body>");
    msgWindow.document.write("</html>");
    msgWindow.document.close();
    msgWindow.focus();
    return true;
}

function open_win_external(elm) {
    window.open(elm.getAttribute("href"), "_blank");
    return true;
}

/* JS: pulldown*/
var visibleId=new Array();
var menuDelay = 100;

if (document.getElementById) {
	document.onmousemove = openMenu;
}

function findX(obj) {
    var x = 0;
    while (obj.offsetParent) {
        x += obj.offsetLeft
        obj = obj.offsetParent;
    }
    return x;
}

function openMenu(event) {
	evnt = eval((document.all)?"window.event.srcElement":"event.target");
    if (visibleId.length>0 && // nejake submenu je viditelne
        !ancestorId(evnt, "nav")){ // mys je zcela mimo #nav
        for (i=visibleId.length;i>0;i--){
            hideEl(document.getElementById(visibleId[i-1]));
        }
        visibleId=new Array();
    }
    if (visibleId.length>0 && // je co schovavat
        ancestorId(evnt, "nav") && // mys je pres nejakeho potomka #nav
        evnt.tagName.toLowerCase() == "a" &&
        visibleId[visibleId.length-1].substring(6) != evnt.parentNode.id.substring(7) &&
        !ancestorId(evnt.parentNode, visibleId[visibleId.length-1])  // neni to ale potomek viditelneho menu
        ) {
        hideEl(document.getElementById(visibleId[visibleId.length-1]));
        visibleId = visibleId.slice(0,visibleId.length-1);
    }
    
    if (evnt.parentNode &&
        evnt.parentNode.id &&
        evnt.tagName.toLowerCase()=="a" &&
        ancestorId(evnt, "nav") &&
        evnt.parentNode.className.toLowerCase().indexOf("p_menu_item_")>=0
        ){
            x = findX(evnt.parentNode);
            li = evnt.parentNode;
            ul = document.getElementById("p_sub_"+li.id.substring(7));
            if (ul && ul.style && ul.style.visibility!="visible"){
               visibleId[visibleId.length]=ul.id;
               ul.style.visibility="visible";
               ul.style.display="block";
               if (ul.className.indexOf("p_menu_inner_0")>=0) /* vypocitat pozici prvni roletky (vnorene maji pozici relativni) */
                    ul.style.left=x-findX(document.getElementById("nav"));
            }
    }
}

function ancestorId(element, id){
   var ancestor = element;
   while (ancestor.parentNode){
      if (ancestor.id==id){
         return true;
      }
      ancestor = ancestor.parentNode;
   }
   return false;
}

function hide(elementId){
    element = document.getElementById(elementId);
    cTimer=setTimeout("hideEl(element)",menuDelay);

}

function hideEl(element){
    if (element && element.style){
        element.style.visibility="hidden";
        element.style.display="block";
    }
}

function show(elementId){
    element = document.getElementById(elementId);
    if (element && element.style){
        element.style.visibility="visible";
        element.style.display="block";
    }
}

function toggle(elementId){
    element = document.getElementById(elementId);
    if (element && element.style){
        if (element.style.visibility!="visible"){
            show(element);
        } else {
            hide(element);
        }
    }
}

/* JS: scrollTo*/
/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/9/2009
 *
 * @projectDescription Easy element scrolling using jQuery.
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 * Works with jQuery +1.2.6. Tested on FF 2/3, IE 6/7/8, Opera 9.5/6, Safari 3, Chrome 1 on WinXP.
 *
 * @author Ariel Flesler
 * @version 1.4.1
 *
 * @id jQuery.scrollTo
 * @id jQuery.fn.scrollTo
 * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
 *	  The different options for target are:
 *		- A number position (will be applied to all axes).
 *		- A string position ('44', '100px', '+=90', etc ) will be applied to all axes
 *		- A jQuery/DOM element ( logically, child of the element to scroll )
 *		- A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
 *		- A hash { top:x, left:y }, x and y can be any kind of number/string like above.
 *		- The string 'max' for go-to-end. 
 * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
 * @param {Object,Function} settings Optional set of settings or the onAfter callback.
 *	 @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
 *	 @option {Number} duration The OVERALL length of the animation.
 *	 @option {String} easing The easing method for the animation.
 *	 @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
 *	 @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
 *	 @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
 *	 @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
 *	 @option {Function} onAfter Function to be called after the scrolling ends. 
 *	 @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @desc Scroll to a fixed position
 * @example $('div').scrollTo( 340 );
 *
 * @desc Scroll relatively to the actual position
 * @example $('div').scrollTo( '+=340px', { axis:'y' } );
 *
 * @dec Scroll using a selector (relative to the scrolled element)
 * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
 *
 * @ Scroll to a DOM element (same for jQuery object)
 * @example var second_child = document.getElementById('container').firstChild.nextSibling;
 *			$('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
 *				alert('scrolled!!');																   
 *			}});
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){
	
	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$(window).scrollTo( target, duration, settings );
	};

	$scrollTo.defaults = {
		axis:'xy',
		duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
	};

	// Returns the element that needs to be animated to scroll the window.
	// Kept for backwards compatibility (specially for localScroll & serialScroll)
	$scrollTo.window = function( scope ){
		return $(window).scrollable();
	};

	// Hack, hack, hack... stay away!
	// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
	$.fn.scrollable = function(){
		return this.map(function(){
			var elem = this,
				isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;

				if( !isWin )
					return elem;

			var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
			
			return $.browser.safari || doc.compatMode == 'BackCompat' ?
				doc.body : 
				doc.documentElement;
		});
	};

	$.fn.scrollTo = function( target, duration, settings ){
		if( typeof duration == 'object' ){
			settings = duration;
			duration = 0;
		}
		if( typeof settings == 'function' )
			settings = { onAfter:settings };
			
		if( target == 'max' )
			target = 9e9;
			
		settings = $.extend( {}, $scrollTo.defaults, settings );
		// Speed is still recognized for backwards compatibility
		duration = duration || settings.speed || settings.duration;
		// Make sure the settings are given right
		settings.queue = settings.queue && settings.axis.length > 1;
		
		if( settings.queue )
			// Let's keep the overall duration
			duration /= 2;
		settings.offset = both( settings.offset );
		settings.over = both( settings.over );

		return this.scrollable().each(function(){
			var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');

			switch( typeof targ ){
				// A number will pass the regex
				case 'number':
				case 'string':
					if( /^([+-]=)?\d+(\.\d+)?(px)?$/.test(targ) ){
						targ = both( targ );
						// We are done
						break;
					}
					// Relative selector, no break!
					targ = $(targ,this);
				case 'object':
					// DOMElement / jQuery
					if( targ.is || targ.style )
						// Get the real position of the target 
						toff = (targ = $(targ)).offset();
			}
			$.each( settings.axis.split(''), function( i, axis ){
				var Pos	= axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					Dim = axis == 'x' ? 'Width' : 'Height';

				if( toff ){// jQuery / DOMElement
					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );

					// If it's a dom element, reduce the margin
					if( settings.margin ){
						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
					}
					
					attr[key] += settings.offset[pos] || 0;
					
					if( settings.over[pos] )
						// Scroll to a fraction of its width/height
						attr[key] += targ[Dim.toLowerCase()]() * settings.over[pos];
				}else
					attr[key] = targ[pos];

				// Number or 'number'
				if( /^\d+$/.test(attr[key]) )
					// Check the limits
					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );

				// Queueing axes
				if( !i && settings.queue ){
					// Don't waste time animating, if there's no need.
					if( old != attr[key] )
						// Intermediate animation
						animate( settings.onAfterFirst );
					// Don't animate this axis again in the next iteration.
					delete attr[key];
				}
			});

			animate( settings.onAfter );			

			function animate( callback ){
				$elem.animate( attr, duration, settings.easing, callback && function(){
					callback.call(this, target, settings);
				});
			};

			// Max scrolling position, works on quirks mode
			// It only fails (not too badly) on IE, quirks mode.
			function max( Dim ){
				var scroll = 'scroll'+Dim;
				
				if( !win )
					return elem[scroll];
				
				var size = 'client' + Dim,
					html = elem.ownerDocument.documentElement,
					body = elem.ownerDocument.body;

				return Math.max( html[scroll], body[scroll] ) 
					 - Math.min( html[size]  , body[size]   );
					
			};

		}).end();
	};

	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};

})( jQuery );
/* JS: localscroll*/
/**
 * jQuery.LocalScroll
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/11/2009
 *
 * @projectDescription Animated scrolling navigation, using anchors.
 * http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html
 * @author Ariel Flesler
 * @version 1.2.7
 *
 * @id jQuery.fn.localScroll
 * @param {Object} settings Hash of settings, it is passed in to jQuery.ScrollTo, none is required.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @example $('ul.links').localScroll();
 *
 * @example $('ul.links').localScroll({ filter:'.animated', duration:400, axis:'x' });
 *
 * @example $.localScroll({ target:'#pane', axis:'xy', queue:true, event:'mouseover' });
 *
 * Notes:
 *	- The plugin requires jQuery.ScrollTo.
 *	- The hash of settings, is passed to jQuery.ScrollTo, so the settings are valid for that plugin as well.
 *	- jQuery.localScroll can be used if the desired links, are all over the document, it accepts the same settings.
 *  - If the setting 'lazy' is set to true, then the binding will still work for later added anchors.
  *	- If onBefore returns false, the event is ignored.
 **/
;(function( $ ){
	var URI = location.href.replace(/#.*/,''); // local url without hash

	var $localScroll = $.localScroll = function( settings ){
		$('body').localScroll( settings );
	};

	// Many of these defaults, belong to jQuery.ScrollTo, check it's demo for an example of each option.
	// @see http://flesler.demos.com/jquery/scrollTo/
	// The defaults are public and can be overriden.
	$localScroll.defaults = {
		duration:1000, // How long to animate.
		axis:'y', // Which of top and left should be modified.
		event:'click', // On which event to react.
		stop:true, // Avoid queuing animations 
		target: window, // What to scroll (selector or element). The whole window by default.
		reset: true // Used by $.localScroll.hash. If true, elements' scroll is resetted before actual scrolling
		/*
		lock:false, // ignore events if already animating
		lazy:false, // if true, links can be added later, and will still work.
		filter:null, // filter some anchors out of the matched elements.
		hash: false // if true, the hash of the selected link, will appear on the address bar.
		*/
	};

	// If the URL contains a hash, it will scroll to the pointed element
	$localScroll.hash = function( settings ){
		if( location.hash ){
			settings = $.extend( {}, $localScroll.defaults, settings );
			settings.hash = false; // can't be true
			
			if( settings.reset ){
				var d = settings.duration;
				delete settings.duration;
				$(settings.target).scrollTo( 0, settings );
				settings.duration = d;
			}
			scroll( 0, location, settings );
		}
	};

	$.fn.localScroll = function( settings ){
		settings = $.extend( {}, $localScroll.defaults, settings );

		return settings.lazy ?
			// use event delegation, more links can be added later.		
			this.bind( settings.event, function( e ){
				// Could use closest(), but that would leave out jQuery -1.3.x
				var a = $([e.target, e.target.parentNode]).filter(filter)[0];
				// if a valid link was clicked
				if( a )
					scroll( e, a, settings ); // do scroll.
			}) :
			// bind concretely, to each matching link
			this.find('a,area')
				.filter( filter ).bind( settings.event, function(e){
					scroll( e, this, settings );
				}).end()
			.end();

		function filter(){// is this a link that points to an anchor and passes a possible filter ? href is checked to avoid a bug in FF.
			return !!this.href && !!this.hash && this.href.replace(this.hash,'') == URI && (!settings.filter || $(this).is( settings.filter ));
		};
	};

	function scroll( e, link, settings ){
		var id = link.hash.slice(1),
			elem = document.getElementById(id) || document.getElementsByName(id)[0];

		if ( !elem )
			return;

		if( e )
			e.preventDefault();

		var $target = $( settings.target );

		if( settings.lock && $target.is(':animated') ||
			settings.onBefore && settings.onBefore.call(settings, e, elem, $target) === false ) 
			return;

		if( settings.stop )
			$target.stop(true); // remove all its animations

		if( settings.hash ){
			var attr = elem.id == id ? 'id' : 'name',
				$a = $('<a> </a>').attr(attr, id).css({
					position:'absolute',
					top: $(window).scrollTop(),
					left: $(window).scrollLeft()
				});

			elem[attr] = '';
			$('body').prepend($a);
			location = link.hash;
			$a.remove();
			elem[attr] = id;
		}
			
		$target
			.scrollTo( elem, settings ) // do scroll
			.trigger('notify.serialScroll',[elem]); // notify serialScroll about this change
	};

})( jQuery );
/* JS: serialScroll*/
/**
 * jQuery.serialScroll
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/20/2008
 *
 * @projectDescription Animated scrolling of series.
 * @author Ariel Flesler
 * @version 1.2.1
 *
 * @id jQuery.serialScroll
 * @id jQuery.fn.serialScroll
 * @param {Object} settings Hash of settings, it is passed in to jQuery.ScrollTo, none is required.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
 *
 * Notes:
 *	- The plugin requires jQuery.ScrollTo.
 *	- The hash of settings, is passed to jQuery.ScrollTo, so its settings can be used as well.
 */
;(function( $ ){

	var $serialScroll = $.serialScroll = function( settings ){
		$.scrollTo.window().serialScroll( settings );
	};

	//Many of these defaults, belong to jQuery.ScrollTo, check it's demo for an example of each option.
	//@see http://flesler.webs/jQuery.ScrollTo/
	$serialScroll.defaults = {//the defaults are public and can be overriden.
		duration:1000, //how long to animate.
		axis:'x', //which of top and left should be scrolled
		event:'click', //on which event to react.
		start:0, //first element (zero-based index)
		step:1, //how many elements to scroll on each action
		lock:true,//ignore events if already animating
		cycle:true, //cycle endlessly ( constant velocity )
		constant:true //use contant speed ?
		/*
		navigation:null,//if specified, it's a selector a collection of items to navigate the container
		target:null, //if specified, it's a selector to the element to be scrolled.
		interval:0, //it's the number of milliseconds to automatically go to the next
		lazy:false,//go find the elements each time (allows AJAX or JS content, or reordering)
		stop:false, //stop any previous animations to avoid queueing
		force:false,//force the scroll to the first element on start ?
		jump: false,//if true, when the event is triggered on an element, the pane scrolls to it
		items:null, //selector to the items (relative to the matched elements)
		prev:null, //selector to the 'prev' button
		next:null, //selector to the 'next' button
		onBefore: function(){}, //function called before scrolling, if it returns false, the event is ignored
		exclude:0 //exclude the last x elements, so we cannot scroll past the end
		*/
	};

	$.fn.serialScroll = function( settings ){
		settings = $.extend( {}, $serialScroll.defaults, settings );
		var event = settings.event, //this one is just to get shorter code when compressed
			step = settings.step, // idem
			lazy = settings.lazy;//idem

		return this.each(function(){
			var 
				context = settings.target ? this : document, //if a target is specified, then everything's relative to 'this'.
				$pane = $(settings.target || this, context),//the element to be scrolled (will carry all the events)
				pane = $pane[0], //will be reused, save it into a variable
				items = settings.items, //will hold a lazy list of elements
				active = settings.start, //active index
				auto = settings.interval, //boolean, do auto or not
				nav = settings.navigation, //save it now to make the code shorter
				timer; //holds the interval id

			if( !lazy )//if not lazy, go get the items now
				items = getItems();

			if( settings.force )
				jump( {}, active );//generate an initial call

			// Button binding, optionall
			$(settings.prev||[], context).bind( event, -step, move );
			$(settings.next||[], context).bind( event, step, move );

			// Custom events bound to the container
			if( !pane.ssbound )//don't bind more than once
				$pane
					.bind('prev.serialScroll', -step, move ) //you can trigger with just 'prev'
					.bind('next.serialScroll', step, move ) //for example: $(container).trigger('next');
					.bind('goto.serialScroll', jump ); //for example: $(container).trigger('goto', [4] );
			if( auto )
				$pane
					.bind('start.serialScroll', function(e){
						if( !auto ){
							clear();
							auto = true;
							next();
						}
					 })
					.bind('stop.serialScroll', function(){//stop a current animation
						clear();
						auto = false;
					});
			$pane.bind('notify.serialScroll', function(e, elem){//let serialScroll know that the index changed externally
				var i = index(elem);
				if( i > -1 )
					active = i;
			});
			pane.ssbound = true;//avoid many bindings

			if( settings.jump )//can't use jump if using lazy items and a non-bubbling event
				(lazy ? $pane : getItems()).bind( event, function( e ){
					jump( e, index(e.target) );
				});

			if( nav )
				nav = $(nav, context).bind(event, function( e ){
					e.data = Math.round(getItems().length / nav.length) * nav.index(this);
					jump( e, this );
				});

			function move( e ){
				e.data += active;
				jump( e, this );
			};
			function jump( e, button ){
				if( !isNaN(button) ){//initial or special call from the outside $(container).trigger('goto',[index]);
					e.data = button;
					button = pane;
				}

				var
					pos = e.data, n,
					real = e.type, //is a real event triggering ?
					$items = settings.exclude ? getItems().slice(0,-settings.exclude) : getItems(),//handle a possible exclude
					limit = $items.length,
					elem = $items[pos],
					duration = settings.duration;

				if( real )//real event object
					e.preventDefault();

				if( auto ){
					clear();//clear any possible automatic scrolling.
					timer = setTimeout( next, settings.interval ); 
				}

				if( !elem ){ //exceeded the limits
					n = pos < 0 ? 0 : limit - 1;
					if( active != n )//we exceeded for the first time
						pos = n;
					else if( !settings.cycle )//this is a bad case
						return;
					else
						pos = limit - n - 1;//invert, go to the other side
					elem = $items[pos];
				}

				if( !elem || real && active == pos || //could happen, save some CPU cycles in vain
					settings.lock && $pane.is(':animated') || //no animations while busy
					real && settings.onBefore && //callback returns false ?
					settings.onBefore.call(button, e, elem, $pane, getItems(), pos) === false ) return;

				if( settings.stop )
					$pane.queue('fx',[]).stop();//remove all its animations

				if( settings.constant )
					duration = Math.abs(duration/step * (active - pos ));//keep constant velocity

				$pane
					.scrollTo( elem, duration, settings )//do scroll
					.trigger('notify.serialScroll',[pos]);//in case serialScroll was called on this elem more than once.
			};
			function next(){//I'll use the namespace to avoid conflicts
				$pane.trigger('next.serialScroll');
			};
			function clear(){
				clearTimeout(timer);
			};
			function getItems(){
				return $( items, pane );
			};
			function index( elem ){
				if( !isNaN(elem) ) return elem;//number
				var $items = getItems(), i;
				while(( i = $items.index(elem)) == -1 && elem != pane )//see if it matches or one of its ancestors
					elem = elem.parentNode;
				return i;
			};
		});
	};

})( jQuery );
/* JS: coda-slider*/
// when the DOM is ready...

$(document).ready(function () {

var $panels = $('#slider .scrollContainer > div');
var $container = $('#slider .scrollContainer');

// if false, we'll float all the panels left and fix the width 
// of the container
var horizontal = true;

// float the panels left if we're going horizontal
//start 
if (horizontal) {

  $panels.css({
    'float' : 'left',
    'position' : 'relative' // IE fix to ensure overflow is hidden
  });
  
  // calculate a new width for the container (so it holds all panels)
  $container.css({width : $panels[0].offsetWidth * $panels.length});

//konec
}

// collect the scroll object, at the same time apply the hidden overflow
// to remove the default scrollbars that will appear
var $scroll = $('#slider .scroll').css('overflow', 'hidden');

// handle nav selection
function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}

$('#slider .navigation').find('a').click(selectNav);

// go find the navigation link that has this target and select the nav
function trigger(data) {
  var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
  selectNav.call(el);
}

if (window.location.hash) {
  trigger({ id : window.location.hash.substr(1) });
} else {
  $('ul.navigation a:first').click();
}

// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset.  Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ? 
  $container.css('paddingTop') : 
  $container.css('paddingLeft')) 
  || 0) * -1;


var scrollOptions = {
  target: $scroll, // the element that has the overflow
  
  // can be a selector which will be relative to the target
  items: $panels,
  
  navigation: '.navigation a',
  
  // selectors are NOT relative to document, i.e. make sure they're unique
  prev: 'img.left', 
  next: 'img.right',
  
  // allow the scroll effect to run both directions
  axis: 'xy',
  
  onAfter: trigger, // our final callback
  
  offset: offset,
  
  // duration of the sliding effect
  duration: 500,
  
  // easing - can be used with the easing plugin: 
  // http://gsgd.co.uk/sandbox/jquery/easing/
  easing: 'swing'
};

// apply serialScroll to the slider - we chose this plugin because it 
// supports// the indexed next and previous scroll along with hooking 
// in to our navigation.
// tady: 
$('#slider').serialScroll(scrollOptions);

// now apply localScroll to hook any other arbitrary links to trigger 
// the effect
// tady: 
$.localScroll(scrollOptions);

// finally, if the URL has a hash, move the slider in to position, 
// setting the duration to 1 because I don't want it to scroll in the
// very first page load.  We don't always need this, but it ensures
// the positioning is absolutely spot on when the pages loads.
// tady: 
scrollOptions.duration = 1;
// tady: 
$.localScroll.hash(scrollOptions);

});
/* JS: init-title*/
$(document).ready(function(){

	$(".p_menu_item_0:last-child").addClass("p_last");
	$("#dymik").css({"_top": "12px"});
});

