/*
*
* Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
* Licensed under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
* 
*/
/*
 * jQuery Image Replacement. An alternative to using CSS hacks
 * The id attribute (or class) is used for the filename
 *
 * @name     jQIR  
 * @param    Function onload  (optional) Function to run when image has loaded 
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $(".jqir").jQIR("png", "images/");
 * @before   <h1 id="heading1" class="jqir">Heading 1</h1>
 *           <h2 class="jqir {src:heading2.png}">Heading 2</h2>
 * @result   <h1 id="heading1" class="jqir"><img alt="Heading 1" src="images/heading1.png"></h1>   
 *           <h2 class="jqir {src:heading2.png}"><img alt="Heading 2" src="images/heading2.png"></h2>   
 * @example  $(".jqir").jQIR("gif"); // use same folder as page
 * @before   <h1 id="heading1" class="jqir">Heading 1</h1>
 * @result   <h1 id="heading1" class="jqir"><img alt="Heading 1" src="heading1.gif"></h1>   
 *
 */
var currentNewsitem = 0;
var maxNewsitem = 3;

function redrawNewsitem()
{
  if(currentNewsitem == 0) {
    $("#newsflash span.left_arrow").hide();
  }
  else {
    $("#newsflash span.left_arrow").show();
  }
  if((currentNewsitem + maxNewsitem) <= $("#newsflash div.newsflash").length) {
    $("#newsflash span.right_arrow").show();
  }
  else {
    $("#newsflash span.right_arrow").hide();
  }
  $("#newsflash div.newsflash").each(function(index, item) {
    if(index >= currentNewsitem && index < (currentNewsitem + maxNewsitem)) {
      $(item).show();
    }
    else {
      $(item).hide();
    }
  });
}

function floatingEffectBlock()
{
  var fullHeight = $("#bd .floating-effect-block .second").innerHeight() - 100;
  var minHeight = 5;

  if($("#bd .floating-effect-block")) {
    if($("#bd .floating-effect-block .first").innerHeight() <= minHeight) {
      $("#bd .floating-effect-block .first").animate({height: fullHeight}, 5000, 'swing',
        function() {
          setTimeout(function() {floatingEffectBlock();}, 3000);
        }
      );
    }
    else {
      $("#bd .floating-effect-block .first").animate({height: minHeight}, 5000, 'swing',
        function() {
          setTimeout(function() {floatingEffectBlock();}, 3000);
        }
      );
    }
  }
}

