
var ie = (navigator.userAgent.indexOf('MSIE') == -1) ? false : true; //for stupid IE workarounds (damn you M$)

/*function CheckForHash(){
var current=document.getElementById("currentPage").href.split("#")[1];
if(!ie) {
hashDone(current);
} else {
//do some crappy iframe thing so that ie works
var state = frames["bfix"].document.body.innerHTML;
if (state==current) {
return; // Nothing's changed since last polled.
}
current = state;
hashDone(current);
}
}
function hashDone(current) {
if(document.location.hash){
var HashLocationName = document.location.hash;
HashLocationName = HashLocationName.replace("#","");
		
if(current != HashLocationName) {
HashLocationName += ".html";
changePage(HashLocationName, 'main');
}
}else{
if((current != "index") && (current != "home"))	changePage('home.html','main');
}
}

function RenameAnchor(anchorid, anchorname){
document.getElementById(anchorid).name = anchorname; //this renames the anchor
}

function RedirectLocation(anchorid, anchorname, HashName){
if(ie) {
frames["bfix"].location.href="status.html?s=" + name.split(".")[0];
}
RenameAnchor(anchorid, anchorname);
document.location = HashName;
}

var HashCheckInterval = setInterval("CheckForHash()", 1000);
window.onload = CheckForHash;
*/
function popWinSize(url, w, h) {
    if (ie) {
        h += 50;
    }
    var theTop = (screen.height / 2) - (h / 2);
    var theLeft = (screen.width / 2) - (w / 2);
    var features = 'height=' + h + ',width=' + w + ',top=' + theTop + ',left=' + theLeft + ",scrollbars=no";
    win = window.open(url, '', features);
}

function popWin(url) {
    //window.open(url,'','scrollbars=no;');
    popWinSize(url, 600, 600);
}
/*
function ahah(url, target) {
document.getElementById(target).innerHTML = ' Fetching data...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != undefined) {
req.onreadystatechange = function() {ahahDone(url, target);};
req.open("GET", url, true);
req.send("");
}
}  

function ahahDone(url, target) {
var js, i;
if (req.readyState == 4) { // only if req is "loaded"
if (req.status == 200) { // only if "OK"
document.getElementById(target).innerHTML = req.responseText;
try {
js = document.getElementById("AJAXscript").innerHTML; //grab any javascript
} catch (err) {      }	
if (js) {
eval(js); //execute if any exists      		
} else { //ie workaround - only works with the gallery
if (document.getElementById("thumbGallery")){
populateGallery(6);
}
}
} else {
document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
}
}
}

function changePage(name, div) {
if(ie) {
frames["bfix"].location.href="status.html?s=" + name.split(".")[0];
}
ahah(name,div);
	
//return false;
//document.getElementById(div).data=name;
//return false;
}
*/
function populateGallery(num) {
    var ihtml, html;
    html = "";
    var gal = -1;
    (num > pictures.length) ? num = pictures.length : num = num;

    if (document.getElementById("propID")) {
        gal = 0; //props gallery
    } else {
        if (document.getElementById("cyID")) {
            gal = 1; //cyprus gallery
        } else {
            document.getElementById("thumbGallery").innerHTML = "populateGallery(): No gallery specified!";
        }
    }
    gal = 0;
    if (gal != -1) {
        useNumPics(gal);
        for (i = 0; i <= num; i++) {

            //ahtml = "<a href='#' onclick='javascript:popWin(\"gallery.html?id=" + i + "\");'>"; //link <a> html
            ihtml = "<img src='" + thumbs[i] + "' class='cGalThumb' onclick='javascript:popWin(\"gallery.html?id=" + i + "\");' alt='click for full view' title='click for full view' href='#'>";
            if (ihtml.indexOf("undefined") == -1) {
                html += ihtml;
            }
            //document.writeln(html);
        }
        try {
            document.getElementById("thumbGallery").innerHTML = html;
        } catch (e) { }
    }
}

function insertMainGallery() {
    
    var html = "<img src='xxIMGPATHxx' class='mGalThumb' onclick='javascript:popWin(\"gallery.html?id=xxIMGIDxx\");' alt='click for full view' title='click for full view' href='#'>";
    var numpics = 32;
    var i; var imgpath = "pics/props/thumbs/"; var fname;
    var ohtml = "";
    for (i = 1; i <= numpics; i++) {
        fname = (i < 10 ? "0" + i : "" + i);
        ohtml += html.replace("xxIMGPATHxx", imgpath + fname+".jpg").replace("xxIMGIDxx", fname);
    }
    document.getElementById("gallery").innerHTML = ohtml;
    
}
