$('html').addClass('js');

$(document).ready(function(){
	$('.hr .banner.heart_of_croatia').hide();
});


//HEADER SLIDESHOW
$(document).ready(function(){
	$('#content-head').cycle({
		fx: 'fade',
		timeout: 4000,
	});
});

//SELECT REPLACE
$(document).ready(function(){
    $('select.mightySelect').not('[multiple]').each(function(){
        $(this).hide().after('<span class="sel-replaced'+(($(this).is(".off"))?" off":"")+' '+$(this).attr('name')+' '+$(this).attr('class')+'"><span>'+$(this).find('option:selected').text()+'</span></span>');
    });
    $('select[multiple].mightySelect').each(function(){
        $(this).hide().after('<span class="sel-replaced'+(($(this).is(".off"))?" off":"")+' '+$(this).attr('name')+' '+$(this).attr('class')+'"><span>'+$(this).find('option:selected').text()+'</span></span>');
    });
    $('.sel-replaced').mightySelect('advanced','');
});

$(function(){

  $('.form-t02 label').inFieldLabels({ fadeOpacity:0, fadeDuration:100 });
  
  
  
  
  //************************ Datepicker ***/
  $.datepicker.regional['hr'] = {
		closeText: 'Zatvori',
		prevText: '&#x3c;',
		nextText: '&#x3e;',
		currentText: 'Danas',
		monthNames: ['Siječanj','Veljača','Ožujak','Travanj','Svibanj','Lipani',
		'Srpanj','Kolovoz','Rujan','Listopad','Studeni','Prosinac'],
		monthNamesShort: ['Sij','Velj','Ožu','Tra','Svi','Lip',
		'Srp','Kol','Ruj','Lis','Stu','Pro'],
		dayNames: ['Nedjalja','Ponedjeljak','Utorak','Srijeda','Četvrtak','Petak','Subota'],
		dayNamesShort: ['Ned','Pon','Uto','Sri','Čet','Pet','Sub'],
		dayNamesMin: ['Ne','Po','Ut','Sr','Če','Pe','Su'],
		firstDay: 1,
		isRTL: false};
  
  $('.datepicker').datepicker($.extend({
    dateFormat: 'yy-mm-dd', 
    showOn: 'both', 
    buttonImage: phrasebook.URLROOT+'/images/btn-datepicker.png',
    buttonText: phrasebook.lbl_calendar,
    buttonImageOnly: true
  }, $.datepicker.regional[phrasebook.lang]));
  
  $('#form-reservations-steps .date').datepicker($.extend({
    dateFormat: 'dd.mm.yy', 
    showOn: 'both', 
    buttonImage: phrasebook.URLROOT+'/images/btn-datepicker.png',
    buttonText: phrasebook.lbl_calendar,
    buttonImageOnly: true,
    onSelect: function(dateText, inst){
        var day = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay);
        day.setDate(day.getDate()+1);
        var nextInput = $(this).closest("div").next("div").find(".date");
        if(nextInput.val()==""){
            nextInput.val(addZero(day.getDate())+"."+addZero(day.getMonth()+1)+"."+day.getFullYear());
        }
    }
  }, $.datepicker.regional[phrasebook.lang]));
  
  
  function addZero(num){
      if(num<10){ num = "0"+num; }
      return num;
  }
  
});

$(document).ready(function() {

	$("#f-childrenNum_form").change(function(){
		var num = $("option:selected", this).text();
		
		$("#starost-display").css("visibility", "visible");
		$("#add-more-children").html("");
		
		for(var i=1; i<=num; i++) {
			var app = '<div class="inline"><label>Dijete '+i+'</label><select name="dijete['+i+']">'+$("#clone-select").html()+'</select></div>';
			$("#add-more-children").append(app);
		}
	});
	
});

