// noturēt fūteri lapas apakšā
function keepfooteronbottomofthepage() {
  // wrapper, page, content
  var height_main = $('#wrapper').height();
  var height_sidebar = $('#sidebar').height()+100;
  var height_document = $(document).height();
  if (height_main < (height_document-50) && height_sidebar < (height_document-50)) {
    $('#footer').addClass("keepfooteronbottomofthepage");
    // classadded = true;
  } else {
    $('#footer').removeClass("keepfooteronbottomofthepage");
    // classadded = false;
  }
  // $('#dev').remove();
  // $('body').append("<div id='dev'></div>");
  // $('#dev').append("height_main: " + height_main + "<br/>" + "height_document: " + height_document + "<br/>" + "height_sidebar: " + height_sidebar + "<br/>" + "keeping down: " + classadded);
}

$(document).ready(function() {
  keepfooteronbottomofthepage();
});
$(window).resize(function() {
  keepfooteronbottomofthepage();
});



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

function showhide_jq(id, save) {
  if (document.getElementById && document.getElementById(id)) {
    var obj = document.getElementById(id);
    if (obj.style.display == "none") {
      $("#" + id).animate({ height: 'show', opacity: 'show' }, 'slow');
      if (save) {
        createCookie(id, 1, 14);
      }
    } else {
      $("#" + id).animate({ height: 'hide', opacity: 'hide' }, 'slow');
      if (save) {
        createCookie(id, 0, 14);
      }
    }
  }
  return false;
}

function swap_images(imgid, originalsrc, swappedsrc) {
  if (document.getElementById(imgid)) {
    var img = document.getElementById(imgid);
    if (img.src == originalsrc) {
      img.src = swappedsrc;
    } else {
      img.src = originalsrc;
    }
  }
}

//-----------------------------------
// http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//-----------------------------------------------

// asociatīvo masīvu simulācija
function arrCount(array) {
  var i = 0;
  if (typeof(array) == "object") {
    for (var tmp in array) {
      i++;
    }
  }
  return i;
}

function arrGetNextKey(array, currentKey) {
  var i = 0;
  if (typeof(array) == "object") {
    for (var tmp in array) {
      if (tmp == currentKey) {
        break;
      }
      i++;
    }
    var j = 0;
    for (var tmp in array) {
      if (j == i+1) {
        return tmp;
        break;
      }
      j++;
    }
  }
}
function arrGetPrevKey(array, currentKey) {
  var i = 0;
  if (typeof(array) == "object") {
    for (var tmp in array) {
      if (tmp == currentKey) {
        break;
      }
      i++;
    }
    var j = 0;
    for (var tmp in array) {
      if (j == i-1) {
        return tmp;
        break;
      }
      j++;
    }
  }
}

function arrGetValue(array, key) {
  if (typeof(array) == "object") {
    for (var tmp in array) {
      if (tmp == key) {
        return array[tmp];
      }
    }
  }
}

function arrGetCurrentPos(array, currentKey) {
  var i = 0;
  if (typeof(array) == "object") {
    for (var tmp in array) {
      if (tmp == currentKey) {
        return i;
      }
      i++;
    }
  }
}

//-----------------------------------------------