
$(document).ready(function(){
//
});

function showLogin() {
	
}




var req;

function loadXMLDoc(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            // ...processing statements go here...
            response  = req.responseXML.documentElement;
            if (response.getElementsByTagName('image').length == 0) {
            	window.location.href=response.getElementsByTagName('root')[0].firstChild.data;
            } else {
            	if (response.getElementsByTagName('next')[0].firstChild.data == "NULL"){
            		window.frames.top.tb_remove();
            	} else {
   	         		if (window.ActiveXObject){
   	         			document.images.gimage.src=response.getElementsByTagName('image')[0].firstChild.data;
	   	         	}else{
	   	         		$('#gimage').fadeOut('slow', function(){
	   	         			var fadein = false;
							document.getElementById('gimage').src=response.getElementsByTagName('image')[0].firstChild.data;
							$('#gimage').load(function(){
								$('#gimage').removeAttr('width'); 
								$('#gimage').attr('height', '532'); 
								if ($('#gimage').attr('width') > 800) { 
									var fx = ($('#gimage').height())/($('#gimage').width());
									$('#gimage').width(800);
									$('#gimage').height(800*fx);
								}
								if (!fadein) {
									fadein = true;
									$('#gimage').fadeIn('slow', function(){
										if ($('#gimage') != null) {
											setTimeout('loadImage("'+response.getElementsByTagName('next')[0].firstChild.data+'")',2000);
										}
									});
								}
							});
	   	         		});
					}
            	}
			}
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}

function loadImage(link){
	if (!image.complete){
		setTimeout('loadImage(\''+link+'\');', 1000);
	} else {
		loadXMLDoc(link+"&out=ajax");
	}
}