//************************ Image gallery ***/
$(function(){

  var slide = $('#img-gallery li').outerWidth(true);
  var slideContainer = $('#img-gallery ul');
  
  $('#img-gallery ul').css({'width':slide*$('#img-gallery li').length});
  
  $('#img-gallery li:first-child').addClass('active first-visible');
  $('#img-gallery li:nth-child(6)').addClass('last-visible');
  $('#img-gallery li a').click(function(){
    $(this).parent().addClass('active').siblings().removeClass('active');
    updateHolder();
    return false;
  });
  
  $('#img-gallery').append('<div class="controls"><a class="prev">'+phrasebook.lbl_prev+'</a><a class="next">'+phrasebook.lbl_next+'</a></div>');
  $('#img-gallery .controls a').click(function(){ sliderControls( $(this).attr('class') ) });
  
  function updateHolder() {
    var imgLink = $('#img-gallery .active a');
    var imgBig = $('#content-head.img-holder img');
    $('#content-head.img-holder').addClass('loading');
    if ( imgBig.attr('src') !== imgLink ) {  
      imgBig.animate({ opacity: 0 }, function(){
        var img = new Image();
        $(img).load(function(){   
          $(this).css({opacity: 0});
          $('#content-head.img-holder').removeClass('loading').html(this);
          $(this).animate({opacity: 1});
        }).error(function(){}).attr({src: imgLink.attr('href'), alt: imgLink.children().attr('alt') });
      });
    }
  }
  function sliderControls(sliderControl){
    if (sliderControl === 'next') {
      $('#img-gallery .active').removeClass('active').next().addClass('active');
      if ( $('#img-gallery .active').prev().hasClass('last-visible') ) {
        $('#img-gallery .last-visible').removeClass('last-visible').next().addClass('last-visible');
        $('#img-gallery .first-visible').removeClass('first-visible').next().addClass('first-visible');
        slideContainer.animate({ marginLeft: -(slide-parseInt(slideContainer.css('margin-left'))) });
      } else if ( $('#img-gallery .active').prevAll().length === 0 ) {
        $('#img-gallery li:first-child').addClass('active first-visible').siblings().removeClass('active first-visible');
        $('#img-gallery li:nth-child(6)').addClass('last-visible').siblings().removeClass('last-visible');
        slideContainer.animate({ marginLeft: 0 });
      }
      updateHolder();
    } else if (sliderControl === 'prev') {
      $('#img-gallery .active').removeClass('active').prev().addClass('active');
      if ( $('#img-gallery .active').next().hasClass('first-visible') ) {
        $('#img-gallery .first-visible').removeClass('first-visible').prev().addClass('first-visible');
        $('#img-gallery .last-visible').removeClass('last-visible').prev().addClass('last-visible');
        slideContainer.animate({ marginLeft: parseInt(slideContainer.css('margin-left'))+slide });
      } else if ( $('#img-gallery .active').nextAll().length === 0 ) {
        $('#img-gallery li:last-child').addClass('active last-visible').siblings().removeClass('active last-visible');
        $('#img-gallery li:eq('+($('#img-gallery li').prevAll().length-(6-1))+')').addClass('first-visible').siblings().removeClass('first-visible');
        if ($('#img-gallery li').length >= 6){
          slideContainer.animate({ marginLeft: -(slide*($('#img-gallery li:last-child').prevAll().length-(6-1))) });
        }
      }
      updateHolder();
    }
  }
  
});




/************************ Slideshow 01 **
$(function(){
  var slide = $('#slideshow-t01 .inner');
  var slideWidth = slide.outerWidth(true);
  var slideContainer = $('#slideshow-t01 .holder');
  $('#slideshow-t01 .title em:first').addClass("active");
  slideContainer.css({'width':slideWidth*slide.length}); 
  $('#slideshow-t01 > ul li').click(function(){ slideshowControl($(this)); clearInterval(slideInterval); });    $('#slideshow-t01 .order_voucher').click(function(){ clearInterval(slideInterval); });    var slideInterval = setInterval(function(){ slideshowControl($('#slideshow-t01 > ul .active').next()) },4350);    function slideshowControl(slide) {    var slideIndex = slide.prevAll().length;    if ( slideIndex === 0 ) { slide = $('#slideshow-t01 > ul li:first'); }    $('#slideshow-t01 .title em:eq('+slideIndex+')').addClass('active').siblings('em').removeClass('active');    slide.addClass('active').siblings().removeClass('active');    slideContainer.animate({'margin-left':-(slideWidth*slideIndex)},580);  }
});
*/


