var hwr4pictures_proxy_reset	= "";
var hwr4picswapinfo	= new Array();

var enlarge_time	= 0.15;
var proxy_fade_time	= 0.15;
var hide_time		= 0.2;


function hwr4pic_swap_pictures(key1) {
	var tmp_pic	= hwr4picswapinfo[0];

	with(document.getElementById("hwr4pictures_thumbproxy")) {
		src	= hwr4picswapinfo[key1]['src'];
		title	= hwr4picswapinfo[key1]['title'];
		style.width		= hwr4picswapinfo[key1]['width'];
		style.height	= hwr4picswapinfo[key1]['height'];
	}
	document.getElementById("hwr4pictures_subtitle").innerHTML	= hwr4picswapinfo[key1]['title'];

	with(document.getElementById("hwr4contentthumb_"+key1)) {
		src		= hwr4picswapinfo[0]['thumb'];
		title	= hwr4picswapinfo[0]['title'];
	}

	document.getElementById("hwr4picture_originallink").href	= hwr4picswapinfo[key1]['link'];

	hwr4picswapinfo[0]		= hwr4picswapinfo[key1];
	hwr4picswapinfo[key1]	= tmp_pic;
}


function hwr4_getPicSwapInfo(xml) {
	var pics	= xml.getElementsByTagName("pic");

	for(var i=0; i<pics.length; i++) {
		pic	= pics[i];
		hwr4picswapinfo[pic.getAttribute("id")]	= new Object();
		hwr4picswapinfo[pic.getAttribute("id")]['src']		= pic.getAttribute("src");
		hwr4picswapinfo[pic.getAttribute("id")]['thumb']	= pic.getAttribute("thumb");
		hwr4picswapinfo[pic.getAttribute("id")]['width']	= pic.getAttribute("width");
		hwr4picswapinfo[pic.getAttribute("id")]['height']	= pic.getAttribute("height");
		hwr4picswapinfo[pic.getAttribute("id")]['title']	= pic.getAttribute("title");
		hwr4picswapinfo[pic.getAttribute("id")]['link']		= pic.getAttribute("link");
	}

	return true;
}



function hwr4enlarge_thumbnail(id, content_src) {
	var thumb	= document.getElementById('hwr4thumbnail_'+id);

	if(!thumb) return false;

	document.body.style.cursor	= "wait";

	var http = (navigator.appName == "Microsoft Internet Explorer") ? (new ActiveXObject("Microsoft.XMLHTTP")) : (new XMLHttpRequest());
	var proxy	= document.getElementById('hwr4pictures_thumbproxy');
	var thumb_pos 	= getOffsetToObject(thumb, 'hwr4all');
	var thumb_dompos 	= YAHOO.util.Dom.getRegion(thumb);
	var all_dompos 	= YAHOO.util.Dom.getRegion('hwr4all');
	var proxycontainer	= document.getElementById('hwr4pictures_thumbproxy_container');

	hwr4pictures_proxy_reset	= proxycontainer.innerHTML;
	proxycontainer.style.top	= thumb_pos[0];
	proxycontainer.style.left	= thumb_dompos.left-all_dompos.left;
    YAHOO.util.Dom.setStyle(proxy.id, 'opacity', 0);

    showShader();

	if(http.readyState!=1) {
		http.open("POST", "ajax/contentpictures.ajax.php", true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.onreadystatechange = function() {
			if(http.readyState == 4) {
				if (http.status == 200) {

					var rendered_tag	= http.responseXML.getElementsByTagName('rendered');
					var rendered_thumb_tag	= http.responseXML.getElementsByTagName('rendered_thumb');

					if(rendered_thumb_tag[0]) {

						proxycontainer.style.visibility	= "visible";
    					YAHOO.util.Dom.setStyle(proxycontainer.id, 'opacity', 1);

						proxy.src	= rendered_thumb_tag[0].getElementsByTagName("src")[0].firstChild.data;
						proxy.title	= rendered_thumb_tag[0].getElementsByTagName("title")[0].firstChild.data;
						thumbstyle	= rendered_thumb_tag[0].getElementsByTagName("style")[0];
						proxy.style.width	= thumbstyle.getAttribute("width");
						proxy.style.height	= thumbstyle.getAttribute("height");
						proxy.style.cursor	= "pointer";


						var proxy_fade	= new YAHOO.util.Anim(proxy.id, { opacity: { to: 1 } }, proxy_fade_time, YAHOO.util.Easing.easeIn);
						proxy_fade.onComplete.subscribe(
							function() {

								var enlarge_anim	= new YAHOO.util.Anim(proxy.id, { width: {to: thumbstyle.getAttribute("width_full") }, height: { to: thumbstyle.getAttribute("height_full") } }, enlarge_time, YAHOO.util.Easing.easeOut);

								enlarge_anim.onComplete.subscribe(
									function() {

										if(rendered_tag[0]) {
											with(document.getElementById("hwr4pictures_proxysub")) {
												innerHTML	= rendered_tag[0].firstChild.data;
												style.width	= thumbstyle.getAttribute("width_full");
											}
											with(document.getElementById("hwr4pictures_icon_bg")) {
												style.left = thumbstyle.getAttribute("width_full")-clientWidth;
											}
										}

										picinfo_tag	= http.responseXML.getElementsByTagName('picinfo')[0];
										if(picinfo_tag)	hwr4_getPicSwapInfo(picinfo_tag);

										document.getElementById("hwr4picture_originallink").href	= hwr4picswapinfo[0]['link'];

										document.body.style.cursor	= "default";
									}
								);

							    enlarge_anim.animate();

								pcont_left_to	= (thumb_dompos.right-thumbstyle.getAttribute("width_full")-all_dompos.left);
							    if(0<pcont_left_to) {
									var move_p_cont	= new YAHOO.util.Anim(proxycontainer.id, { left: { to: pcont_left_to }  }, enlarge_time, YAHOO.util.Easing.easeOut);
							    	move_p_cont.animate();
							    }

							}
						);
						proxy_fade.animate();
					}
				}
			}
		}
		http.send("a_id="+id);
	}
}


function hwr4hide_picoverlay(proxycontainer_id) {

	if(!proxycontainer_id) proxycontainer_id='hwr4pictures_thumbproxy_container';

	var proxycontainer	= document.getElementById(proxycontainer_id);
	var container_anim	= new YAHOO.util.Anim(proxycontainer_id, { opacity: { to: 0} }, hide_time, YAHOO.util.Easing.easeNone);

	hideShader();

	container_anim.onComplete.subscribe(
		function() {
			document.getElementById(proxycontainer_id).style.visibility	= "hidden";
			proxycontainer.innerHTML	= hwr4pictures_proxy_reset;
			if(proxycontainer_id=="hwr4webcam_thumbproxy_container") document.getElementById('hwr4webcam_closeicon').style.visibility	= 'hidden';

		}
	);
	container_anim.animate();
}