// JavaScript Document

$(document).ready(function() {

    $('#vivaFlash').click( function () {
    closeVivaFlash();

    })


    $('a[href^="http"]').each(function () {
      if (($(this).attr('class') != 'button01') && ($(this).attr('class') != 'button02') && ($(this).attr('class') != 'button05') && ($(this).attr('class') != 'fb') && ($(this).attr('class') != 'tw') && ($(this).attr('class') != 'shareFB') && ($(this).attr('class') != 'gp') && ($(this).attr('class') != 'shareTW') ) {
        $(this).addClass('newWindow').append("<span></span>");
      }
    });


    $('a[href^="http"]').click( function () {
        window.open ($(this).attr('href'),"");
       return false;
    }


            );

    $('<span id="nav" class="nav"><span></span></span>').appendTo(".changeImageArea");
    $(function() {
      $('#fade img:first').fadeIn(1000, function() {
          $('#fade').cycle({
          pager:  '#nav',
          timeout: 8000
          });
      });
    });

    /* Contact forms */
    $('div.contactForm ul li a').click(function() {
        var selectedForm = $(this).attr('class');
        if ($(this).parent('li').attr('class') == "selected") {
            $('form#form01').slideUp("fast", function() {
                $('div.contactForm ul li').removeClass("selected");
                $('.'+selectedForm).parent('li').siblings().removeClass("selected");
            });
        } else {
                $('.'+selectedForm).parent('li').addClass("selected");
                $('.'+selectedForm).parent('li').siblings().removeClass("selected");
                $('div.contactForm form#form01').slideDown("fast");

        }
        return false;
    });

    // Mazání defaultnich poli formulare
    $('div.contactForm.contactPage #name-1, div.contactForm.contactPage #name-2, .formHero #name-1, .formHero #name-2').focus(
        function() {
            var val = $(this).val();
            if ($(this).val() == 'Vaše jméno') {
                $(this).val('');
            }
        }
    );
    $('div.contactForm.contactPage #name-1, div.contactForm.contactPage #name-2, .formHero #name-1, .formHero #name-2').blur(
        function() {
            if ($(this).val() == '') {
                $(this).val('Vaše jméno');
            }
        }
    );

    $('div.contactForm.contactPage #mail-1, .formHero #mail-1').focus(
        function() {
            var val = $(this).val();
            if ($(this).val() == 'Váš email') {
                $(this).val('');
            }
        }
    );
    $('div.contactForm.contactPage #mail-1, .formHero #mail-1').blur(
        function() {
            if ($(this).val() == '') {
                $(this).val('Váš email');
            }
        }
    );

    $('div.contactForm.contactPage #phone-2, .formHero #phone-2').focus(
        function() {
            var val = $(this).val();
            if ($(this).val() == 'Váš telefon') {
                $(this).val('');
            }
        }
    );
    $('div.contactForm.contactPage #phone-2, .formHero #phone-2').blur(
        function() {
            if ($(this).val() == '') {
                $(this).val('Váš telefon');
            }
        }
    );

    $('div.contactForm.contactPage #text-1, .formHero #text-1').focus(
        function() {
            var val = $(this).val();
            if ($(this).val() == 'Vaše zpráva') {
                $(this).val('');
            }
        }
    );
    $('div.contactForm.contactPage #text-1, .formHero #text-1').blur(
        function() {
            if ($(this).val() == '') {
                $(this).val('Vaše zpráva');
            }
        }
    );
    
    

    // Mazání defaultnich poli formulare
    $('body.en div.contactForm.contactPage #name-1, body.en div.contactForm.contactPage #name-2, body.en .formHero #name-1, body.en .formHero #name-2').focus(
        function() {
            var val = $(this).val();
            if ($(this).val() == 'Name') {
                $(this).val('');
            }
        }
    );
    $('body.en div.contactForm.contactPage #name-1, body.en div.contactForm.contactPage #name-2, body.en .formHero #name-1, body.en .formHero #name-2').blur(
        function() {
            if ($(this).val() == '') {
                $(this).val('Name');
            }
        }
    );

    $('body.en div.contactForm.contactPage #mail-1, body.en .formHero #mail-1').focus(
        function() {
            var val = $(this).val();
            if ($(this).val() == 'E-mail') {
                $(this).val('');
            }
        }
    );
    $('body.en div.contactForm.contactPage #mail-1, body.en .formHero #mail-1').blur(
        function() {
            if ($(this).val() == '') {
                $(this).val('E-mail');
            }
        }
    );

    $('body.en div.contactForm.contactPage #text-1, body.en .formHero #text-1').focus(
        function() {
            var val = $(this).val();
            if ($(this).val() == 'Message') {
                $(this).val('');
            }
        }
    );
    $('body.en div.contactForm.contactPage #text-1, body.en .formHero #text-1').blur(
        function() {
            if ($(this).val() == '') {
                $(this).val('Message');
            }
        }
    );
    
    

    /* Tooltips */
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    }
    $('img.Webtop100, #tooltipWEBTOP100').mouseenter(function() {
        $('#tooltipWEBTOP100').css("left",(myWidth/2+240)+"px").show();
    });
    $('img.Webtop100, #tooltipWEBTOP100').mouseleave(function() {
        $('#tooltipWEBTOP100').hide();
    });
    $('img.IEA10, #tooltipIEA2010').mouseenter(function() {
        $('#tooltipIEA2010').css("left",(myWidth/2+240)+"px").show();
    });
    $('img.IEA10, #tooltipIEA2010').mouseleave(function() {
        $('#tooltipIEA2010').hide();
    });
    $('img.IEA11, #tooltipIEA2011').mouseenter(function() {
        $('#tooltipIEA2011').css("left",(myWidth/2+240)+"px").show();
    });
    $('img.IEA11, #tooltipIEA2011').mouseleave(function() {
        $('#tooltipIEA2011').hide();
    });



    
    $("#referenceContainer a img").each(function (i) {
          var string = ($(this).attr('src'));
          $(this).clone().appendTo($(this).parent('.imgCont')).addClass('clone').attr('src', string.replace(".jpg", "-over.jpg"));
    });    
    
    $("#referenceContainer a IMG.clone").hide();
    /*$("#referenceContainer a IMG.clone").desaturate().hide();*/


var isiOS = false;
var agent = navigator.userAgent.toLowerCase();
if(agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0){
       isiOS = true;
}
if (!isiOS) {
    $('#referenceContainer a').mouseenter(function() {
        $(this).children('span').stop(false, false).show().fadeTo(200, 1);
        $(this).children('em').children('img.clone').stop(false, false).fadeTo(500, 1);
    });
    $('#referenceContainer a').mouseleave(function() {
        $(this).children('span').stop(false, false).show().fadeTo(200, 0);
        $(this).children('em').children('img.clone').stop(false, false).fadeTo(500, 0);
    });
    
    $('#referenceContainer a img').click(function() {
       window.location = $(this).parent('em').parent('a').attr('href');
    });


    $('a.img').mouseenter(function() {
        $(this).children('span').stop(false, false).show().fadeTo(200, 1);
    });
    $('a.img').mouseleave(function() {
        $(this).children('span').stop(false, false).show().fadeTo(200, 0);
    });
}


 

    
//    if ($(".matrKontakt").height() > 0 ) {
//      $('span#delnicka, #maniny, #u-pruhonu, #ortenovo-nam').tooltip();
//    }
});