$(document).ready(function() {
  $("a.zoom[rel!=testimony]").attr('rel', 'clickable_gallery');
  $("a.zoom").fancybox({"overlayShow": false});
  $("a[rel=external]").attr('target', "_blank");
  $("#hd label").inFieldLabels();
  
  $("#hd form input[type=submit]").addClass("submit");
  $("#hd form span.search-icon").show().click(function() {
    $("#hd form").submit();
  });

  $("#banner ul.menu li a").append('<span></span>');

  $("#hd h3.phone_select span").click(function() {
    if(!$(this).hasClass('active')) {
      if($(this).hasClass('praha')) {
        $("#hd ul.contact li.praha").show();
        $("#hd ul.contact li.brno").hide();
        $("#hd h3.phone_select span.praha").addClass('active');
        $("#hd h3.phone_select span.brno").removeClass('active');
      }
      else {
        $("#hd ul.contact li.brno").show();
        $("#hd ul.contact li.praha").hide();
        $("#hd h3.phone_select span.brno").addClass('active');
        $("#hd h3.phone_select span.praha").removeClass('active');
      }
    }
  });
  
  $("#slideshow").jqFancyTransitions({effect: 'wave', width: 700, height: 260, direction: 'fountainAlternate', position: 'top', strips: 15});

  if(!$("#iv-content-widget-controls").length) {
    $("#banner .yui-g .yui-u").each(function() {
      $(this).append('<div class="slideshow"><div class="details"></div></div>');
      $(this).find(".slideshow").append($(this).find("img"));
      $(this).find(".details").append($(this).find("ul"));
      $(this).find("p").remove();
    });

    $("#banner .yui-g .slideshow")
      .cycle({timeout: 5000, speed: 2000, slideExpr: "img"});
    $("#banner .yui-g .yui-u")
      .click(function() {
        window.location.href = $(this).find("a").attr('href');
      })
      .hover(function() {
        $(this).find(".details").show();
        $(this).find("h2").addClass("active")
      }, function() {
        $(this).find(".details").hide();
        $(this).find("h2").removeClass("active")
      });
  }

  if($("#newsflash div.newsflash").length > maxNewsitem) {
    $("#newsflash span.left_arrow, #newsflash span.right_arrow").css('display', 'block');

    redrawNewsitem();

    $("#newsflash span.left_arrow").click(function() {
      currentNewsitem = currentNewsitem >= maxNewsitem ? currentNewsitem - maxNewsitem : currentNewsitem;
      redrawNewsitem();
    });

    $("#newsflash span.right_arrow").click(function() {
      currentNewsitem = (currentNewsitem + maxNewsitem) < ($("#newsflash div.newsflash").length) ? currentNewsitem + maxNewsitem : currentNewsitem;
      redrawNewsitem();
    });
  }

  floatingEffectBlock();

  $("#bd.contacts .slideshow")
    .cycle({timeout: 5000, speed: 2000, slideExpr: "img"});

  $("#bd .yui-gd .slideshow")
    .cycle({timeout: 5000, speed: 2000, slideExpr: "img"});

// remove replaced fonts
//  if(document.images) {
//    var path = "/replacement/";
//    $("#banner .yui-g h2").each(function() {
//      var img = $("<img>"), el = jQuery(this);
//      var file;
//      var re = /(?:{src\:)(\S+)(?:})/i;
//      var m = this.className.match(re);
//      if(m)
//      {
//        file = path + m[1];
//      }
//      else
//      {
//        file = path + "index.php?type=" + this.className + "&text=" + escape($(this).html());
//      }
//
//      jQuery(img).attr(
//      {
//        src: file,
//        alt: el.text()
//      }).load(typeof onload == "function" ? onload : function(){} );
//      var a = el.find("a");
//      var toAppend = a.length ? a.empty().append(img) : img;
//      el.empty().append(toAppend);
//    });
//  }
});

