/**
 * PhotoDetail.js
 */

var win = null;

function setWindowSize() {
	//var iframe = win.getContent();
	var iframe = document.getElementById("win_detail_content");;
	
	if(iframe.contentDocument) {
		var el = iframe.contentDocument.getElementById("ofWindowSize");
	}else{
		var el = iframe.contentWindow.document.getElementById("ofWindowSize");
	}

	var y = document.body.scrollTop || document.documentElement.scrollTop;

	var w = getInnerWidth();
	var x = 0;
	if(w!=null) {
		x = (w - el.clientWidth)/2;
	}

	win.setLocation(y, x);
	win.setSize(el.clientWidth+3, el.clientHeight+3);
	
}

function windowOpenByURL(url,width,height,modal) {
	win = new Window("win_detail", {className:"ws_dialog",
	                  zIndex:100,
	                  url:url,
	                  //width:width,
	                  //height:height,
	                  top: -10,
	                  left: -10,
	                  minWidth: 0,
	                  minHeigth: 0,
	                  width: 0,
	                  height: 0,
	                  closable:false,
                      resizable:false,
                      minimizable:false,
                      maximizable:false,
                      draggable:false,
					  onload:setWindowSize,
                      showEffect: Element.show,
                      hideEffect: Element.hide
                      });
	win.setDestroyOnClose();
    if(modal==true) {
        //win.showCenter(true);
        win.show(true);
    }else {
        //win.showCenter();
        win.show();
    }
    
    var iframe = document.getElementById("win_detail_content");
	if(iframe){
		iframe.setAttribute("scrolling","no");
	};
}

function windowClose() {
    if(win != null) {
    	win.close();
    	win = null;
    }
    return true;
}

function reloadEditWindow(html) {
	win.setHTMLContent(html);
	win.updateHeight();
	win.updateWidth();
}

function getInnerWidth() {
	var w = null;
	if(typeof(innerWidth) != 'undefined') {
		w = innerWidth;
	}
	else {
		var w1 = null;
		var w2 = null;
		if(typeof(document.body.clientWidth) != 'undefined') {
		 	w1 = document.body.clientWidth;
		}
		if(typeof(document.documentElement.clientWidth) != 'undefined') {
		 	w2 = document.documentElement.clientWidth;
		}
		if( w1!=null && w2!=null ) {
			if( w1 < w2 ) {
				w = w1;
			}
			else {
				w = w2;
			}
		}
		else if(w1!=null) {
			w = w1;
		}
		else if(w2!=null) {
			w = w2;
		}
	}

	return w;
}

function openPhotoDetailWindow(m_id, p_id, f_id) {
	url = "/Photo/PhotoDetail/p_id/" + p_id + "/";
	if( f_id ) {
		url += "f_id/" + f_id + "/";
	}
	if( m_id ) {
		url += "m_id/" + m_id + "/";
	}

	windowOpenByURL(url, null, null, true);
}

function locationHref(url) {
	location.href = url;
}