//************************ Slideshow 02 ***/
$(function(){

  $('#slideshow-t02 img').each(function(i){ $(this).attr('rel',''+parseInt(i+1)); });
  
  $('#slideshow-t02 .info').append('<div class="controls"><a class="pause">Play/pause</a><a class="prev">'+phrasebook.lbl_prev+'</a><a class="next">'+phrasebook.lbl_next+'</a></div>');
  
  $('#slideshow-t02 .prev').after('<span class="amount"><span/>/'+$('#slideshow-t02 img').length+'</span>');
  $('#slideshow-t02 .amount span').html($("#slideshow-t02 img.active").attr('rel'));
  
  if($("#slideshow-t02 img.active").attr("alt")!=""){ $("#slideshow-t02 .info em").text($("#slideshow-t02 img.active").attr("alt")); }
  
  var slideImgInterval = setInterval("slideImg('next')", 5000 );
  
  $("#slideshow-t02 .pause").toggle(function(){
      clearInterval(slideImgInterval);
      $(this).removeClass('pause').addClass("play");
  },function(){
      slideImgInterval = setInterval("slideImg('next')", 5000 );
      $(this).removeClass('play').addClass("pause");
  });
  
  $("#slideshow-t02 .prev, #slideshow-t02 .next").click(function(){
      if(!$("#slideshow-t02 .play").is(".pause")){
          $("#slideshow-t02 .play").click();
      }
      switch($(this).attr("class")){
          case "prev":
              slideImg("prev");
              break;
          case "next":
              slideImg("next");
              break;
      }
  });
  
});

function slideImg(direction){
  if($("#slideshow-t02 img").is(":animated")){ return false; }
  switch(direction){
      case "prev":
          if($("#slideshow-t02 img.active").prev().is("img")){
              $("#slideshow-t02 img.active").fadeOut(function(){
                  $(this).removeClass("active");
              });
              $("#slideshow-t02 img.active").prev("img").addClass("active").show();
              $('#slideshow-t02 .amount span').html($("#slideshow-t02 img.active").attr('rel'));
              if($("#slideshow-t02 img.active").prev("img").attr("alt")!=""){ $("#slideshow-t02 .info em").text($("#slideshow-t02 img.active").prev("img").attr("alt")); }
              else { $("#slideshow-t02 .info em").text( $("#slideshow-t02 .info em").attr("rel") ); }
          } else {
              $("#slideshow-t02 img:last").fadeIn(function(){
                  $("#slideshow-t02 img.active").removeClass("active").hide();
                  $(this).addClass("active");
                  $('#slideshow-t02 .amount span').html($(this).attr('rel'));
                  if($(this).attr("alt")!=""){ $("#slideshow-t02 .info em").text($(this).attr("alt")); }
                  else { $("#slideshow-t02 .info em").text( $("#slideshow-t02 .info em").attr("rel") ); }
              });
          }

          break;
      case "next":
          if($("#slideshow-t02 img.active").next().is("img")){
              $("#slideshow-t02 img.active").next("img").fadeIn(function(){
                  $("#slideshow-t02 img.active").removeClass("active").hide();
                  $(this).addClass("active");
                  $('#slideshow-t02 .amount span').html($(this).attr('rel'));
                  if($(this).attr("alt")!=""){ $("#slideshow-t02 .info em").text($(this).attr("alt")); }
                  else { $("#slideshow-t02 .info em").text( $("#slideshow-t02 .info em").attr("rel") ); }
              });
          } else {
              $("#slideshow-t02 img.active").fadeOut(function(){
                  $(this).removeClass("active");
              });
              $("#slideshow-t02 img:first").addClass("active").show();
              $('#slideshow-t02 .amount span').html($("#slideshow-t02 img:first").attr('rel'));
              if($("#slideshow-t02 img:first").attr("alt")!=""){ $("#slideshow-t02 .info em").text($("#slideshow-t02 img:first").attr("alt")); }
              else { $("#slideshow-t02 .info em").text( $("#slideshow-t02 .info em").attr("rel") ); }
          } 
          break;
  }
}


//************************ Slideshow 03 ***/
$(function(){
  var slide = $('#slideshow-t03 .inner');
  var slideWidth = slide.outerWidth(true);
  var slideContainer = $('#slideshow-t03 .holder');
  slideContainer.css({'width':slideWidth*slide.length}); 
  $('#slideshow-t03 > ul li').click(function(){
    var slideIndex = $(this).prevAll().length;
    $(this).addClass('active').siblings().removeClass('active');
    slideContainer.animate({'margin-left':-(slideWidth*slideIndex)});
  });
});