/*
 * jQuery Cycle Plugin (with Transition Definitions)
 * Examples and documentation at: http://malsup.com/jquery/cycle/
 * Copyright (c) 2007-2008 M. Alsup
 * Version: 2.22
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
;(function($){var ver='Lite-1.0';$.fn.cycle=function(options){return this.each(function(){options=options||{};if(this.cycleTimeout)clearTimeout(this.cycleTimeout);this.cycleTimeout=0;this.cyclePause=0;var $cont=$(this);var $slides=options.slideExpr?$(options.slideExpr,this):$cont.children();var els=$slides.get();if(els.length<2){if(window.console&&window.console.log)
window.console.log('terminating; too few slides: '+els.length);return;}
var opts=$.extend({},$.fn.cycle.defaults,options||{},$.metadata?$cont.metadata():$.meta?$cont.data():{});opts.before=opts.before?[opts.before]:[];opts.after=opts.after?[opts.after]:[];opts.after.unshift(function(){opts.busy=0;});var cls=this.className;opts.width=parseInt((cls.match(/w:(\d+)/)||[])[1])||opts.width;opts.height=parseInt((cls.match(/h:(\d+)/)||[])[1])||opts.height;opts.timeout=parseInt((cls.match(/t:(\d+)/)||[])[1])||opts.timeout;if($cont.css('position')=='static')
$cont.css('position','relative');if(opts.width)
$cont.width(opts.width);if(opts.height&&opts.height!='auto')
$cont.height(opts.height);var first=0;$slides.css({position:'absolute',top:0,left:0}).hide().each(function(i){$(this).css('z-index',els.length-i)});$(els[first]).css('opacity',1).show();if($.browser.msie)els[first].style.removeAttribute('filter');if(opts.fit&&opts.width)
$slides.width(opts.width);if(opts.fit&&opts.height&&opts.height!='auto')
$slides.height(opts.height);if(opts.pause)
$cont.hover(function(){this.cyclePause=1;},function(){this.cyclePause=0;});$.fn.cycle.transitions.fade($cont,$slides,opts);$slides.each(function(){var $el=$(this);this.cycleH=(opts.fit&&opts.height)?opts.height:$el.height();this.cycleW=(opts.fit&&opts.width)?opts.width:$el.width();});$slides.not(':eq('+first+')').css({opacity:0});if(opts.cssFirst)
$($slides[first]).css(opts.cssFirst);if(opts.timeout){if(opts.speed.constructor==String)
opts.speed={slow:600,fast:200}[opts.speed]||400;if(!opts.sync)
opts.speed=opts.speed/2;while((opts.timeout-opts.speed)<250)
opts.timeout+=opts.speed;}
opts.speedIn=opts.speed;opts.speedOut=opts.speed;opts.slideCount=els.length;opts.currSlide=first;opts.nextSlide=1;var e0=$slides[first];if(opts.before.length)
opts.before[0].apply(e0,[e0,e0,opts,true]);if(opts.after.length>1)
opts.after[1].apply(e0,[e0,e0,opts,true]);if(opts.click&&!opts.next)
opts.next=opts.click;if(opts.next)
$(opts.next).bind('click',function(){return advance(els,opts,opts.rev?-1:1)});if(opts.prev)
$(opts.prev).bind('click',function(){return advance(els,opts,opts.rev?1:-1)});if(opts.timeout)
this.cycleTimeout=setTimeout(function(){go(els,opts,0,!opts.rev)},opts.timeout+(opts.delay||0));});};function go(els,opts,manual,fwd){if(opts.busy)return;var p=els[0].parentNode,curr=els[opts.currSlide],next=els[opts.nextSlide];if(p.cycleTimeout===0&&!manual)
return;if(manual||!p.cyclePause){if(opts.before.length)
$.each(opts.before,function(i,o){o.apply(next,[curr,next,opts,fwd]);});var after=function(){if($.browser.msie)
this.style.removeAttribute('filter');$.each(opts.after,function(i,o){o.apply(next,[curr,next,opts,fwd]);});};if(opts.nextSlide!=opts.currSlide){opts.busy=1;$.fn.cycle.custom(curr,next,opts,after);}
var roll=(opts.nextSlide+1)==els.length;opts.nextSlide=roll?0:opts.nextSlide+1;opts.currSlide=roll?els.length-1:opts.nextSlide-1;}
if(opts.timeout)
p.cycleTimeout=setTimeout(function(){go(els,opts,0,!opts.rev)},opts.timeout);};function advance(els,opts,val){var p=els[0].parentNode,timeout=p.cycleTimeout;if(timeout){clearTimeout(timeout);p.cycleTimeout=0;}
opts.nextSlide=opts.currSlide+val;if(opts.nextSlide<0){opts.nextSlide=els.length-1;}
else if(opts.nextSlide>=els.length){opts.nextSlide=0;}
go(els,opts,1,val>=0);return false;};$.fn.cycle.custom=function(curr,next,opts,cb){var $l=$(curr),$n=$(next);$n.css({opacity:0});var fn=function(){$n.animate({opacity:1},opts.speedIn,opts.easeIn,cb)};$l.animate({opacity:0},opts.speedOut,opts.easeOut,function(){$l.css({display:'none'});if(!opts.sync)fn();});if(opts.sync)fn();};$.fn.cycle.transitions={fade:function($cont,$slides,opts){$slides.not(':eq(0)').css('opacity',0);opts.before.push(function(){$(this).show()});}};$.fn.cycle.ver=function(){return ver;};$.fn.cycle.defaults={timeout:4000,speed:1000,next:null,prev:null,before:null,after:null,height:'auto',sync:1,fit:0,pause:0,delay:0,slideExpr:null};})(jQuery);
 
/*
 * In-Field Label jQuery Plugin
 * http://fuelyourcoding.com/scripts/infield.html
 *
 * Copyright (c) 2009 Doug Neiner
 * Dual licensed under the MIT and GPL licenses.
 * Uses the same license as jQuery, see:
 * http://docs.jquery.com/License
 *
 * @version 0.1
 */
