$(document).ready(function() {
  $(".aboutus").hide();

  $('#mydialog').dialog({				
		autoOpen: false,
		modal: true,
		width: 300,
		resizable: false,
		buttons: {
		    "OK": function(){
			    $(this).dialog('close');
		    }
		}
	});
	$('#mydialogko').dialog({
		autoOpen: false,
		modal: true,
		width: 300,
		resizable: false,		
		buttons: {
		    "OK": function(){
			    $(this).dialog('close');
		    }
		}
	});

    //google maps
    var myLatlng = new google.maps.LatLng(50.058172,14.444731);
    var myOptions = {
      zoom: 16,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title:"1. Pozitivní - komunikační agentura, www.1pozitivni.cz"
    });

/* SlideEffect */
  $(".slddown").delay(500).animate({width: 'toggle'}, 'slow');

 // Prevezme text z elementu label
	var labelTxt = $('#header form label').text();

	// Prida text z elementu label do vyhlevaciho pole - value
	$('#search-input').attr('value',labelTxt);

	// Focus & blur efekty
	$('#search-input').focus(function(){
		if ((this.value == '') || (this.value == labelTxt)) {
			$(this).val('');
			$(this).addClass('focus');
		}
	});
	$('#search-input').blur(function(){
		if (this.value == '') {
			$(this).val(labelTxt);
			$(this).removeClass('focus');
		}
	});
	var frmJmeno = 'jméno';

	// Prida text z elementu label do vyhlevaciho pole - value
	$('#formjmeno').attr('value',frmJmeno);

	// Focus & blur efekty
	$('#formjmeno').focus(function(){
		if ((this.value == '') || (this.value == frmJmeno)) {
			$(this).val('');
			$(this).addClass('focus');
			$(this).css('color', 'black');
		}
	});
	$('#formjmeno').blur(function(){
		if (this.value == '') {
			$(this).val(frmJmeno);
			$(this).removeClass('focus');
			$(this).css('color', '#A7A7A7');
		}
	});
	var frmTel = 'telefon';

	// Prida text z elementu label do vyhlevaciho pole - value
	$('#formtel').attr('value',frmTel);

	// Focus & blur efekty
	$('#formtel').focus(function(){
		if ((this.value == '') || (this.value == frmTel)) {
			$(this).val('');
			$(this).addClass('focus');
			$(this).css('color', 'black');
		}
	});
	$('#formtel').blur(function(){
		if (this.value == '') {
			$(this).val(frmTel);
			$(this).removeClass('focus');
			$(this).css('color', '#A7A7A7');
		}
	});
	var frmMail = 'email';

	// Prida text z elementu label do vyhlevaciho pole - value
	$('#formmail').attr('value',frmMail);

	// Focus & blur efekty
	$('#formmail').focus(function(){
		if ((this.value == '') || (this.value == frmMail)) {
			$(this).val('');
			$(this).addClass('focus');
			$(this).css('color', 'black');
		}
	});
	$('#formmail').blur(function(){
		if (this.value == '') {
			$(this).val(frmMail);
			$(this).removeClass('focus');
			$(this).css('color', '#A7A7A7');
		}
	});
	$('#formSubmit').click(function()
	{	    
	    var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	    var phoneReg = /^[0-9]{9}/;
	    if (emailReg.test($('#formmail').val()) && phoneReg.test($('#formtel').val()))
		{
		    $('#mydialog').dialog('open');
		    //alert("Vaše zpráva byla úspěšně odeslána.");
		    return true;
		}
	    else
		{
		    $('#mydialogko').dialog('open');
		    //alert("Údaje nejsou správně vyplněny.");
		    return false;
		}
		//return false;
	});

  //No display for label
  $('#header form label:first').css({display: "none"});

  $('.hp').prepend("<div class='ie-bg'></div>");
  
  /* PNG fix for IE6  */
  if($.browser.msie && $.browser.version=="6.0") DD_belatedPNG.fix('.ie-bg');
  
  //------------------------------------------- news rotator
  
   var headline_count;
   var headline_interval;
   var old_headline = 0;
   var current_headline = 0;
   
   $(document).ready(function(){
     headline_count = $("div.headline").size();
     $("div.headline:eq("+current_headline+")").css('top','10px');
   
     headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
     $('#newsscroller').hover(function() {
       clearInterval(headline_interval);
     }, function() {
       headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
       headline_rotate();
     });
   });
   
   function headline_rotate() {
     current_headline = (old_headline + 1) % headline_count; 
     $("div.headline:eq(" + old_headline + ")").animate({top: -130},"slow", function() {
       $(this).css('top','130px');
     });
     $("div.headline:eq(" + current_headline + ")").show().animate({top: 10},"slow");  
     old_headline = current_headline;
   }   
    
   //---------------------------------------- end of news rotator 
  
  
	
  /* Cufon replacement */
  //Cufon.replace("body");
  Cufon.replace('.thumbNav a, .bottom h2, .bottom2 h2, .bottom3 h2, .bottom4 h2, .bottom5 h2, .bottom6 h2, .bottom7 h2, .bottom8 h2, #content .content h1, #content .maintext p, .submenu li a, #content .maintext li, .bubble p, .bubblehp p,.maintextCitat,.maintext,.rightnasilide, .toggle, .lang span, .lang a, #pfooter, #ulfooter, #mydialogko p, #mydialog p, .rightdetfir a', {fontFamily: 'Juvenis'});
  Cufon.replace('strong, .bottom h2, .bottom2 h2, .bottom3 h2, .bottom4 h2, .bottom5 h2, .bottom6 h2, .bottom7 h2, .bottom8 h2, #content .content h1, .maintext .right strong, .maintext .left strong, .bubble strong,.bubblebez strong, .bubblehp strong, #content .maintext li strong', {fontFamily: 'Juvenis Text', fontWeight: 700});

  FancyBox();

    $("a[id=ahrefhomeNews]").click(function(){
	$("div[id=divhomeToggleNews]").toggle("slow");
    });

    $("a[id=ahrefkontHomePage]").click(function(){
	$('#slider2').anythingSlider(9);
	$(".hiddenhome").show();
	$(".hiddenkontakty").hide();
    });

    $("a[id=ahrefUvodHomePage]").click(function(){
	$('#slider2').anythingSlider(1);
	$(".hiddenhome").hide();
	$(".hiddenkontakty").show();
    });
    
    
  
    
});