//************************ Voucher popup ***/
$(function(){
    $("#popup .close").live("click",function(){ $("#popup").remove(); });

    $(".order_voucher").click(function(){
        var offset = $(this).offset();
        $.get($(this).attr("rel"),function(data){
            $("#popup").remove();
            $("body").append('<div id="popup">'+data+'</div>');
            var left = offset.left + 65;
            var top = offset.top - $("#popup").height() +15;            
            $("#popup").css({left: left, top: top}).show();
            $("#popup form").submit(function(){
               submitForm($(this));
               return false;
            });
        });
    });
});

function submitForm(this_form){
    var data = this_form.serializeArray();                                      
    $.post(this_form.attr("action"), data, function(data){                       
         $("#popup").html(data);
         $("#popup form").submit(function(){
             submitForm($(this));
             return false;
         });
    },"html");
    
}

$(document).ready(function(){
	$('.flag-01').each(function(){
		$(this).children('p:eq(1)').hide();
	});
	$('.extra-info-02').each(function(){
		$(this).children('p:eq(0)').remove();
	});
	$(".show-hide-extra").click(function() {
		$(this).prev('.extra-info-02').slideToggle("fast", function(){
			if($(this).css("display")=="none") {
				$(this).prev('.desc').css("visibility", "visible");
			} else {
				$(this).prev('.desc').css("visibility", "visible");
			}
		});
		return false;
	});
});

$(document).ready(function() {
	
	$(".room-list tr:last td").css("padding-bottom", "10px");
	
});

$(document).ready(function() {
	
	if($(".room-list tr").size() > 3) {
		//alert("OK");
		$(".room-list tr:nth-child(3)").nextAll('tr').css("display", "none");
		
		$(".jos-rezultata a").click(function(){
			
			$(".room-list tr").show();
			$(".jos-rezultata").remove();
			
			return false;
		});
	}
	
});

$(document).ready(function() {
	$(".article-gal .thumbs img").click(function() {
		$(".article-gal #first").attr("src", $(this).parent().attr("href"));
		return false;
	});
});

$(document).ready(function() {
	
	$("#quick-jump").change(function() {
		window.location = $("option:selected", this).val();
	});

});




/**
* GOOGLE ANALYTICS FUNKCIJE
*/
var pageTracker_trackEvent_NewsletterObrazac_Prijava = function(){
	_gaq.push(['_trackEvent', 'Newsletter-obrazac', 'Newsletter-obrazac-Prijava']);
	if( typeof console != 'undefined' && console ) console.log("_trackEvent( 'Newsletter-obrazac', 'Newsletter-obrazac-Prijava' )");
};
var pageTracker_trackEvent_NewsletterObrazac_Autorizacija = function(){
	_gaq.push(['_trackEvent', 'Newsletter-obrazac', 'Newsletter-obrazac-Autorizacija']);
	if( typeof console != 'undefined' && console ) console.log("_trackEvent( 'Newsletter-obrazac', 'Newsletter-obrazac-Autorizacija' )");
};
var pageTracker_trackEvent_RezervacijePosebnaPonudaObrazac_Poslano = function( event, ponuda ){ 
	ponuda = ( typeof event != 'undefined' && typeof event.data != 'undefined' && typeof event.data.ponuda != 'undefined' ) ? event.data.ponuda : ponuda;
	_gaq.push(['_trackEvent', 'Rezervacije-posebna-ponuda', 'Rezervacije-posebna-ponuda-Poslano', ponuda]);
	if( typeof console != 'undefined' && console ) console.log("_trackEvent( 'Rezervacije-posebna-ponuda', 'Rezervacije-posebna-ponuda-Poslano', "+ponuda+" )");
};
var pageTracker_trackEvent_RezervacijaEN_Poslano = function(){
	_gaq.push(['_trackEvent', 'Rezervacija-EN', 'Rezervacija-EN-Poslano']);
	if( typeof console != 'undefined' && console ) console.log("_trackEvent( 'Rezervacija-EN', 'Rezervacija-EN-Poslano' )");
};
var pageTracker_trackEvent_Kontakt_Poslano = function(){
	_gaq.push(['_trackEvent', 'Kontakt-obrazac', 'Kontakt-obrazac-Poslano']);
	if( typeof console != 'undefined' && console ) console.log("_trackEvent( 'Kontakt-obrazac', 'Kontakt-obrazac-Poslano' )");
};
