resize_confMaxDim = 560; // pixels

function resize_resize(obj) {

   thisWidth = obj.width;
   thisHeight = obj.height;
   
   if(thisWidth > thisHeight) thisMaxDim = thisWidth;
   else thisMaxDim = thisHeight;
   
   if(thisMaxDim > resize_confMaxDim) {
      thisMinDim = Math.round((((thisWidth > thisHeight)?thisHeight:thisWidth) * resize_confMaxDim) / thisMaxDim); 
      
      if(thisWidth > thisHeight) {
         thisWidth = resize_confMaxDim;
         thisHeight = thisMinDim;
      } else {
         thisHeight = resize_confMaxDim;
         thisWidth = thisMinDim;
      }
   } 
   
   if(thisMaxDim > resize_confMaxDim) {
   obj.height = thisHeight;
   obj.width = thisWidth;
   }
}

var ori_pic_width = [];
function final_resize() {
// x.length
	var x=getElementsByClass("postlink");
	max_length = 85;
	for (var i = 0; i < x.length; i++){
		x[i].target = "_blank";
		link_value = x[i].innerHTML;
		has_images = 0;
		
		if (link_value.length > max_length) {
			var children = x[i].childNodes;
			for (var j=0; j<children.length; j++) {
			 	if (children[j].nodeName == "IMG") {
			 		has_images = 1;
			 	}
			}
			if (has_images == 0) {
				x[i].title = link_value;
				x[i].innerHTML = link_value.substring(0, max_length-3) + "...";
			}
		}
	}
	var x=getElementsByClass("postlink-local");
	for (var i = 0; i < x.length; i++){
		x[i].target = "_blank";
		//alert(x[i].href);
	}
	//alert(c);


 var x=document.getElementsByName("thread_pic");
 for (i=0; i < x.length; i++) {
obj = x[i];

   thisWidth = obj.width;
   thisHeight = obj.height;
   
   
   if(thisWidth > thisHeight) thisMaxDim = thisWidth;
   else thisMaxDim = thisHeight;
   
   thisSrc = obj.src;
   ori_pic_width[thisSrc] = thisWidth;
   
   if(thisMaxDim > resize_confMaxDim) {
      
      thisMinDim = Math.round((((thisWidth > thisHeight)?thisHeight:thisWidth) * resize_confMaxDim) / thisMaxDim); 
      
      if(thisWidth > thisHeight) {
         thisWidth = resize_confMaxDim;
         thisHeight = thisMinDim;
      } else {
         thisHeight = resize_confMaxDim;
         thisWidth = thisMinDim;
      }
      
      
      obj.height = thisHeight;
      obj.width = thisWidth;
   }
  }
 
 var cont=document.getElementById("containerCenter");
 x = cont.getElementsByTagName('img');
 for (i=0; i < x.length; i++) {
	 obj = x[i];

	    thisWidth = obj.width;
	    thisHeight = obj.height;
	    
	    
	    if(thisWidth > thisHeight) thisMaxDim = thisWidth;
	    else thisMaxDim = thisHeight;
	    
	    thisSrc = obj.src;
	    ori_pic_width[thisSrc] = thisWidth;
	    
	    if(thisMaxDim > resize_confMaxDim) {
	       
	       thisMinDim = Math.round((((thisWidth > thisHeight)?thisHeight:thisWidth) * resize_confMaxDim) / thisMaxDim); 
	       
	       if(thisWidth > thisHeight) {
	          thisWidth = resize_confMaxDim;
	          thisHeight = thisMinDim;
	       } else {
	          thisHeight = resize_confMaxDim;
	          thisWidth = thisMinDim;
	       }
	       
	       
	       obj.height = thisHeight;
	       obj.width = thisWidth;
	    }
	   }
 
}

function normal_size(obj) {

	thisSrc = obj.src;
	new_resize_width = ori_pic_width[thisSrc];
      
   thisWidth = obj.width;
   thisHeight = obj.height;
   
   
   if(thisWidth > thisHeight) thisMaxDim = thisWidth;
   else thisMaxDim = thisHeight;
   
   
   if(thisMaxDim != new_resize_width) {
   	   
	      ori_pic_width[thisSrc] = thisMaxDim;	      
	      thisMinDim = Math.round((((thisWidth > thisHeight)?thisHeight:thisWidth) * new_resize_width) / thisMaxDim); 
	      	      
	      if(thisWidth > thisHeight) {
	         thisWidth = new_resize_width;
	         thisHeight = thisMinDim;
	      } else {
	         thisHeight = new_resize_width;
	         thisWidth = thisMinDim;
	      }
	      
	      
	      obj.height = thisHeight;
	      obj.width = thisWidth;
  }
}


function resize_setLink(obj) {
   thisInnerHtml = obj.innerHTML;
   tmpArray = thisInnerHtml.split(' src=\"');
   tmpArray = tmpArray[1].split('"');
   obj.href = tmpArray[0];
}


function changeContent(div_id) 
{ 
document.getElementById(div_id).innerHTML = window.frames['iframe-'+div_id].document.getElementsByTagName('html')[0].innerHTML; 
}

var loaded_images = [];
var ran_num = [];
var tag_data = [];
var my_images_divs = [];
var t;
function changeMyImages(div_id) { 
	my_num = my_images_divs.length;
	my_images_divs[div_id] = div_id;
	clearTimeout(t);
	t = setTimeout('genTags()',750);
} 

my_images_last = [];
my_images_data = [];
function genTags() {
	my_images_ids = "";
	for (var i in my_images_divs) {
		all_divs = $('div[name='+i+'_tags]');
		$(all_divs).each(function(id){
			new_id = i+'_'+id;
			$(this).attr("id",new_id);
			my_images_last[new_id] = i;
		});
		my_images_ids += i+',';
		
	}
	//alert(my_images_ids);
	$.get("my_images_iframe.php?t="+Math.random(), { ids: my_images_ids}, function(data){
		all_data = data.split("|||");
		for (var i in all_data) {
			small_data = [];
			small_data = all_data[i].split("||");
			my_images_data[small_data[0]] = small_data[1]+'|||'+small_data[2];
		}
		
		createTags();
	});
}

function createTags() {
	for (var i in my_images_last) {
		my_data = my_images_data[my_images_last[i]].split("|||");
		$('#'+i).html('<img id="'+i+'_image" src="/my_images/images/'+my_data[0]+'" onload="insertTags(\''+i+'\');">');
		$('#'+i).after('<div id="'+i+'_imagetags" class="tags">&nbsp;</div>');
	}
}

function insertTags(id) {
	my_data = my_images_data[my_images_last[id]].split("|||");
	json_obj = eval(my_data[1]);
	$('#'+id).imgNotes(json_obj, id);
	$('#'+id).updateTags(id);
	
}


function SelectedPosts() {

var x = document.getElementsByName("check_posts");
boxes = document.getElementsByName("check_posts").length;
values = ""
do_value = ""
for (i = 0; i < boxes; i++) {
if (x[i].checked) {

if (do_value != "") do_value = "-"+x[i].value;
else do_value = x[i].value;

values = values + do_value;
}
}

var y = document.getElementsByName("do_check_posts");
y[0].value = values;

if (values == "") {
alert("Du har ikke valgt nogle indlęg!");
return false;
} else {
return true;
}
}

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}