(function($){$.InFieldLabels=function(label,field,options){var base=this;base.$label=$(label);base.$field=$(field);base.$label.data("InFieldLabels",base);base.showing=true;base.init=function(){base.options=$.extend({},$.InFieldLabels.defaultOptions,options);base.$label.css('position','absolute');var fieldPosition=base.$field.position();base.$label.css({'left':fieldPosition.left,'top':fieldPosition.top}).addClass(base.options.labelClass);if(base.$field.val()!=""){base.$label.hide();base.showing=false;};base.$field.focus(function(){base.fadeOnFocus();}).blur(function(){base.checkForEmpty(true);}).bind('keydown.infieldlabel',function(e){base.hideOnChange(e);}).change(function(e){base.checkForEmpty();}).bind('onPropertyChange',function(){base.checkForEmpty();});};base.fadeOnFocus=function(){if(base.showing){base.setOpacity(base.options.fadeOpacity);};};base.setOpacity=function(opacity){base.$label.stop().animate({opacity:opacity},base.options.fadeDuration);base.showing=(opacity>0.0);};base.checkForEmpty=function(blur){if(base.$field.val()==""){base.prepForShow();base.setOpacity(blur?1.0:base.options.fadeOpacity);}else{base.setOpacity(0.0);};};base.prepForShow=function(e){if(!base.showing){base.$label.css({opacity:0.0}).show();base.$field.bind('keydown.infieldlabel',function(e){base.hideOnChange(e);});};};base.hideOnChange=function(e){if((e.keyCode==16)||(e.keyCode==9))return;if(base.showing){base.$label.hide();base.showing=false;};base.$field.unbind('keydown.infieldlabel');};base.init();};$.InFieldLabels.defaultOptions={fadeOpacity:0.5,fadeDuration:300,labelClass:'infield'};$.fn.inFieldLabels=function(options){return this.each(function(){var for_attr=$(this).attr('for');if(!for_attr)return;var $field=$("input#"+for_attr+"[type='text'],"+"input#"+for_attr+"[type='password'],"+"textarea#"+for_attr);if($field.length==0)return;(new $.InFieldLabels(this,$field[0],options));});};})(jQuery);

/**
 * jqFancyTransitions - jQuery plugin
 * @version: 1.8 (2010/06/13)
 * @requires jQuery v1.2.2 or later 
 * @author Ivan Lazarevic
 * Examples and documentation at: http://www.workshop.rs/projects/jqfancytransitions
 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
**/

