﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />


function formatText(index, panel) {
  return index + "";
}

//CMS class

function cms(){
  this.Search = function(q){
    if (q.length > 2) {
      var qs = "?q=" + encodeURIComponent(q);
      window.location.href = "/hr/trazi/" + qs;
      }
  }
}

var $CMS = new cms();







function GalleryMagic() {
  $(".pg-thumb:first").addClass('pg-thumb-selected');

  $(".pg-thumb").click(function () {
    $("#pg-photo-img").attr('src', $(this).attr('href'));
    $("#pg-photo-a").attr('href', $(this).attr('rel'));

    $(".pg-thumb").each(function () {
      $(this).addClass('pg-thumb');
      $(this).removeClass('pg-thumb-selected');
    });

    


    $(this).addClass('pg-thumb-selected');
    return false;
  });


  $("#pg-photo A").fancybox();
}









function validate() {
  var message = "Uspješno ste poslali svoj komentar";
  var error = "";

  var comment = $("#taComment").val();
  if (comment == "") {
    error = "Unesite komentar";
  }

  var email = $("#tbEmail").val();
  if (email == "") {
    error = error + (error != "" ? "<br />" : "") + "Unesite email";
  }
  else if (!isValidEmail(email)) {
    error = error + (error != "" ? "<br />" : "") + "Unesite valjanu email adresu";
  }

  if (error == "") {

    var dataString = 'comment=' + $("#taComment").val() + '&email=' + $("#tbEmail").val();

    $.ajax({
      type: "POST",
      url: "/inc/ajax/contact.aspx",
      data: dataString,
      success: function () {
        $("#message_box").html(message);
        $("#message_box").removeClass('red');
        $("#message_box").addClass('green');

        $("#taComment").val("");
        $("#tbEmail").val("");
      }
    });
  } else {
    $("#message_box").html(error);
    $("#message_box").removeClass('green');
    $("#message_box").addClass('red');
  }
  setupMessageBox();

}


var updateTimer = 0;
function setupMessageBox() {
  showMessage(); //displays message on page load
  jQuery(window).scroll(function () {
    if (jQuery("#message_box").is(':visible')) {
      showMessage();
    }
  });
  clearTimeout(updateTimer);
  activateTimer();
}

function activateTimer() {
  updateTimer = setTimeout('jQuery("#message_box").hide("slow")', 5000);
}

function showMessage() {
  $("#message_box").show('slow');
  jQuery('#message_box').animate({ top: jQuery(window).scrollTop() + "px" }, { queue: false, duration: 350 });
}

function isValidEmail(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);
}










$(function(){

  Cufon.replace('.cufonMenu, .cufonTitle, .cufonTitlev2, .cufonTitlev3, .cufonTitlev4, .cufonTitlev7, .cufonTextv2');


  
  $('#search INPUT').focus(function () {
    $(this).val('');

  });

  $("#inputSearchTop,#inputSearchBottom").keypress(function(e){
    if (e.which == 13) {
      $CMS.Search($(this).val());
    }
  });
  
  $("#search-btn,.search-btn,.search").click(function(e){
    $CMS.Search($(this).parent().find("INPUT").eq(0).val());
    return false;
  });
  
  /*function setHeight(){
    var $wh = $(window).height();
    var $ch = $("#header").height() + $("#menu").height() + $("#wrap").height();
    
    if ($wh>$ch){
      $("#wrap").height($("#wrap").height()+($wh-$ch)-46);
    }
    
  }*/
  
  /*$(window).resize(function() {
    setHeight();
  });
  
  setHeight();*/
  
  //$(".jclite").jCarouselLite({
//        btnNext: ".next",
//        btnPrev: ".prev"
    //});
    
  //simple menu
//  $(window).bind("onload", function(){
//    var menu = new menu.dd("menu");
//	  menu.init("menu","menuhover");
//  });
  
  /*$('ul.mainMenu').superfish();
  $(".mainMenu .sf-sub-indicator").wrapInner("<em>");*/


  $("#menu ul").superfish({ 
      animation: {height:'show'},   // slide-down effect without fade-in 
      delay:     200               // 1.2 second delay on mouseout 
    });

  $("#menu ul .sf-sub-indicator").wrapInner("<em>");

  $(".iframe-big").fancybox({
    'width': '75%',
    'height': '75%',
    'autoScale': false,
    'transitionIn': 'none',
    'transitionOut': 'none',
    'type': 'iframe'
  });

  $(".iframe-small").fancybox({
    'width': 500,
    'height': 380,
    'autoScale': false,
    'transitionIn': 'none',
    'transitionOut': 'none',
    'type': 'iframe'
  });

  $(".iframe-max").fancybox({
    'width': '100%',
    'height': '100%',
    'autoScale': false,
    'transitionIn': 'none',
    'transitionOut': 'none',
    'type': 'iframe'
  });


  
//  $(".mainMenu > LI > UL").each(function(){
//      console.debug($(this).parent());
//      $(this).css("width", $(this).parent().width());
//    });
  
  /*$(".jclite UL").liScroll();*/
  
});
