// nepieciešams noturēt fūteri lapas apakšā
function keepfooteronbottomofthepage(onload) {
  // ja tā nav pirmā lapa
  if (!$('#content').hasClass('frontpage')) {
    var height_header = $('#header').height();
    var height_content = $('#content').height();
    var height_footer = $('#footer').height();
    var height_document = $(document).height();

    if (height_document > (height_header + height_content + height_footer) + 15) {
      $('#footer').addClass("keepfooteronbottomofthepage");
      classadded = true;
    } else {
      $('#footer').removeClass("keepfooteronbottomofthepage");
      classadded = false;
    }
  
    // $('#dev').remove();
    // $('body').append("<div id='dev'></div>");
    // $('#dev').append("height_header: " + height_header + "<br/>");
    // $('#dev').append("height_content: " + height_content + "<br/>");
    // $('#dev').append("height_footer: " + height_footer + "<br/>");
    // $('#dev').append("" + height_document + " >? " + (height_header + height_content + height_footer+15) + "<br/>");
    // $('#dev').append("keeping down: " + classadded);
  }
}

// $(window).bind('load', function() {
// // $(document).ready(function() {
// // setInterval(function(){
//   keepfooteronbottomofthepage(true);
//   // }, 300);
// });
// $(window).resize(function() {
//   keepfooteronbottomofthepage(false);
// });  


// sms un webcam logiem
function getUserViewPoint(){
  return [ $(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
}


function checkKeycode(e) {
  var keycode;
  if (window.event) 
    keycode = window.event.keyCode;
  else if (e) 
    keycode = e.which;
  return keycode;
  // Esc: 27
}

// #auth_*
$(document).ready(function(){
  $('#auth_username').focus(function(){
    if ($(this).val() == $('#auth_username').attr("title")) { 
      $(this).val('');
      $(this).removeClass("disabled");
    }
  });
  $('#auth_username').blur(function(){
    if ($(this).val() == '') {
      $(this).val($('#auth_username').attr("title"));
      $(this).addClass("disabled");
    }
  });
  $('#auth_password').focus(function(){
    if ($(this).val() == $('#auth_password').attr("title")) { 
      $(this).val('');
      $(this).removeClass("disabled");
    }
  });
  $('#auth_password').blur(function(){
    if ($(this).val() == '') {
      $(this).val($('#auth_password').attr("title"));
      $(this).addClass("disabled");
    }
  });
  $('#search-q').focus(function(){
    if ($(this).val() == $('#search-q').attr("title")) { 
      $(this).val('');
      $(this).removeClass("disabled");
    }
  });
  $('#search-q').blur(function(){
    if ($(this).val() == '') {
      $(this).val($('#search-q').attr("title"));
      $(this).addClass("disabled");
    }
  });

  // onload
  if ($('#auth_username').val() == '') {
    $('#auth_username').val($('#auth_username').attr("title"));
    $('#auth_username').addClass("disabled");
  }
  if ($('#auth_password').val() == '') {
    $('#auth_password').val($('#auth_password').attr("title"));
    $('#auth_password').addClass("disabled");
  }
  if ($('#search-q').val() == '') {
    $('#search-q').val($('#search-q').attr("title"));
    $('#search-q').addClass("disabled");
  }
});



// sarkanā podziņa kastīšu virsrakstiem
$(document).ready(
  function(){
    $('.main-split-title, .bfooter-button').each(
      function(){
        $(this).hover(
          function(){
            $(this).find('img').attr('src', 
              function(){
                return $(this).attr('src').replace(/bullet\-grey\.png/, 'bullet-red.png');
              }
            );
          },
          function(){
            $(this).find('img').attr('src',
              function(){
                return $(this).attr('src').replace(/bullet\-red\.png/, 'bullet-grey.png');
              }
            );
          }
        );
      }
    );
  }
);


// GA
function ga_trackLink(linkname) {
  try {
    pageTracker._trackPageview(linkname);    
  } catch (e) {
    // alert("ga_trackLink: " + e);
  }
}


function showhide(id) {
  if (document.getElementById){
    obj = document.getElementById(id);
    if (obj.style.display == "none") {
      obj.style.display = "";
     } else {
       obj.style.display = "none";
     }
   }
}

function in_array(el, arr) {
  for (var i = 0; i < arr.length; i++) {
  	if (arr[i] == el) {
			return true;
		}
  }
  return false;
}