// Warchild JavaScript Document - Image Viewer Function (Large)
// Authors: Pablo Mellognio / Adrian Busscheart
// Email: pablo@socimedia.com / adrian@socimedia.com

///// INTERNATIONAL PROGRAMS - IMAGE VIEWER FUNCTION \\\\\\

    var programs_int_http_request = false;

    var initializeCount = 0;
    var autoDiv = 1;
    var activeDiv = 0;
    var activationTimer = setInterval('changeDiv()', 5000);
    var pause = 0;

	var PROGRAMSID;
	var LINKIMG;
	var TITLE;
	var SHORTCOPY;

	function programs_int_makeRequest(url) {

		programs_int_http_request = false;
        
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			programs_int_http_request = new XMLHttpRequest();
			if (programs_int_http_request.overrideMimeType) {
				programs_int_http_request.overrideMimeType('text/xml');
			}
		} else if (window.ActiveXObject) { // IE
			try {
				programs_int_http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
				programs_int_http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}

		if (!programs_int_http_request) {
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
		
		programs_int_http_request.onreadystatechange = setContentsProgram;
		programs_int_http_request.open('GET', url, true);
		programs_int_http_request.send(null);

	}
	
    function setupprograms_int(){
        programs_int_makeRequest("getPrograms.aspx");
    }
    
    function refreshPlayer_prog(){
   			  
        document.getElementById("programs_int").innerHTML = "<a href=\"programs_int_selected.aspx?id=" + PROGRAMSID + "\"><img src=\"images/int_programs/" + LINKIMG + "\" alt=\"\" border=\"0\" /></a>";
        document.getElementById("programs_int_text").innerHTML = "<p>&nbsp;</p><p><strong><font color=\"#00CCFF\">" + TITLE + "</font></strong><p>&nbsp;</p><p>" + SHORTCOPY + "&nbsp;<a href=\"programs_int_selected.aspx?id=" + PROGRAMSID + "\">Read More...</a></p>";
    }
	
	function setContentsProgram() {
		if (programs_int_http_request.readyState == 4) {
			if (programs_int_http_request.status == 200) {
			  
			    var RESPONSE = String(programs_int_http_request.responseText);
			    var RETURNED = RESPONSE.split("|");
			    
			    PROGRAMSID = RETURNED[0];
			    LINKIMG = RETURNED[1];
			    TITLE = RETURNED[2];
			    SHORTCOPY = RETURNED[3];
			    
			    refreshPlayer_prog();
			    
			} else {
				alert('There was a problem with the request.');
			}
		}
	} 
	
	function changeDiv() {
	    changeProgram('next');
    }

    function pauseplayer() {
	    if (pause == 0) {
		    clearInterval(activationTimer);
		    pause = 1;
		    document.getElementById("pause").style.display = 'none';
		    document.getElementById("play").style.display = 'block';
	    } else {
		    activationTimer = setInterval('changeDiv()', 5000);
		    pause = 0;
		    document.getElementById("play").style.display = 'none';
		    document.getElementById("pause").style.display = 'block';
	    }
    }

	function changeProgram(action) {
        programs_int_makeRequest("getPrograms.aspx?id=" + PROGRAMSID + "&action=" + action );
    }
    
    function changeProgramJump(action, id) {
        programs_int_makeRequest("getPrograms.aspx?id=" + id + "&action=" + action );
    }
