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

///// Programs - IMAGE VIEWER FUNCTION \\\\\\

    var programs_home_http_request = false;


    var initializeCount = 0;
    var autoDiv = 1;
    var activeDiv = 0;
    
    ///in case we need auto switching for this section \\\
    
    //var activationTimer = setInterval('changeNewsDiv()', 5000);
    //var pause = 0;

	var PROGRAMSID;
	var PROGRAMSIMAGE;
	var PROGRAMSTITLE;
	var PROGRAMSCOPY;

	function programs_home_makeRequest(url) {

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

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

	}
	
    function setupProgramsHome(){
        programs_home_makeRequest("getProgramsHome.aspx");
    }
    
    function refreshProgramsHome(){

        document.getElementById("home_programs_menu").innerHTML = "<a href=\"programs_int_selected.aspx?id=" + PROGRAMSID + "\"><img src=\"images/int_programs/" + PROGRAMSIMAGE + "\" alt=\"\" border=\"0\" /></a>";
        document.getElementById("home_programs_menutext").innerHTML = "<h2><span class=\"homelink\"><a href=\"programs_int_selected.aspx?id="+PROGRAMSID+" \">"+PROGRAMSTITLE+"</a></span></h2><br><p>" + PROGRAMSCOPY + "&nbsp;<a href=\"programs_int_selected.aspx?id=" + PROGRAMSID + "\">Read More...</a></p>";
        
    }
	
	function setContentsProgramsHome() {
		if (programs_home_http_request.readyState == 4) {
			if (programs_home_http_request.status == 200) {
			  
			    var RESPONSE = String(programs_home_http_request.responseText);
			    var RETURNED = RESPONSE.split("|");
			    
			    PROGRAMSID = RETURNED[0];
			    PROGRAMSIMAGE = RETURNED[1];
			    PROGRAMSTITLE = RETURNED[2];
			    PROGRAMSCOPY = RETURNED[3];
			    
			    refreshProgramsHome();
			    
			} else {
				alert('There was a problem with the request.');
			}
		}
	} 
	
	function changeProgramsHomeDiv() {
	    changeProgramsHome('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('changeNewsDiv()', 5000);
//		    pause = 0;
//		    document.getElementById("play").style.display = 'none';
//		    document.getElementById("pause").style.display = 'block';
//	    }
//    }

	function changeProgramsHome(action) {
        programs_home_makeRequest("getProgramsHome.aspx?id=" + PROGRAMSID + "&action=" + action );
    }
    
//    function changeProgramsHome(action, id) {
//        programs_home_makeRequest("getProgramsHome.aspx?id=" + id + "&action=" + action );
//    }
    