function NactiUvod() {
   $("div[id=obsah01]").load("/loadhome", function() {
	FancyBox();
	 Cufon.replace('.bubblehp p', {fontFamily: 'Juvenis'});
    });
   $("li[id=idPanel01]").css("background-image",'url(gfx/home-bg.jpg)');   
}
function FancyBox()
{
    /* fancybox */
    $("a[rel=imgrefhome]").fancybox({
	'onComplete'	:	function() {
	    var winHeight = winH();
	    if ((winHeight < 590) && (	winHeight>1))
		{
		    $("#fancybox-wrap").css('top','5px');
		    $('#fancybox-content').height(winHeight * 0.7);
		}
	}
    });
    $("a[rel=imgrefbrana]").fancybox({
	'onComplete'	:	function() {
	    var winHeight = winH();
	    if ((winHeight < 590) && (	winHeight>1))
		{
		    $("#fancybox-wrap").css('top','5px');
		    $('#fancybox-content').height(winHeight * 0.7);
		}
	}
    });
    $("a[rel=imgref]").fancybox({
	'onComplete'	:	function() {
	    var winHeight = winH();
	    if ((winHeight < 590) && (	winHeight>1))
		{
		    $("#fancybox-wrap").css('top','5px');
		    $('#fancybox-content').height(winHeight * 0.7);
		}
	}
    });
}
function winH() {
   if (window.innerHeight)
      /* NN4 a kompatibilní prohlížeče */
      return window.innerHeight;
   else if
   (document.documentElement &&
   document.documentElement.clientHeight)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerHeight */
      return document.documentElement.clientHeight;
   else if
   (document.body && document.body.clientHeight)
      /* starší MSIE + MSIE6 v quirk režimu */
      return document.body.clientHeight;
   else
      return null;
}

