function imgChange (name, img)
{
	for (var i = 0; i < document.images.length; i++) {
		if (document.images[i].name == name) {
			document.images[i].src = img;
			break;
		}
	}
}

function addDOMLoadEvent(func)
{
   if (!window.__load_events) {      
   	  var init = function () {
          // quit if this function has already been called
          if (arguments.callee.done) return;
          // flag this function so we don't do the same thing twice
          arguments.callee.done = true;
      
          // kill the timer
          if (window.__load_timer) {
              clearInterval(window.__load_timer);
              window.__load_timer = null;
          }
          
          // execute each function in the stack in the order they were added
          for (var i = 0; i < window.__load_events.length; i++)
          {
              window.__load_events[i]();
          }
          
          window.__load_events = null;
      };
   
      // for Mozilla/Opera9
      if (document.addEventListener) {
          document.addEventListener("DOMContentLoaded", init, false);
      }
            
      // for Safari
      if (/WebKit/i.test(navigator.userAgent)) { // sniff
          window.__load_timer = setInterval(function() {
              if (/loaded|complete/.test(document.readyState)) {
                  init(); // call the onload handler
              }
          }, 10);
      }
      
      // for other browsers
      window.onload = init;
      // create event function stack
      window.__load_events = [];
   }
   // add function to event stack
   window.__load_events.push(func);
}

function showPhoto (link)
{
	document.getElementById('top_photo').src = link;
}

function showComment (comment)
{
	document.getElementById('top_photo').title = comment;
	document.getElementById('comment').innerHTML = comment;
}


/*** Right-click protection functions ***/

var isNS = (navigator.appName == "Netscape") ? 1 : 0;

function mischandler() { return false; }

function mousehandler(e)
{
	var myevent = (isNS) ? e : event;
	var eventbutton = (isNS) ? myevent.which : myevent.button;
  	if((eventbutton==2)||(eventbutton==3)) {
  		return false;
	}
}

function disable_rclick(target)
{
	if(isNS && target.captureEvents) {
        target.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
	}
        
    target.oncontextmenu = mischandler;
    target.onmousedown = mousehandler;
    target.onmouseup = mousehandler;
}

function redirect(url) 
{
    window.location.href = url;
}

function position (x, y)
{
	self.scrollTo(x, y);
}

/****************************** */

/**
 * Set Cookie
 * @param {Object} name
 * @param {Object} value
 * @param {Object} expires
 */
function setCookie(name, value, expires)
{
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expires);
	document.cookie = name + "=" + escape(value) +
	((expires === null) ? "" : ";expires=" + exdate.toGMTString());
}

/**
 * Get Cookie
 * @param {Object} name
 */
function getCookie(name)
{
	if (document.cookie.length > 0) {
  		c_start = document.cookie.indexOf(name + "=");
  		if (c_start != -1) { 
    		c_start = c_start + name.length+1;
    		c_end = document.cookie.indexOf(";",c_start);
    		if (c_end == -1) {
				c_end = document.cookie.length;
			}
    	
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	
	return null;
}

/**
 * Del Cookie
 * @param {Object} name
 */
function delCookie (name)
{
	if ( getCookie( name ) ) {
		document.cookie = name + "=" + 
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

/**
 * Save position
 */
function savePosition()
{
	var Y = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape, Opera
		Y = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		Y = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE sux
		Y = document.documentElement.scrollTop;
	}
  	
	setCookie("position", Y, 1);
}

/**
 * Load position
 */
function loadPosition()
{
	var Y = getCookie("position");
		
	if (Y === null) {
		window.scrollTo(0, 0);
	} else {
		window.scrollTo(0, Y);
		delCookie("position");
	}
}

