var imgLayout="";

window.onload = function(){
	setSlideshowLink();
	setOpenNewWin();
	window.focus();
}

function setOpenNewWin(){
    var body=document.getElementsByTagName('body')[0];
	var anchers = document.getElementsByTagName('a');
    for (var i = 0; i < anchers.length; i++) {
		var e = anchers[i];
		var newWinfunc = "openNewWin('" + e.href + "');";
		var newWinInnerfunc = "openNewWinInner('" + e.href + "');";
		if (e.className == "openNewWinO") {
		    e.setAttribute("title","Opening new window");
		    if(body.getAttribute("style") == body.style) {
			e.setAttribute("onclick",new Function(newWinfunc + "return false;"));
		    } else {
			e.setAttribute("onclick",newWinfunc + "return false;");
		    }
		} else if (e.className == "openNewWin") {
		    e.setAttribute("title","Opening new window");
		    if(body.getAttribute("style") == body.style) {
			e.setAttribute("onclick",new Function(newWinInnerfunc + "return false;"));
		    } else {
			e.setAttribute("onclick",newWinInnerfunc + "return false;");
		    }
		}
    }
}

function setSlideshowLink(){
	var body=document.getElementsByTagName('body')[0];
	subAnchors = document.getElementById('main').getElementsByTagName('a');
	for (var i = 0; i < subAnchors.length; i++) {
		if(subAnchors[i].href.indexOf('slideshow',0) >= 0){
			subAnchors[i].setAttribute("title","Opening new window");
			if(body.getAttribute("style") == body.style) {
					subAnchors[i].setAttribute("onclick",new Function("slideShowWin('" + subAnchors[i].href + "');return false;"));
			} else {
					subAnchors[i].setAttribute("onclick","slideShowWin('" + subAnchors[i].href + "');return false;");
			}
		}
	}
}

function widthResizeA(){
	var parentWidth=document.body.clientWidth;
	if (parentWidth > 1200){
		document.getElementById('hdTop').style.width="979px";
	}else if(parentWidth < 700){
		document.getElementById('hdTop').style.width="500px";
	}else{
		document.getElementById('hdTop').style.width="auto";
	}
		clearTimeout(imgLayout);
}

function widthResizeB(){
	var parentWidth=document.body.clientWidth;
	if (parentWidth > 1200){
		document.getElementById('main').style.width="979px";
	}else if(parentWidth < 700){
		document.getElementById('main').style.width="500px";
	}else{
		document.getElementById('main').style.width="auto";
	}
		clearTimeout(imgLayout);
}

function widthResizeC(){
	var parentWidth=document.body.clientWidth;
	if (parentWidth > 1200){
		document.getElementsByTagName('address')[0].style.width="973px";
	}else if(parentWidth < 700){
		document.getElementsByTagName('address')[0].style.width="494px";
	}else{
		document.getElementsByTagName('address')[0].style.width="auto";
	}
		clearTimeout(imgLayout);
}


function resizeEv(){
    imgLayout=setTimeout("widthResizeA()",300);
    imgLayout=setTimeout("widthResizeB()",300);
    imgLayout=setTimeout("widthResizeC()",100); 
	}

function wResize(){
    resizeEv();
}
window.onresize = wResize;

function openNewWin(url){
    var theWin = window.open(url, 'other', 'toolbar=yes,scrollbars=yes,menubar=yes,location=yes,status=yes,directories=yes,resizable=yes');
    theWin.focus();
    targetWin = theWin;
    focusWin = setTimeout('activeWin()',1000);
    othrWin = theWin;
}

function openNewWinInner(url){
    var theWinInner = window.open(url,"Inner","toolbar=yes,scrollbars=yes,menubar=yes,location=yes,status=yes,directories=yes,resizable=yes");
    theWinInner.focus();
    targetWin = theWinInner;
    focusWin = setTimeout("activeWin()",1000);
    othrWin = theWinInner;
}

function slideShowWin(url){
		var theWinInner = window.open(url,"Inner","width=800,height=600,toolbar=yes,scrollbars=yes,menubar=yes,location=yes,status=yes,directories=yes,resizable=yes");
		theWinInner.focus();
		targetWin = theWinInner;
		focusWin = setTimeout('activeWin()',1000);
		othrWin = theWinInner;
}

function activeWin(){
	clearTimeout(focusWin);
	targetWin.focus();
}