(function($){var opts=new Array;var level=new Array;var img=new Array;var links=new Array;var titles=new Array;var order=new Array;var imgInc=new Array;var inc=new Array;var stripInt=new Array;var imgInt=new Array;$.fn.jqFancyTransitions=$.fn.jqfancytransitions=function(options){init=function(el){opts[el.id]=$.extend({},$.fn.jqFancyTransitions.defaults,options);img[el.id]=new Array();links[el.id]=new Array();titles[el.id]=new Array();order[el.id]=new Array();imgInc[el.id]=0;inc[el.id]=0;params=opts[el.id];if(params.effect=='zipper'){params.direction='alternate';params.position='alternate';}
if(params.effect=='wave'){params.direction='alternate';params.position='top';}
if(params.effect=='curtain'){params.direction='alternate';params.position='curtain';}
stripWidth=parseInt(params.width/params.strips);gap=params.width-stripWidth*params.strips;stripLeft=0;$.each($('#'+el.id+' img'),function(i,item){img[el.id][i]=$(item).attr('src');links[el.id][i]=$(item).next().attr('href');titles[el.id][i]=$(item).attr('alt')?$(item).attr('alt'):'';$(item).hide();});$('#'+el.id).css({'background-image':'url('+img[el.id][0]+')','width':params.width,'height':params.height,'position':'relative','background-position':'top left'});$('#'+el.id).append("<div class='ft-title' id='ft-title-"+el.id+"' style='position: absolute; bottom:0; left: 0; z-index: 1000; color: #fff; background-color: #000; '>"+titles[el.id][0]+"</div>");if(titles[el.id][imgInc[el.id]])
$('#ft-title-'+el.id).css('opacity',opts[el.id].titleOpacity);else
$('#ft-title-'+el.id).css('opacity',0);if(params.navigation){$.navigation(el);$('#ft-buttons-'+el.id).children().first().addClass('ft-button-'+el.id+'-active');}
odd=1;for(j=1;j<params.strips+1;j++){if(gap>0){tstripWidth=stripWidth+1;gap--;}else{tstripWidth=stripWidth;}
if(params.links)
$('#'+el.id).append("<a href='"+links[el.id][0]+"' class='ft-"+el.id+"' id='ft-"+el.id+j+"' style='width:"+tstripWidth+"px; height:"+params.height+"px; float: left; position: absolute;outline:none;'></a>");else
$('#'+el.id).append("<div class='ft-"+el.id+"' id='ft-"+el.id+j+"' style='width:"+tstripWidth+"px; height:"+params.height+"px; float: left; position: absolute;'></div>");$("#ft-"+el.id+j).css({'background-position':-stripLeft+'px top','left':stripLeft});stripLeft+=tstripWidth;if(params.position=='bottom')
$("#ft-"+el.id+j).css('bottom',0);if(j%2==0&&params.position=='alternate')
$("#ft-"+el.id+j).css('bottom',0);if(params.direction=='fountain'||params.direction=='fountainAlternate'){order[el.id][j-1]=parseInt(params.strips/2)-(parseInt(j/2)*odd);order[el.id][params.strips-1]=params.strips;odd*=-1;}else{order[el.id][j-1]=j;}}
$('.ft-'+el.id).mouseover(function(){opts[el.id].pause=true;});$('.ft-'+el.id).mouseout(function(){opts[el.id].pause=false;});$('#ft-title-'+el.id).mouseover(function(){opts[el.id].pause=true;});$('#ft-title-'+el.id).mouseout(function(){opts[el.id].pause=false;});clearInterval(imgInt[el.id]);imgInt[el.id]=setInterval(function(){$.transition(el)},params.delay+params.stripDelay*params.strips);};$.transition=function(el,direction){if(opts[el.id].pause==true)return;stripInt[el.id]=setInterval(function(){$.strips(order[el.id][inc[el.id]],el)},opts[el.id].stripDelay);$('#'+el.id).css({'background-image':'url('+img[el.id][imgInc[el.id]]+')'});if(typeof(direction)=="undefined")
imgInc[el.id]++;else
if(direction=='prev')
imgInc[el.id]--;else
imgInc[el.id]=direction;if(imgInc[el.id]==img[el.id].length){imgInc[el.id]=0;}
if(imgInc[el.id]==-1){imgInc[el.id]=img[el.id].length-1;}
if(titles[el.id][imgInc[el.id]]!=''){$('#ft-title-'+el.id).animate({opacity:0},opts[el.id].titleSpeed,function(){$(this).html(titles[el.id][imgInc[el.id]]).animate({opacity:opts[el.id].titleOpacity},opts[el.id].titleSpeed);});}else{$('#ft-title-'+el.id).animate({opacity:0},opts[el.id].titleSpeed);}
inc[el.id]=0;buttons=$('#ft-buttons-'+el.id).children();buttons.each(function(index){if(index==imgInc[el.id]){$(this).addClass('ft-button-'+el.id+'-active');}else{$(this).removeClass('ft-button-'+el.id+'-active');}});if(opts[el.id].direction=='random')
$.fisherYates(order[el.id]);if((opts[el.id].direction=='right'&&order[el.id][0]==1)||opts[el.id].direction=='alternate'||opts[el.id].direction=='fountainAlternate')
order[el.id].reverse();};$.strips=function(itemId,el){temp=opts[el.id].strips;if(inc[el.id]==temp){clearInterval(stripInt[el.id]);return;}
$('.ft-'+el.id).attr('href',links[el.id][imgInc[el.id]]);if(opts[el.id].position=='curtain'){currWidth=$('#ft-'+el.id+itemId).width();$('#ft-'+el.id+itemId).css({width:0,opacity:0,'background-image':'url('+img[el.id][imgInc[el.id]]+')'});$('#ft-'+el.id+itemId).animate({width:currWidth,opacity:1},1000);}else{$('#ft-'+el.id+itemId).css({height:0,opacity:0,'background-image':'url('+img[el.id][imgInc[el.id]]+')'});$('#ft-'+el.id+itemId).animate({height:opts[el.id].height,opacity:1},1000);}
inc[el.id]++;};$.navigation=function(el){$('#'+el.id).append("<a href='#' id='ft-prev-"+el.id+"' class='ft-prev'>prev</a>");$('#'+el.id).append("<a href='#' id='ft-next-"+el.id+"' class='ft-next'>next</a>");$('#ft-prev-'+el.id).css({'position':'absolute','top':params.height/2-15,'left':0,'z-index':1001,'line-height':'30px','opacity':0.7}).click(function(e){e.preventDefault();$.transition(el,'prev');clearInterval(imgInt[el.id]);imgInt[el.id]=setInterval(function(){$.transition(el)},params.delay+params.stripDelay*params.strips);});$('#ft-next-'+el.id).css({'position':'absolute','top':params.height/2-15,'right':0,'z-index':1001,'line-height':'30px','opacity':0.7}).click(function(e){e.preventDefault();$.transition(el);clearInterval(imgInt[el.id]);imgInt[el.id]=setInterval(function(){$.transition(el)},params.delay+params.stripDelay*params.strips);});$("<div id='ft-buttons-"+el.id+"'></div>").insertAfter($('#'+el.id));$('#ft-buttons-'+el.id).css({'text-align':'right','padding-top':5,'width':opts[el.id].width});for(k=1;k<img[el.id].length+1;k++){$('#ft-buttons-'+el.id).append("<a href='#' class='ft-button-"+el.id+"'>"+k+"</a>");}
$('.ft-button-'+el.id).css({'padding':5});$.each($('.ft-button-'+el.id),function(i,item){$(item).click(function(e){e.preventDefault();$.transition(el,i);clearInterval(imgInt[el.id]);imgInt[el.id]=setInterval(function(){$.transition(el)},params.delay+params.stripDelay*params.strips);})});}
$.fisherYates=function(arr){var i=arr.length;if(i==0)return false;while(--i){var j=Math.floor(Math.random()*(i+1));var tempi=arr[i];var tempj=arr[j];arr[i]=tempj;arr[j]=tempi;}}
this.each(function(){init(this);});};$.fn.jqFancyTransitions.defaults={width:500,height:332,strips:10,delay:5000,stripDelay:50,titleOpacity:0.7,titleSpeed:1000,position:'alternate',direction:'fountainAlternate',effect:'',navigation:false,links:false};})(jQuery);
