/*
mouseout="http://www.nachofoto.com/img/addalt.gif";
mouseover="http://www.nachofoto.com/img/add.gif";
Vertical_Adjust=0;
Horizontal_Adjust=0;
Minimum_Image_Width=100;
Minimum_Image_Height=100;
*/

var mouseoutImage=typeof mouseout=='string'?mouseout:_IMG_SERVER+"img/addalt.gif";
var mouseoverImage=typeof mouseover=='string'?mouseover:_IMG_SERVER+"img/add.gif";
var Vertical_Adjust_Length=typeof Vertical_Adjust=='number'?Vertical_Adjust:0;
var Horizontal_Adjust_Length=typeof Horizontal_Adjust=='number'?Horizontal_Adjust:0;
var Minimum_Image_Width_Length=typeof Minimum_Image_Width=='number'?Minimum_Image_Width:200;
var Minimum_Image_Height_Length=typeof Minimum_Image_Height=='number'?Minimum_Image_Height:200;

//Selected text as description
var c = '';
if (window.getSelection){
c = window.getSelection();
}
else if (document.getSelection){
c = document.getSelection();
}
else if (document.selection){
c = document.selection.createRange().text;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function a_hear( a, b, c, d ){
   if( a.addEventListener ){
	   a.addEventListener( b, c, d );
   }
   else if( a.attachEvent ){
		a.attachEvent("on" + b,c);
	}
}

function getArrayByClassName(clsName,tag){
var retVal = new Array();
if (tag == null) { tag="*"; }
var elements = document.getElementsByTagName(tag);
for(var i = 0;i < elements.length;i++){
var classes = elements[i].className.split(" ");
	for(var j = 0;j < classes.length;j++){
	if(classes[j] == clsName)
	retVal.push(elements[i]);
	}
}

return retVal;
}	


//+ icons
function placefotomarks(){
	
	//resize hack
	prevfotomarks=getArrayByClassName("dontTouchThis","img");
	for(i=0;i<prevfotomarks.length;i++){
		prevfotomarks[i].style.display="none";			
	}
	
	images = document.getElementsByTagName('img');
	for (cImage = 0; cImage < images.length; cImage++) {	
		img = images[cImage];
	
	    // Check this isn't an image we created ourselves
	    if (img.className == 'dontTouchThis') continue;
	
	    width = img.width;
	    height = img.height;
	    src = img.src;
	
	
	if(width<Minimum_Image_Width_Length || height<Minimum_Image_Height_Length)continue;
	var left = findPos(img)[0];
	var top = findPos(img)[1];
	
	//reject header images
	if(left<20 || top<20)continue;
	if(top<100)continue;
	
	newimg = document.createElement('img');
	newimg.src = mouseoutImage;
	newimg.id=img.src;
	newimg.setAttribute("alt","Fotomark it");
	newimg.setAttribute("title","Fotomark it");
	newimg.onmouseover=function(){newimg.src = mouseoverImage;}
	newimg.onmouseout=function(){newimg.src = mouseoutImage;}
	newimg.style.zIndex=10000;
	newimg.style.position = 'absolute';
	newimg.style.display = '';
	newimg.style.top = top-7+Vertical_Adjust_Length+'px';
	newimg.style.left = left+Horizontal_Adjust_Length+'px';
	newimg.style.cursor='pointer';
	newimg.className = 'dontTouchThis';
	newimg.style.border=0;
	
	link=document.createElement("a");
	link.setAttribute("href","http://www.nachofoto.com/submitfoto?weburl="+encodeURIComponent(window.location)+"&imgurl="+encodeURIComponent(img.src)+"&imgtitle="+encodeURIComponent(document.title)+"&bm=1&imgdesc="+c);
	link.setAttribute("onclick","checkDescription();")
	link.setAttribute("target","_blank");
	
	link.appendChild(newimg);
	
	document.getElementsByTagName('body')[0].appendChild(link);
	
	}

}

placefotomarks();
a_hear(window,"resize",function(){placefotomarks();},true);	

