// JavaScript Document

images_medium = new Object();

function changeimg(media_id,node_id){
	target_img = "image_medium["+node_id+"]";
	target_link = "link["+node_id+"]";
	
	document.images[target_img].src = images_medium[node_id][media_id]["image"].src;
	
	if (document.getElementById(target_link)&&(images_medium[node_id][media_id]["large_img"])) {
		js_link = document.createAttribute("href");
		js_link.nodeValue = "javascript:show_full('"+media_id+"','"+node_id+"')";
		document.getElementById(target_link).setAttributeNode(js_link);
	}else {
		js_link = document.createAttribute("href");
		js_link.nodeValue = "javascript:fake()";
		document.getElementById(target_link).setAttributeNode(js_link);
	}
	
	var short_text 		= document.getElementById("short_text["+node_id+"]");
	var short_text_end 	= document.getElementById("short_text_end["+node_id+"]");
	
	if (images_medium[node_id][media_id]["short_text"].length>0){
		short_text.style.display="block";
		short_text_end.style.display="block";
		short_text.innerHTML = images_medium[node_id][media_id]["short_text"];
	}else{
		
		short_text.style.display="none";
		short_text_end.style.display="none";
		
	}
	return false;
}


function change_portfolioImg(parent_id,node_id){
	
	parent_id_prefix = "block";
	
	for (var media in images_medium[node_id]){
		if (images_medium[node_id][media]["parent_id"] == parent_id.replace(parent_id_prefix,'')){
			changeimg(media,node_id);
			break;		
		}		
	}	
}

function showLarge(){
	
	test = document.createElement("div");
	test.id = "grey";
	var body = document.getElementsByTagName("body");
	
	large_img = document.createElement("div");
	large_img.className = "picture_desc";	
	large_img.style.width = "230px";	
	large_img.style.height = "200px";	
	large_img_end = document.createElement("div");
	large_img_end.className = "picture_desc_end";	
	large_img_end.style.width = "230px";	
	
	test.appendChild(large_img);	
	test.appendChild(large_img_end);	
	body[0].appendChild(test);	

}

function show_full(media_id,node_id){
	

	document.getElementById('gallery_layer').style.display="block";
	pagesize = getPageSize();
	
	if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	
		newMarginTop = (document.documentElement.scrollTop);

	} else if (document.body) { // other Explorers
		newMarginTop = (document.body.scrollTop);
	}else{		
		newMarginTop = (window.pageYOffset);
	}
	
	if (navigator.appName ==  "Microsoft Internet Explorer"){
		document.getElementById('gallery_layer').style.height=(newMarginTop + pagesize[1]*1.5)+"px";
	}else{
		document.getElementById('gallery_layer').style.height=newMarginTop + pagesize[1]+"px";
	}
	document.getElementById('large_img').style.marginTop = (newMarginTop+50)+"px";
	
	document.getElementById('show_full_text').innerHTML = images_medium[node_id][media_id]["short_text"];
	document.images['large_img'].src = images_medium[node_id][media_id]["large_img"];
	
	for(var thumbs in images_medium[node_id]){
		if (images_medium[node_id][thumbs]["thumb"] && !document.getElementById("large_thumbs" + thumbs)){
			
			newthumb = document.createElement("a");
			
			newthumb_href = document.createAttribute("href");
			newthumb_href.nodeValue = "javascript:show_full('"+thumbs+"','"+node_id+"')";
			newthumb.setAttributeNode(newthumb_href);
			
			newthumb_href = document.createAttribute("id");
			newthumb_href.nodeValue = "large_thumbs" + thumbs;
			newthumb.setAttributeNode(newthumb_href);
			
			newthumb_img = document.createElement("img");
			newthumbimg_src = document.createAttribute("src");
			newthumbimg_src.nodeValue = images_medium[node_id][thumbs]["thumb"].src;
			newthumb_img.setAttributeNode(newthumbimg_src);
			
			newthumb.appendChild(newthumb_img);
			
			document.getElementById("large_thumbs").appendChild(newthumb);
		}
	}
}

function hide_full(){
	document.getElementById('gallery_layer').style.display="none";	
}

function fake(){
	
}



