/* 
 @author Martin Kluska <martin@kluska.cz> 
 */

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
var i = 0;
var interval;
function dot(moto) {
  
  $('#moto').html($('#moto').html()+'.');
  i++;
  if (i==3) {
    clearInterval(interval);
    i=0;
  }
}
function motoStart(moto) {
      var delay = 1500;
	  
      moto.css('left','-150px');
      moto.css('display','none');
			 moto.html('Už nemusíte hledat!');
			  interval = setInterval('dot()',250);
			  moto.fadeIn(500).delay(delay).animate({'left':'120px'},1000).fadeOut(500,function(){
				moto.text('My máme řešení!');
				moto.fadeIn(500).delay(delay).animate({'left':'0px'},500).fadeOut(500,function(){
					moto.css('left','-100px');
					moto.text('Nechte vyvolat vaše fotografie profesionály!');
					moto.fadeIn(500).delay(delay).fadeOut(500,function(){
					moto.css('left','-130px');
						moto.html('Není nic jednodušího...<br/>Než využít Naši elektronickou fotosběrnu!');
						moto.fadeIn(500).delay(2500).fadeOut(500,function() {
						  moto.html('Stačí vybrat fotografie a odeslat Vaši objednávku!');                  
						  moto.fadeIn(500).delay(delay).fadeOut(500,function(){
							moto.delay(1000);
							motoStart(moto);
						  });
						});
						
					});
				});;
			  });
}

$(document).ready(function() {    

    $('#update').click(function(e) {        
        $('form[name=updateF]').submit();
    });

    $('#objPot').click(function(e) {
        var ok = true;
        var i = 1;
        var allOk = true;

        while (ok) {
            if ($('#fill'+i).length !=0) {
                Iname = $('#fill'+i).attr("name");
                document.getElementById(Iname).textContent = '';

                if ($('#fill'+i).val()=='') {
                    allOk = false;
                    document.getElementById(Iname).textContent = 'Toto pole musí být vyplněno!';
                }
                i++;
            } else {
                ok = false;
            }
            if (i==7) {
                i++;
                if ($('#fill'+i).length !=0) {
                    if ($('#fill'+i).val()=='') {
                        ok=false;
                    }
                }
            }
            if (i==10) {
                i++;
            }
        }
        if (allOk) {
            $('form[name=objForm]').submit();
        }
    });
    
    $('#submit').click(function(e) {
        
        if (!isValidEmailAddress($('#email').val())) {
            $('#status').text('Není validní emailová adresa!');
            e.preventDefault();
            
        }
    });
    
    var moto = $('#moto');
    if (moto.length>0) {
      motoStart(moto);
    }
   
});
/* Martin Halík */


window.onerror=function(desc,page,line,chr){
/* alert('JavaScript error occurred! \n'
  +'\nError description: \t'+desc
  +'\nPage address:      \t'+page
  +'\nLine number:       \t'+line
 );*/
}

$(function(){
 $('a').focus(function(){this.blur();});
 SI.Files.stylizeAll();
 slider.init();

 $('input.text-default').each(function(){
  $(this).attr('default',$(this).val());
 }).focus(function(){
  if($(this).val()==$(this).attr('default'))
   $(this).val('');
 }).blur(function(){
  if($(this).val()=='')
   $(this).val($(this).attr('default'));
 });

 $('input.text,textarea.text').focus(function(){
  $(this).addClass('textfocus');
 }).blur(function(){
  $(this).removeClass('textfocus');
 });

 var popopenobj=0,popopenaobj=null;
 $('a.popup').click(function(){
  var pid=$(this).attr('rel').split('|')[0],_os=parseInt($(this).attr('rel').split('|')[1]);
  var pobj=$('#'+pid);
  if(!pobj.length)
   return false;
  if(typeof popopenobj=='object' && popopenobj.attr('id')!=pid){
   popopenobj.hide(50);
   $(popopenaobj).parent().removeClass(popopenobj.attr('id').split('-')[1]+'-open');
   popopenobj=null;
  }
  return false;
 });
 $('p.images img').click(function(){
  var newbg=$(this).attr('src').split('bg/bg')[1].split('-thumb')[0];
  $(document.body).css('backgroundImage','url('+_siteRoot+'images/bg/bg'+newbg+'.jpg)');

  $(this).parent().find('img').removeClass('on');
  $(this).addClass('on');
  return false;
 });
 
 $('div.sc-large div.img:has(div.tml)').each(function(){
  $('div.tml',this).hide();
  $(this).append('<a href="#" class="tml_open">&nbsp;</a>').find('a').css({
   left:parseInt($(this).offset().left)+864,top:parseInt($(this).offset().top)+1
  }).click(function(){
   $(this).siblings('div.tml').slideToggle();
   return false;
  }).focus(function(){this.blur();});
 });
});
var slider={
 num:-1,
 cur:0,
 cr:[],
 al:null,
 at:4*1000,
 ar:true,
 init:function(){
  if(!slider.data || !slider.data.length)
   return false;

  var d=slider.data;
  slider.num=d.length;
  var pos=Math.floor(Math.random()*1);//slider.num);
  for(var i=0;i<slider.num;i++){
   $('#'+d[i].id).css({left:((i-pos)*1000)});
   $('#slide-nav').append('<a id="slide-link-'+i+'" href="#" onclick="slider.slide('+i+');return false;" onfocus="this.blur();">'+(i+1)+'</a>');
  }

  $('img,div#slide-controls',$('div#slide-holder')).fadeIn();
  slider.text(d[pos]);
  slider.on(pos);
  slider.cur=pos;
  window.setTimeout('slider.auto();',slider.at);
 },
 auto:function(){
  if(!slider.ar)
   return false;

  var next=slider.cur+1;
  if(next>=slider.num) next=0;
  slider.slide(next);
 },
 slide:function(pos){
  if(pos<0 || pos>=slider.num || pos==slider.cur)
   return;

  window.clearTimeout(slider.al);
  slider.al=window.setTimeout('slider.auto();',slider.at);

  var d=slider.data;
  for(var i=0;i<slider.num;i++)
   $('#'+d[i].id).stop().animate({left:((i-pos)*1000)},1000,'swing');

  slider.on(pos);
  slider.text(d[pos]);
  slider.cur=pos;
 },
 on:function(pos){
  $('#slide-nav a').removeClass('on');
  $('#slide-nav a#slide-link-'+pos).addClass('on');
 },
 text:function(di){
  slider.cr['a']=di.client;
  slider.cr['b']=di.desc;
  slider.ticker('#slide-client span',di.client,0,'a');
  slider.ticker('#slide-desc',di.desc,0,'b');
 },
 ticker:function(el,text,pos,unique){
  if(slider.cr[unique]!=text)
   return false;

  ctext=text.substring(0,pos)+(pos%2?'-':'_');
  $(el).html(ctext);

  if(pos==text.length)
   $(el).html(text);
  else
   window.setTimeout('slider.ticker("'+el+'","'+text+'",'+(pos+1)+',"'+unique+'");',10);
 }
};

// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if(!window.SI){var SI={};};
SI.Files={
 htmlClass:'SI-FILES-STYLIZED',
 fileClass:'file',
 wrapClass:'cabinet',

 fini:false,
 able:false,
 init:function(){
  this.fini=true;
 },
 stylize:function(elem){
  if(!this.fini){this.init();};
  if(!this.able){return;};

  elem.parentNode.file=elem;
  elem.parentNode.onmousemove=function(e){
   if(typeof e=='undefined') e=window.event;
   if(typeof e.pageY=='undefined' &&  typeof e.clientX=='number' && document.documentElement){
    e.pageX=e.clientX+document.documentElement.scrollLeft;
    e.pageY=e.clientY+document.documentElement.scrollTop;
   };
   var ox=oy=0;
   var elem=this;
   if(elem.offsetParent){
    ox=elem.offsetLeft;
    oy=elem.offsetTop;
    while(elem=elem.offsetParent){
     ox+=elem.offsetLeft;
     oy+=elem.offsetTop;
    };
   };
  };
 },
 stylizeAll:function(){
  if(!this.fini){this.init();};
  if(!this.able){return;};
 }
};

